CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * Short description for file.
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.console.libs
 20:  * @since         CakePHP(tm) v 1.2.0.5012
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * @package       cake
 28:  * @subpackage    cake.cake.console.libs
 29:  */
 30: class ConsoleShell extends Shell {
 31: /**
 32:  * Available binding types
 33:  *
 34:  * @var array
 35:  * @access public
 36:  */
 37:     var $associations = array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany');
 38: /**
 39:  * Chars that describe invalid commands
 40:  *
 41:  * @var array
 42:  * @access public
 43:  */
 44:     var $badCommandChars = array('$', ';');
 45: /**
 46:  * Available models
 47:  *
 48:  * @var array
 49:  * @access public
 50:  */
 51:     var $models = array();
 52: /**
 53:  * Override intialize of the Shell
 54:  *
 55:  * @access public
 56:  */
 57:     function initialize() {
 58:         require_once CAKE . 'dispatcher.php';
 59:         $this->Dispatcher = new Dispatcher();
 60:         $this->models = Configure::listObjects('model');
 61:         App::import('Model', $this->models);
 62: 
 63:         foreach ($this->models as $model) {
 64:             $class = Inflector::camelize(r('.php', '', $model));
 65:             $this->models[$model] = $class;
 66:             $this->{$class} =& new $class();
 67:         }
 68:         $this->out('Model classes:');
 69:         $this->out('--------------');
 70: 
 71:         foreach ($this->models as $model) {
 72:             $this->out(" - {$model}");
 73:         }
 74:         $this->__loadRoutes();
 75:     }
 76: /**
 77:  * Prints the help message
 78:  *
 79:  * @access public
 80:  */
 81:     function help() {
 82:         $this->main('help');
 83:     }
 84: /**
 85:  * Override main() to handle action
 86:  *
 87:  * @access public
 88:  */
 89:     function main($command = null) {
 90:         while (true) {
 91:             if (empty($command)) {
 92:                 $command = trim($this->in(''));
 93:             }
 94: 
 95:             switch ($command) {
 96:                 case 'help':
 97:                     $this->out('Console help:');
 98:                     $this->out('-------------');
 99:                     $this->out('The interactive console is a tool for testing parts of your app before you commit code');
100:                     $this->out('');
101:                     $this->out('Model testing:');
102:                     $this->out('To test model results, use the name of your model without a leading $');
103:                     $this->out('e.g. Foo->find("all")');
104:                     $this->out('');
105:                     $this->out('To dynamically set associations, you can do the following:');
106:                     $this->out("\tModelA bind <association> ModelB");
107:                     $this->out("where the supported assocations are hasOne, hasMany, belongsTo, hasAndBelongsToMany");
108:                     $this->out('');
109:                     $this->out('To dynamically remove associations, you can do the following:');
110:                     $this->out("\t ModelA unbind <association> ModelB");
111:                     $this->out("where the supported associations are the same as above");
112:                     $this->out('');
113:                     $this->out("To save a new field in a model, you can do the following:");
114:                     $this->out("\tModelA->save(array('foo' => 'bar', 'baz' => 0))");
115:                     $this->out("where you are passing a hash of data to be saved in the format");
116:                     $this->out("of field => value pairs");
117:                     $this->out('');
118:                     $this->out("To get column information for a model, use the following:");
119:                     $this->out("\tModelA columns");
120:                     $this->out("which returns a list of columns and their type");
121:                     $this->out('');
122:                     $this->out('Route testing:');
123:                     $this->out('To test URLs against your app\'s route configuration, type:');
124:                     $this->out("\tRoute <url>");
125:                     $this->out("where url is the path to your your action plus any query parameters, minus the");
126:                     $this->out("application's base path");
127:                     $this->out('');
128:                     $this->out('To reload your routes config (config/routes.php), do the following:');
129:                     $this->out("\tRoutes reload");
130:                     $this->out('');
131:                     $this->out('');
132:                     $this->out('To show all connected routes, do the following:');
133:                     $this->out("\tRoutes show");
134:                     $this->out('');
135:                 break;
136:                 case 'quit':
137:                 case 'exit':
138:                     return true;
139:                 break;
140:                 case 'models':
141:                     $this->out('Model classes:');
142:                     $this->hr();
143:                     foreach ($this->models as $model) {
144:                         $this->out(" - {$model}");
145:                     }
146:                 break;
147:                 case (preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp) == true):
148:                     foreach ($tmp as $data) {
149:                         $data = strip_tags($data);
150:                         $data = str_replace($this->badCommandChars, "", $data);
151:                     }
152: 
153:                     $modelA = $tmp[1];
154:                     $association = $tmp[2];
155:                     $modelB = $tmp[3];
156: 
157:                     if ($this->__isValidModel($modelA) && $this->__isValidModel($modelB) && in_array($association, $this->associations)) {
158:                         $this->{$modelA}->bindModel(array($association => array($modelB => array('className' => $modelB))), false);
159:                         $this->out("Created $association association between $modelA and $modelB");
160:                     } else {
161:                         $this->out("Please verify you are using valid models and association types");
162:                     }
163:                 break;
164:                 case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true):
165:                     foreach ($tmp as $data) {
166:                         $data = strip_tags($data);
167:                         $data = str_replace($this->badCommandChars, "", $data);
168:                     }
169: 
170:                     $modelA = $tmp[1];
171:                     $association = $tmp[2];
172:                     $modelB = $tmp[3];
173: 
174:                     // Verify that there is actually an association to unbind
175:                     $currentAssociations = $this->{$modelA}->getAssociated();
176:                     $validCurrentAssociation = false;
177: 
178:                     foreach ($currentAssociations as $model => $currentAssociation) {
179:                         if ($model == $modelB && $association == $currentAssociation) {
180:                             $validCurrentAssociation = true;
181:                         }
182:                     }
183: 
184:                     if ($this->__isValidModel($modelA) && $this->__isValidModel($modelB) && in_array($association, $this->associations) && $validCurrentAssociation) {
185:                         $this->{$modelA}->unbindModel(array($association => array($modelB)));
186:                         $this->out("Removed $association association between $modelA and $modelB");
187:                     } else {
188:                         $this->out("Please verify you are using valid models, valid current association, and valid association types");
189:                     }
190:                 break;
191:                 case (strpos($command, "->find") > 0):
192:                     // Remove any bad info
193:                     $command = strip_tags($command);
194:                     $command = str_replace($this->badCommandChars, "", $command);
195: 
196:                     // Do we have a valid model?
197:                     list($modelToCheck, $tmp) = explode('->', $command);
198: 
199:                     if ($this->__isValidModel($modelToCheck)) {
200:                         $findCommand = "\$data = \$this->$command;";
201:                         @eval($findCommand);
202: 
203:                         if (is_array($data)) {
204:                             foreach ($data as $idx => $results) {
205:                                 if (is_numeric($idx)) { // findAll() output
206:                                     foreach ($results as $modelName => $result) {
207:                                         $this->out("$modelName");
208: 
209:                                         foreach ($result as $field => $value) {
210:                                             if (is_array($value)) {
211:                                                 foreach ($value as $field2 => $value2) {
212:                                                     $this->out("\t$field2: $value2");
213:                                                 }
214: 
215:                                                 $this->out("");
216:                                             } else {
217:                                                 $this->out("\t$field: $value");
218:                                             }
219:                                         }
220:                                     }
221:                                 } else { // find() output
222:                                     $this->out($idx);
223: 
224:                                     foreach ($results as $field => $value) {
225:                                         if (is_array($value)) {
226:                                             foreach ($value as $field2 => $value2) {
227:                                                 $this->out("\t$field2: $value2");
228:                                             }
229: 
230:                                             $this->out("");
231:                                         } else {
232:                                             $this->out("\t$field: $value");
233:                                         }
234:                                     }
235:                                 }
236:                             }
237:                         } else {
238:                             $this->out("\nNo result set found");
239:                         }
240:                     } else {
241:                         $this->out("$modelToCheck is not a valid model");
242:                     }
243: 
244:                 break;
245:                 case (strpos($command, '->save') > 0):
246:                     // Validate the model we're trying to save here
247:                     $command = strip_tags($command);
248:                     $command = str_replace($this->badCommandChars, "", $command);
249:                     list($modelToSave, $tmp) = explode("->", $command);
250: 
251:                     if ($this->__isValidModel($modelToSave)) {
252:                         // Extract the array of data we are trying to build
253:                         list($foo, $data) = explode("->save", $command);
254:                         $data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data);
255:                         $saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));";
256:                         @eval($saveCommand);
257:                         $this->out('Saved record for ' . $modelToSave);
258:                     }
259:                 break;
260:                 case (preg_match("/^(\w+) columns/", $command, $tmp) == true):
261:                     $modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
262: 
263:                     if ($this->__isValidModel($modelToCheck)) {
264:                         // Get the column info for this model
265:                         $fieldsCommand = "\$data = \$this->{$modelToCheck}->getColumnTypes();";
266:                         @eval($fieldsCommand);
267: 
268:                         if (is_array($data)) {
269:                             foreach ($data as $field => $type) {
270:                                 $this->out("\t{$field}: {$type}");
271:                             }
272:                         }
273:                     } else {
274:                         $this->out("Please verify that you selected a valid model");
275:                     }
276:                 break;
277:                 case (preg_match("/^routes\s+reload/i", $command, $tmp) == true):
278:                     $router =& Router::getInstance();
279:                     if (!$this->__loadRoutes()) {
280:                         $this->out("There was an error loading the routes config.  Please check that the file");
281:                         $this->out("exists and is free of parse errors.");
282:                         break;
283:                     }
284:                     $this->out("Routes configuration reloaded, " . count($router->routes) . " routes connected");
285:                 break;
286:                 case (preg_match("/^routes\s+show/i", $command, $tmp) == true):
287:                     $router =& Router::getInstance();
288:                     $this->out(implode("\n", Set::extract($router->routes, '{n}.0')));
289:                 break;
290:                 case (preg_match("/^route\s+(.*)/i", $command, $tmp) == true):
291:                     $this->out(var_export(Router::parse($tmp[1]), true));
292:                 break;
293:                 default:
294:                     $this->out("Invalid command\n");
295:                 break;
296:             }
297:             $command = '';
298:         }
299:     }
300: /**
301:  * Tells if the specified model is included in the list of available models
302:  *
303:  * @param string $modelToCheck
304:  * @return boolean true if is an available model, false otherwise
305:  * @access private
306:  */
307:     function __isValidModel($modelToCheck) {
308:         return in_array($modelToCheck, $this->models);
309:     }
310: /**
311:  * Reloads the routes configuration from config/routes.php, and compiles
312:  * all routes found
313:  *
314:  * @return boolean True if config reload was a success, otherwise false
315:  * @access private
316:  */
317:     function __loadRoutes() {
318:         $router =& Router::getInstance();
319: 
320:         $router->reload();
321:         extract($router->getNamedExpressions());
322: 
323:         if (!@include(CONFIGS . 'routes.php')) {
324:             return false;
325:         }
326:         $router->parse('/');
327: 
328:         foreach (array_keys($router->getNamedExpressions()) as $var) {
329:             unset(${$var});
330:         }
331:         for ($i = 0; $i < count($router->routes); $i++) {
332:             $router->compile($i);
333:         }
334:         return true;
335:     }
336: }
337: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs