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.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.3
      • 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
  • BakeTask
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeRoute
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbConfigTask
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • FileLog
  • FixtureTask
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • MootoolsEngineHelper
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginShortRoute
  • PluginTask
  • ProjectTask
  • PrototypeEngineHelper
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • Set
  • Shell
  • String
  • TemplateTask
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • 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
   1: <?php
   2: /**
   3:  * App and Configure classes
   4:  *
   5:  * PHP versions 4 and 5
   6:  *
   7:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
   8:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
   9:  *
  10:  * Licensed under The MIT License
  11:  * Redistributions of files must retain the above copyright notice.
  12:  *
  13:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14:  * @link          http://cakephp.org CakePHP(tm) Project
  15:  * @package       cake
  16:  * @subpackage    cake.cake.libs
  17:  * @since         CakePHP(tm) v 1.0.0.2363
  18:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  19:  */
  20: 
  21: /**
  22:  * Configuration class (singleton). Used for managing runtime configuration information.
  23:  *
  24:  * @package       cake
  25:  * @subpackage    cake.cake.libs
  26:  * @link          http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#the-configuration-class
  27:  */
  28: class Configure extends Object {
  29: 
  30: /**
  31:  * Current debug level.
  32:  *
  33:  * @link          http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#cakephp-core-configuration-variables
  34:  * @var integer
  35:  * @access public
  36:  */
  37:     var $debug = 0;
  38: 
  39: /**
  40:  * Returns a singleton instance of the Configure class.
  41:  *
  42:  * @return Configure instance
  43:  * @access public
  44:  */
  45:     function &getInstance($boot = true) {
  46:         static $instance = array();
  47:         if (!$instance) {
  48:             if (!class_exists('Set')) {
  49:                 require LIBS . 'set.php';
  50:             }
  51:             $instance[0] =& new Configure();
  52:             $instance[0]->__loadBootstrap($boot);
  53:         }
  54:         return $instance[0];
  55:     }
  56: 
  57: /**
  58:  * Used to store a dynamic variable in the Configure instance.
  59:  *
  60:  * Usage:
  61:  * {{{
  62:  * Configure::write('One.key1', 'value of the Configure::One[key1]');
  63:  * Configure::write(array('One.key1' => 'value of the Configure::One[key1]'));
  64:  * Configure::write('One', array(
  65:  *     'key1' => 'value of the Configure::One[key1]',
  66:  *     'key2' => 'value of the Configure::One[key2]'
  67:  * );
  68:  *
  69:  * Configure::write(array(
  70:  *     'One.key1' => 'value of the Configure::One[key1]',
  71:  *     'One.key2' => 'value of the Configure::One[key2]'
  72:  * ));
  73:  * }}}
  74:  *
  75:  * @link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#write
  76:  * @link http://book.cakephp.org/view/926/write
  77:  * @param array $config Name of var to write
  78:  * @param mixed $value Value to set for var
  79:  * @return boolean True if write was successful
  80:  * @access public
  81:  */
  82:     function write($config, $value = null) {
  83:         $_this =& Configure::getInstance();
  84: 
  85:         if (!is_array($config)) {
  86:             $config = array($config => $value);
  87:         }
  88: 
  89:         foreach ($config as $name => $value) {
  90:             if (strpos($name, '.') === false) {
  91:                 $_this->{$name} = $value;
  92:             } else {
  93:                 $names = explode('.', $name, 4);
  94:                 switch (count($names)) {
  95:                     case 2:
  96:                         $_this->{$names[0]}[$names[1]] = $value;
  97:                     break;
  98:                     case 3:
  99:                         $_this->{$names[0]}[$names[1]][$names[2]] = $value;
 100:                         break;
 101:                     case 4:
 102:                         $names = explode('.', $name, 2);
 103:                         if (!isset($_this->{$names[0]})) {
 104:                             $_this->{$names[0]} = array();
 105:                         }
 106:                         $_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
 107:                     break;
 108:                 }
 109:             }
 110:         }
 111: 
 112:         if (isset($config['debug']) || isset($config['log'])) {
 113:             $reporting = 0;
 114:             if ($_this->debug) {
 115:                 if (!class_exists('Debugger')) {
 116:                     require LIBS . 'debugger.php';
 117:                 }
 118:                 $reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT;
 119:                 if (function_exists('ini_set')) {
 120:                     ini_set('display_errors', 1);
 121:                 }
 122:                 $callback = array('Debugger', 'getInstance');
 123:             } elseif (function_exists('ini_set')) {
 124:                 ini_set('display_errors', 0);
 125:             }
 126: 
 127:             if (isset($_this->log) && $_this->log) {
 128:                 if (is_integer($_this->log) && !$_this->debug) {
 129:                     $reporting = $_this->log;
 130:                 } else {
 131:                     $reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT;
 132:                 }
 133:                 error_reporting($reporting);
 134:                 if (!class_exists('CakeLog')) {
 135:                     require LIBS . 'cake_log.php';
 136:                 }
 137:                 if (empty($callback)) {
 138:                     $callback = array('CakeLog', 'getInstance');
 139:                 }
 140:             }
 141:             if (!empty($callback) && !defined('DISABLE_DEFAULT_ERROR_HANDLING') && class_exists('Debugger')) {
 142:                 Debugger::invoke(call_user_func($callback));
 143:             }
 144:             error_reporting($reporting);
 145:         }
 146:         return true;
 147:     }
 148: 
 149: /**
 150:  * Used to read information stored in the Configure instance.
 151:  *
 152:  * Usage:
 153:  * {{{
 154:  * Configure::read('Name'); will return all values for Name
 155:  * Configure::read('Name.key'); will return only the value of Configure::Name[key]
 156:  * }}}
 157:  *
 158:  * @link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#read
 159:  * @param string $var Variable to obtain.  Use '.' to access array elements.
 160:  * @return string value of Configure::$var
 161:  * @access public
 162:  */
 163:     function read($var = 'debug') {
 164:         $_this =& Configure::getInstance();
 165: 
 166:         if ($var === 'debug') {
 167:             return $_this->debug;
 168:         }
 169: 
 170:         if (strpos($var, '.') !== false) {
 171:             $names = explode('.', $var, 3);
 172:             $var = $names[0];
 173:         }
 174:         if (!isset($_this->{$var})) {
 175:             return null;
 176:         }
 177:         if (!isset($names[1])) {
 178:             return $_this->{$var};
 179:         }
 180:         switch (count($names)) {
 181:             case 2:
 182:                 if (isset($_this->{$var}[$names[1]])) {
 183:                     return $_this->{$var}[$names[1]];
 184:                 }
 185:             break;
 186:             case 3:
 187:                 if (isset($_this->{$var}[$names[1]][$names[2]])) {
 188:                     return $_this->{$var}[$names[1]][$names[2]];
 189:                 }
 190:                 if (!isset($_this->{$var}[$names[1]])) {
 191:                     return null;
 192:                 }
 193:                 return Set::classicExtract($_this->{$var}[$names[1]], $names[2]);
 194:             break;
 195:         }
 196:         return null;
 197:     }
 198: 
 199: /**
 200:  * Used to delete a variable from the Configure instance.
 201:  *
 202:  * Usage:
 203:  * {{{
 204:  * Configure::delete('Name'); will delete the entire Configure::Name
 205:  * Configure::delete('Name.key'); will delete only the Configure::Name[key]
 206:  * }}}
 207:  *
 208:  * @link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#delete
 209:  * @param string $var the var to be deleted
 210:  * @return void
 211:  * @access public
 212:  */
 213:     function delete($var = null) {
 214:         $_this =& Configure::getInstance();
 215: 
 216:         if (strpos($var, '.') === false) {
 217:             unset($_this->{$var});
 218:             return;
 219:         }
 220: 
 221:         $names = explode('.', $var, 2);
 222:         $_this->{$names[0]} = Set::remove($_this->{$names[0]}, $names[1]);
 223:     }
 224: 
 225: /**
 226:  * Loads a file from app/config/configure_file.php.
 227:  * Config file variables should be formated like:
 228:  *  `$config['name'] = 'value';`
 229:  * These will be used to create dynamic Configure vars. load() is also used to
 230:  * load stored config files created with Configure::store()
 231:  *
 232:  * - To load config files from app/config use `Configure::load('configure_file');`.
 233:  * - To load config files from a plugin `Configure::load('plugin.configure_file');`.
 234:  *
 235:  * @link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#load
 236:  * @param string $fileName name of file to load, extension must be .php and only the name
 237:  *     should be used, not the extenstion
 238:  * @return mixed false if file not found, void if load successful
 239:  * @access public
 240:  */
 241:     function load($fileName) {
 242:         $found = $plugin = $pluginPath = false;
 243:         list($plugin, $fileName) = pluginSplit($fileName);
 244:         if ($plugin) {
 245:             $pluginPath = App::pluginPath($plugin);
 246:         }
 247:         $pos = strpos($fileName, '..');
 248: 
 249:         if ($pos === false) {
 250:             if ($pluginPath && file_exists($pluginPath . 'config' . DS . $fileName . '.php')) {
 251:                 include($pluginPath . 'config' . DS . $fileName . '.php');
 252:                 $found = true;
 253:             } elseif (file_exists(CONFIGS . $fileName . '.php')) {
 254:                 include(CONFIGS . $fileName . '.php');
 255:                 $found = true;
 256:             } elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {
 257:                 include(CACHE . 'persistent' . DS . $fileName . '.php');
 258:                 $found = true;
 259:             } else {
 260:                 foreach (App::core('cake') as $key => $path) {
 261:                     if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) {
 262:                         include($path . DS . 'config' . DS . $fileName . '.php');
 263:                         $found = true;
 264:                         break;
 265:                     }
 266:                 }
 267:             }
 268:         }
 269: 
 270:         if (!$found) {
 271:             return false;
 272:         }
 273: 
 274:         if (!isset($config)) {
 275:             trigger_error(sprintf(__('Configure::load() - no variable $config found in %s.php', true), $fileName), E_USER_WARNING);
 276:             return false;
 277:         }
 278:         return Configure::write($config);
 279:     }
 280: 
 281: /**
 282:  * Used to determine the current version of CakePHP.
 283:  *
 284:  * Usage `Configure::version();`
 285:  *
 286:  * @link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#version
 287:  * @return string Current version of CakePHP
 288:  * @access public
 289:  */
 290:     function version() {
 291:         $_this =& Configure::getInstance();
 292: 
 293:         if (!isset($_this->Cake['version'])) {
 294:             require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
 295:             $_this->write($config);
 296:         }
 297:         return $_this->Cake['version'];
 298:     }
 299: 
 300: /**
 301:  * Used to write a config file to disk.
 302:  *
 303:  * {{{
 304:  * Configure::store('Model', 'class_paths', array('Users' => array(
 305:  *      'path' => 'users', 'plugin' => true
 306:  * )));
 307:  * }}}
 308:  *
 309:  * @param string $type Type of config file to write, ex: Models, Controllers, Helpers, Components
 310:  * @param string $name file name.
 311:  * @param array $data array of values to store.
 312:  * @return void
 313:  * @access public
 314:  */
 315:     function store($type, $name, $data = array()) {
 316:         $write = true;
 317:         $content = '';
 318: 
 319:         foreach ($data as $key => $value) {
 320:             $content .= "\$config['$type']['$key'] = " . var_export($value, true) . ";\n";
 321:         }
 322:         if (is_null($type)) {
 323:             $write = false;
 324:         }
 325:         Configure::__writeConfig($content, $name, $write);
 326:     }
 327: 
 328: /**
 329:  * Creates a cached version of a configuration file.
 330:  * Appends values passed from Configure::store() to the cached file
 331:  *
 332:  * @param string $content Content to write on file
 333:  * @param string $name Name to use for cache file
 334:  * @param boolean $write true if content should be written, false otherwise
 335:  * @return void
 336:  * @access private
 337:  */
 338:     function __writeConfig($content, $name, $write = true) {
 339:         $file = CACHE . 'persistent' . DS . $name . '.php';
 340: 
 341:         if (Configure::read() > 0) {
 342:             $expires = "+10 seconds";
 343:         } else {
 344:             $expires = "+999 days";
 345:         }
 346:         $cache = cache('persistent' . DS . $name . '.php', null, $expires);
 347: 
 348:         if ($cache === null) {
 349:             cache('persistent' . DS . $name . '.php', "<?php\n\$config = array();\n", $expires);
 350:         }
 351: 
 352:         if ($write === true) {
 353:             if (!class_exists('File')) {
 354:                 require LIBS . 'file.php';
 355:             }
 356:             $fileClass = new File($file);
 357: 
 358:             if ($fileClass->writable()) {
 359:                 $fileClass->append($content);
 360:             }
 361:         }
 362:     }
 363: 
 364: /**
 365:  * @deprecated
 366:  * @see App::objects()
 367:  */
 368:     function listObjects($type, $path = null, $cache = true) {
 369:         return App::objects($type, $path, $cache);
 370:     }
 371: 
 372: /**
 373:  * @deprecated
 374:  * @see App::core()
 375:  */
 376:     function corePaths($type = null) {
 377:         return App::core($type);
 378:     }
 379: 
 380: /**
 381:  * @deprecated
 382:  * @see App::build()
 383:  */
 384:     function buildPaths($paths) {
 385:         return App::build($paths);
 386:     }
 387: 
 388: /**
 389:  * Loads app/config/bootstrap.php.
 390:  * If the alternative paths are set in this file
 391:  * they will be added to the paths vars.
 392:  *
 393:  * @param boolean $boot Load application bootstrap (if true)
 394:  * @return void
 395:  * @access private
 396:  */
 397:     function __loadBootstrap($boot) {
 398:         if ($boot) {
 399:             Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT));
 400: 
 401:             if (!include(CONFIGS . 'core.php')) {
 402:                 trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
 403:             }
 404: 
 405:             if (Configure::read('Cache.disable') !== true) {
 406:                 $cache = Cache::config('default');
 407: 
 408:                 if (empty($cache['settings'])) {
 409:                     trigger_error(__('Cache not configured properly. Please check Cache::config(); in APP/config/core.php', true), E_USER_WARNING);
 410:                     $cache = Cache::config('default', array('engine' => 'File'));
 411:                 }
 412:                 $path = $prefix = $duration = null;
 413: 
 414:                 if (!empty($cache['settings']['path'])) {
 415:                     $path = realpath($cache['settings']['path']);
 416:                 } else {
 417:                     $prefix = $cache['settings']['prefix'];
 418:                 }
 419: 
 420:                 if (Configure::read() >= 1) {
 421:                     $duration = '+10 seconds';
 422:                 } else {
 423:                     $duration = '+999 days';
 424:                 }
 425: 
 426:                 if (Cache::config('_cake_core_') === false) {
 427:                     Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
 428:                         'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
 429:                         'serialize' => true, 'duration' => $duration
 430:                     )));
 431:                 }
 432: 
 433:                 if (Cache::config('_cake_model_') === false) {
 434:                     Cache::config('_cake_model_', array_merge((array)$cache['settings'], array(
 435:                         'prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS,
 436:                         'serialize' => true, 'duration' => $duration
 437:                     )));
 438:                 }
 439:                 Cache::config('default');
 440:             }
 441:             App::build();
 442:             if (!include(CONFIGS . 'bootstrap.php')) {
 443:                 trigger_error(sprintf(__("Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
 444:             }
 445:         }
 446:     }
 447: }
 448: 
 449: /**
 450:  * Class/file loader and path management.
 451:  *
 452:  * @link          http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#the-app-class
 453:  * @since         CakePHP(tm) v 1.2.0.6001
 454:  * @package       cake
 455:  * @subpackage    cake.cake.libs
 456:  */
 457: class App extends Object {
 458: 
 459: /**
 460:  * List of object types and their properties
 461:  *
 462:  * @var array
 463:  * @access public
 464:  */
 465:     var $types = array(
 466:         'class' => array('suffix' => '.php', 'extends' => null, 'core' => true),
 467:         'file' => array('suffix' => '.php', 'extends' => null, 'core' => true),
 468:         'model' => array('suffix' => '.php', 'extends' => 'AppModel', 'core' => false),
 469:         'behavior' => array('suffix' => '.php', 'extends' => 'ModelBehavior', 'core' => true),
 470:         'controller' => array('suffix' => '_controller.php', 'extends' => 'AppController', 'core' => true),
 471:         'component' => array('suffix' => '.php', 'extends' => null, 'core' => true),
 472:         'lib' => array('suffix' => '.php', 'extends' => null, 'core' => true),
 473:         'view' => array('suffix' => '.php', 'extends' => null, 'core' => true),
 474:         'helper' => array('suffix' => '.php', 'extends' => 'AppHelper', 'core' => true),
 475:         'vendor' => array('suffix' => '', 'extends' => null, 'core' => true),
 476:         'shell' => array('suffix' => '.php', 'extends' => 'Shell', 'core' => true),
 477:         'plugin' => array('suffix' => '', 'extends' => null, 'core' => true)
 478:     );
 479: 
 480: /**
 481:  * List of additional path(s) where model files reside.
 482:  *
 483:  * @var array
 484:  * @access public
 485:  */
 486:     var $models = array();
 487: 
 488: /**
 489:  * List of additional path(s) where behavior files reside.
 490:  *
 491:  * @var array
 492:  * @access public
 493:  */
 494:     var $behaviors = array();
 495: 
 496: /**
 497:  * List of additional path(s) where controller files reside.
 498:  *
 499:  * @var array
 500:  * @access public
 501:  */
 502:     var $controllers = array();
 503: 
 504: /**
 505:  * List of additional path(s) where component files reside.
 506:  *
 507:  * @var array
 508:  * @access public
 509:  */
 510:     var $components = array();
 511: 
 512: /**
 513:  * List of additional path(s) where datasource files reside.
 514:  *
 515:  * @var array
 516:  * @access public
 517:  */
 518:     var $datasources = array();
 519: 
 520: /**
 521:  * List of additional path(s) where libs files reside.
 522:  *
 523:  * @var array
 524:  * @access public
 525:  */
 526:     var $libs = array();
 527: /**
 528:  * List of additional path(s) where view files reside.
 529:  *
 530:  * @var array
 531:  * @access public
 532:  */
 533:     var $views = array();
 534: 
 535: /**
 536:  * List of additional path(s) where helper files reside.
 537:  *
 538:  * @var array
 539:  * @access public
 540:  */
 541:     var $helpers = array();
 542: 
 543: /**
 544:  * List of additional path(s) where plugins reside.
 545:  *
 546:  * @var array
 547:  * @access public
 548:  */
 549:     var $plugins = array();
 550: 
 551: /**
 552:  * List of additional path(s) where vendor packages reside.
 553:  *
 554:  * @var array
 555:  * @access public
 556:  */
 557:     var $vendors = array();
 558: 
 559: /**
 560:  * List of additional path(s) where locale files reside.
 561:  *
 562:  * @var array
 563:  * @access public
 564:  */
 565:     var $locales = array();
 566: 
 567: /**
 568:  * List of additional path(s) where console shell files reside.
 569:  *
 570:  * @var array
 571:  * @access public
 572:  */
 573:     var $shells = array();
 574: 
 575: /**
 576:  * Paths to search for files.
 577:  *
 578:  * @var array
 579:  * @access public
 580:  */
 581:     var $search = array();
 582: 
 583: /**
 584:  * Whether or not to return the file that is loaded.
 585:  *
 586:  * @var boolean
 587:  * @access public
 588:  */
 589:     var $return = false;
 590: 
 591: /**
 592:  * Holds key/value pairs of $type => file path.
 593:  *
 594:  * @var array
 595:  * @access private
 596:  */
 597:     var $__map = array();
 598: 
 599: /**
 600:  * Holds paths for deep searching of files.
 601:  *
 602:  * @var array
 603:  * @access private
 604:  */
 605:     var $__paths = array();
 606: 
 607: /**
 608:  * Holds loaded files.
 609:  *
 610:  * @var array
 611:  * @access private
 612:  */
 613:     var $__loaded = array();
 614: 
 615: /**
 616:  * Holds and key => value array of object types.
 617:  *
 618:  * @var array
 619:  * @access private
 620:  */
 621:     var $__objects = array();
 622: 
 623: /**
 624:  * Used to read information stored path
 625:  *
 626:  * Usage:
 627:  *
 628:  * `App::path('models'); will return all paths for models`
 629:  *
 630:  * @param string $type type of path
 631:  * @return string array
 632:  * @access public
 633:  */
 634:     function path($type) {
 635:         $_this =& App::getInstance();
 636:         if (!isset($_this->{$type})) {
 637:             return array();
 638:         }
 639:         return $_this->{$type};
 640:     }
 641: 
 642: /**
 643:  * Build path references. Merges the supplied $paths
 644:  * with the base paths and the default core paths.
 645:  *
 646:  * @param array $paths paths defines in config/bootstrap.php
 647:  * @param boolean $reset true will set paths, false merges paths [default] false
 648:  * @return void
 649:  * @access public
 650:  */
 651:     function build($paths = array(), $reset = false) {
 652:         $_this =& App::getInstance();
 653:         $defaults = array(
 654:             'models' => array(MODELS),
 655:             'behaviors' => array(BEHAVIORS),
 656:             'datasources' => array(MODELS . 'datasources'),
 657:             'controllers' => array(CONTROLLERS),
 658:             'components' => array(COMPONENTS),
 659:             'libs' => array(APPLIBS),
 660:             'views' => array(VIEWS),
 661:             'helpers' => array(HELPERS),
 662:             'locales' => array(APP . 'locale' . DS),
 663:             'shells' => array(APP . 'vendors' . DS . 'shells' . DS, VENDORS . 'shells' . DS),
 664:             'vendors' => array(APP . 'vendors' . DS, VENDORS),
 665:             'plugins' => array(APP . 'plugins' . DS)
 666:         );
 667: 
 668:         if ($reset == true) {
 669:             foreach ($paths as $type => $new) {
 670:                 $_this->{$type} = (array)$new;
 671:             }
 672:             return $paths;
 673:         }
 674: 
 675:         $core = $_this->core();
 676:         $app = array('models' => true, 'controllers' => true, 'helpers' => true);
 677: 
 678:         foreach ($defaults as $type => $default) {
 679:             $merge = array();
 680: 
 681:             if (isset($app[$type])) {
 682:                 $merge = array(APP);
 683:             }
 684:             if (isset($core[$type])) {
 685:                 $merge = array_merge($merge, (array)$core[$type]);
 686:             }
 687: 
 688:             if (empty($_this->{$type}) || empty($paths)) {
 689:                 $_this->{$type} = $default;
 690:             }
 691: 
 692:             if (!empty($paths[$type])) {
 693:                 $path = array_flip(array_flip(array_merge(
 694:                     (array)$paths[$type], $_this->{$type}, $merge
 695:                 )));
 696:                 $_this->{$type} = array_values($path);
 697:             } else {
 698:                 $path = array_flip(array_flip(array_merge($_this->{$type}, $merge)));
 699:                 $_this->{$type} = array_values($path);
 700:             }
 701:         }
 702:     }
 703: 
 704: /**
 705:  * Get the path that a plugin is on.  Searches through the defined plugin paths.
 706:  *
 707:  * @param string $plugin CamelCased/lower_cased plugin name to find the path of.
 708:  * @return string full path to the plugin.
 709:  */
 710:     function pluginPath($plugin) {
 711:         $_this =& App::getInstance();
 712:         $pluginDir = Inflector::underscore($plugin);
 713:         for ($i = 0, $length = count($_this->plugins); $i < $length; $i++) {
 714:             if (is_dir($_this->plugins[$i] . $pluginDir)) {
 715:                 return $_this->plugins[$i] . $pluginDir . DS ;
 716:             }
 717:         }
 718:         return $_this->plugins[0] . $pluginDir . DS;
 719:     }
 720: 
 721: /**
 722:  * Find the path that a theme is on.  Search through the defined theme paths.
 723:  *
 724:  * @param string $theme lower_cased theme name to find the path of.
 725:  * @return string full path to the theme.
 726:  */
 727:     function themePath($theme) {
 728:         $_this =& App::getInstance();
 729:         $themeDir = 'themed' . DS . Inflector::underscore($theme);
 730:         for ($i = 0, $length = count($_this->views); $i < $length; $i++) {
 731:             if (is_dir($_this->views[$i] . $themeDir)) {
 732:                 return $_this->views[$i] . $themeDir . DS ;
 733:             }
 734:         }
 735:         return $_this->views[0] . $themeDir . DS;
 736:     }
 737: 
 738: /**
 739:  * Returns a key/value list of all paths where core libs are found.
 740:  * Passing $type only returns the values for a given value of $key.
 741:  *
 742:  * @param string $type valid values are: 'model', 'behavior', 'controller', 'component',
 743:  *    'view', 'helper', 'datasource', 'libs', and 'cake'
 744:  * @return array numeric keyed array of core lib paths
 745:  * @access public
 746:  */
 747:     function core($type = null) {
 748:         static $paths = false;
 749:         if ($paths === false) {
 750:             $paths = Cache::read('core_paths', '_cake_core_');
 751:         }
 752:         if (!$paths) {
 753:             $paths = array();
 754:             $libs = dirname(__FILE__) . DS;
 755:             $cake = dirname($libs) . DS;
 756:             $path = dirname($cake) . DS;
 757: 
 758:             $paths['cake'][] = $cake;
 759:             $paths['libs'][] = $libs;
 760:             $paths['models'][] = $libs . 'model' . DS;
 761:             $paths['datasources'][] = $libs . 'model' . DS . 'datasources' . DS;
 762:             $paths['behaviors'][] = $libs . 'model' . DS . 'behaviors' . DS;
 763:             $paths['controllers'][] = $libs . 'controller' . DS;
 764:             $paths['components'][] = $libs . 'controller' . DS . 'components' . DS;
 765:             $paths['views'][] = $libs . 'view' . DS;
 766:             $paths['helpers'][] = $libs . 'view' . DS . 'helpers' . DS;
 767:             $paths['plugins'][] = $path . 'plugins' . DS;
 768:             $paths['vendors'][] = $path . 'vendors' . DS;
 769:             $paths['shells'][] = $cake . 'console' . DS . 'libs' . DS;
 770: 
 771:             Cache::write('core_paths', array_filter($paths), '_cake_core_');
 772:         }
 773:         if ($type && isset($paths[$type])) {
 774:             return $paths[$type];
 775:         }
 776:         return $paths;
 777:     }
 778: 
 779: /**
 780:  * Returns an array of objects of the given type.
 781:  *
 782:  * Example usage:
 783:  *
 784:  * `App::objects('plugin');` returns `array('DebugKit', 'Blog', 'User');`
 785:  *
 786:  * @param string $type Type of object, i.e. 'model', 'controller', 'helper', or 'plugin'
 787:  * @param mixed $path Optional Scan only the path given. If null, paths for the chosen
 788:  *   type will be used.
 789:  * @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true.
 790:  * @return mixed Either false on incorrect / miss.  Or an array of found objects.
 791:  * @access public
 792:  */
 793:     function objects($type, $path = null, $cache = true) {
 794:         $objects = array();
 795:         $extension = false;
 796:         $name = $type;
 797: 
 798:         if ($type === 'file' && !$path) {
 799:             return false;
 800:         } elseif ($type === 'file') {
 801:             $extension = true;
 802:             $name = $type . str_replace(DS, '', $path);
 803:         }
 804:         $_this =& App::getInstance();
 805: 
 806:         if (empty($_this->__objects) && $cache === true) {
 807:             $_this->__objects = Cache::read('object_map', '_cake_core_');
 808:         }
 809: 
 810:         if (!isset($_this->__objects[$name]) || $cache !== true) {
 811:             $types = $_this->types;
 812: 
 813:             if (!isset($types[$type])) {
 814:                 return false;
 815:             }
 816:             $objects = array();
 817: 
 818:             if (empty($path)) {
 819:                 $path = $_this->{"{$type}s"};
 820:                 if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
 821:                     array_pop($path);
 822:                 }
 823:             }
 824:             $items = array();
 825: 
 826:             foreach ((array)$path as $dir) {
 827:                 if ($dir != APP) {
 828:                     $items = $_this->__list($dir, $types[$type]['suffix'], $extension);
 829:                     $objects = array_merge($items, array_diff($objects, $items));
 830:                 }
 831:             }
 832: 
 833:             if ($type !== 'file') {
 834:                 foreach ($objects as $key => $value) {
 835:                     $objects[$key] = Inflector::camelize($value);
 836:                 }
 837:             }
 838: 
 839:             if ($cache === true) {
 840:                 $_this->__resetCache(true);
 841:             }
 842:             $_this->__objects[$name] = $objects;
 843:         }
 844: 
 845:         return $_this->__objects[$name];
 846:     }
 847: 
 848: /**
 849:  * Finds classes based on $name or specific file(s) to search.  Calling App::import() will
 850:  * not construct any classes contained in the files. It will only find and require() the file.
 851:  *
 852:  * @link http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html#using-app-import
 853:  * @param mixed $type The type of Class if passed as a string, or all params can be passed as
 854:  *                    an single array to $type,
 855:  * @param string $name Name of the Class or a unique name for the file
 856:  * @param mixed $parent boolean true if Class Parent should be searched, accepts key => value
 857:  *              array('parent' => $parent ,'file' => $file, 'search' => $search, 'ext' => '$ext');
 858:  *              $ext allows setting the extension of the file name
 859:  *              based on Inflector::underscore($name) . ".$ext";
 860:  * @param array $search paths to search for files, array('path 1', 'path 2', 'path 3');
 861:  * @param string $file full name of the file to search for including extension
 862:  * @param boolean $return, return the loaded file, the file must have a return
 863:  *                         statement in it to work: return $variable;
 864:  * @return boolean true if Class is already in memory or if file is found and loaded, false if not
 865:  * @access public
 866:  */
 867:     function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
 868:         $plugin = $directory = null;
 869: 
 870:         if (is_array($type)) {
 871:             extract($type, EXTR_OVERWRITE);
 872:         }
 873: 
 874:         if (is_array($parent)) {
 875:             extract($parent, EXTR_OVERWRITE);
 876:         }
 877: 
 878:         if ($name === null && $file === null) {
 879:             $name = $type;
 880:             $type = 'Core';
 881:         } elseif ($name === null) {
 882:             $type = 'File';
 883:         }
 884: 
 885:         if (is_array($name)) {
 886:             foreach ($name as $class) {
 887:                 $tempType = $type;
 888:                 $plugin = null;
 889: 
 890:                 if (strpos($class, '.') !== false) {
 891:                     $value = explode('.', $class);
 892:                     $count = count($value);
 893: 
 894:                     if ($count > 2) {
 895:                         $tempType = $value[0];
 896:                         $plugin = $value[1] . '.';
 897:                         $class = $value[2];
 898:                     } elseif ($count === 2 && ($type === 'Core' || $type === 'File')) {
 899:                         $tempType = $value[0];
 900:                         $class = $value[1];
 901:                     } else {
 902:                         $plugin = $value[0] . '.';
 903:                         $class = $value[1];
 904:                     }
 905:                 }
 906: 
 907:                 if (!App::import($tempType, $plugin . $class, $parent)) {
 908:                     return false;
 909:                 }
 910:             }
 911:             return true;
 912:         }
 913: 
 914:         if ($name != null && strpos($name, '.') !== false) {
 915:             list($plugin, $name) = explode('.', $name);
 916:             $plugin = Inflector::camelize($plugin);
 917:         }
 918:         $_this =& App::getInstance();
 919:         $_this->return = $return;
 920: 
 921:         if (isset($ext)) {
 922:             $file = Inflector::underscore($name) . ".{$ext}";
 923:         }
 924:         $ext = $_this->__settings($type, $plugin, $parent);
 925:         if ($name != null && !class_exists($name . $ext['class'])) {
 926:             if ($load = $_this->__mapped($name . $ext['class'], $type, $plugin)) {
 927:                 if ($_this->__load($load)) {
 928:                     $_this->__overload($type, $name . $ext['class'], $parent);
 929: 
 930:                     if ($_this->return) {
 931:                         return include($load);
 932:                     }
 933:                     return true;
 934:                 } else {
 935:                     $_this->__remove($name . $ext['class'], $type, $plugin);
 936:                     $_this->__resetCache(true);
 937:                 }
 938:             }
 939:             if (!empty($search)) {
 940:                 $_this->search = $search;
 941:             } elseif ($plugin) {
 942:                 $_this->search = $_this->__paths('plugin');
 943:             } else {
 944:                 $_this->search = $_this->__paths($type);
 945:             }
 946:             $find = $file;
 947: 
 948:             if ($find === null) {
 949:                 $find = Inflector::underscore($name . $ext['suffix']).'.php';
 950: 
 951:                 if ($plugin) {
 952:                     $paths = $_this->search;
 953:                     foreach ($paths as $key => $value) {
 954:                         $_this->search[$key] = $value . $ext['path'];
 955:                     }
 956:                 }
 957:             }
 958: 
 959:             if (strtolower($type) !== 'vendor' && empty($search) && $_this->__load($file)) {
 960:                 $directory = false;
 961:             } else {
 962:                 $file = $find;
 963:                 $directory = $_this->__find($find, true);
 964:             }
 965: 
 966:             if ($directory !== null) {
 967:                 $_this->__resetCache(true);
 968:                 $_this->__map($directory . $file, $name . $ext['class'], $type, $plugin);
 969:                 $_this->__overload($type, $name . $ext['class'], $parent);
 970: 
 971:                 if ($_this->return) {
 972:                     return include($directory . $file);
 973:                 }
 974:                 return true;
 975:             }
 976:             return false;
 977:         }
 978:         return true;
 979:     }
 980: 
 981: /**
 982:  * Returns a single instance of App.
 983:  *
 984:  * @return object
 985:  * @access public
 986:  */
 987:     function &getInstance() {
 988:         static $instance = array();
 989:         if (!$instance) {
 990:             $instance[0] =& new App();
 991:             $instance[0]->__map = (array)Cache::read('file_map', '_cake_core_');
 992:         }
 993:         return $instance[0];
 994:     }
 995: 
 996: /**
 997:  * Locates the $file in $__paths, searches recursively.
 998:  *
 999:  * @param string $file full file name
1000:  * @param boolean $recursive search $__paths recursively
1001:  * @return mixed boolean on fail, $file directory path on success
1002:  * @access private
1003:  */
1004:     function __find($file, $recursive = true) {
1005:         static $appPath = false;
1006: 
1007:         if (empty($this->search)) {
1008:             return null;
1009:         } elseif (is_string($this->search)) {
1010:             $this->search = array($this->search);
1011:         }
1012: 
1013:         if (empty($this->__paths)) {
1014:             $this->__paths = Cache::read('dir_map', '_cake_core_');
1015:         }
1016: 
1017:         foreach ($this->search as $path) {
1018:             if ($appPath === false) {
1019:                 $appPath = rtrim(APP, DS);
1020:             }
1021:             $path = rtrim($path, DS);
1022: 
1023:             if ($path === $appPath) {
1024:                 $recursive = false;
1025:             }
1026:             if ($recursive === false) {
1027:                 if ($this->__load($path . DS . $file)) {
1028:                     return $path . DS;
1029:                 }
1030:                 continue;
1031:             }
1032: 
1033:             if (!isset($this->__paths[$path])) {
1034:                 if (!class_exists('Folder')) {
1035:                     require LIBS . 'folder.php';
1036:                 }
1037:                 $Folder =& new Folder();
1038:                 $ignorePaths = array('.svn', '.git', 'CVS', 'tests', 'templates', 'node_modules');
1039:                 $directories = $Folder->tree($path, $ignorePaths, 'dir');
1040:                 sort($directories);
1041:                 $this->__paths[$path] = $directories;
1042:             }
1043: 
1044:             foreach ($this->__paths[$path] as $directory) {
1045:                 if ($this->__load($directory . DS . $file)) {
1046:                     return $directory . DS;
1047:                 }
1048:             }
1049:         }
1050:         return null;
1051:     }
1052: 
1053: /**
1054:  * Attempts to load $file.
1055:  *
1056:  * @param string $file full path to file including file name
1057:  * @return boolean
1058:  * @access private
1059:  */
1060:     function __load($file) {
1061:         if (empty($file)) {
1062:             return false;
1063:         }
1064:         if (!$this->return && isset($this->__loaded[$file])) {
1065:             return true;
1066:         }
1067:         if (file_exists($file)) {
1068:             if (!$this->return) {
1069:                 $this->__loaded[$file] = true;
1070:                 require($file);
1071:             }
1072:             return true;
1073:         }
1074:         return false;
1075:     }
1076: 
1077: /**
1078:  * Maps the $name to the $file.
1079:  *
1080:  * @param string $file full path to file
1081:  * @param string $name unique name for this map
1082:  * @param string $type type object being mapped
1083:  * @param string $plugin camelized if object is from a plugin, the name of the plugin
1084:  * @return void
1085:  * @access private
1086:  */
1087:     function __map($file, $name, $type, $plugin) {
1088:         if ($plugin) {
1089:             $this->__map['Plugin'][$plugin][$type][$name] = $file;
1090:         } else {
1091:             $this->__map[$type][$name] = $file;
1092:         }
1093:     }
1094: 
1095: /**
1096:  * Returns a file's complete path.
1097:  *
1098:  * @param string $name unique name
1099:  * @param string $type type object
1100:  * @param string $plugin camelized if object is from a plugin, the name of the plugin
1101:  * @return mixed, file path if found, false otherwise
1102:  * @access private
1103:  */
1104:     function __mapped($name, $type, $plugin) {
1105:         if ($plugin) {
1106:             if (isset($this->__map['Plugin'][$plugin][$type]) && isset($this->__map['Plugin'][$plugin][$type][$name])) {
1107:                 return $this->__map['Plugin'][$plugin][$type][$name];
1108:             }
1109:             return false;
1110:         }
1111: 
1112:         if (isset($this->__map[$type]) && isset($this->__map[$type][$name])) {
1113:             return $this->__map[$type][$name];
1114:         }
1115:         return false;
1116:     }
1117: 
1118: /**
1119:  * Used to overload objects as needed.
1120:  *
1121:  * @param string $type Model or Helper
1122:  * @param string $name Class name to overload
1123:  * @access private
1124:  */
1125:     function __overload($type, $name, $parent) {
1126:         if (($type === 'Model' || $type === 'Helper') && $parent !== false) {
1127:             Overloadable::overload($name);
1128:         }
1129:     }
1130: 
1131: /**
1132:  * Loads parent classes based on $type.
1133:  * Returns a prefix or suffix needed for loading files.
1134:  *
1135:  * @param string $type type of object
1136:  * @param string $plugin camelized name of plugin
1137:  * @param boolean $parent false will not attempt to load parent
1138:  * @return array
1139:  * @access private
1140:  */
1141:     function __settings($type, $plugin, $parent) {
1142:         if (!$parent) {
1143:             return array('class' => null, 'suffix' => null, 'path' => null);
1144:         }
1145: 
1146:         if ($plugin) {
1147:             $pluginPath = Inflector::underscore($plugin);
1148:         }
1149:         $path = null;
1150:         $load = strtolower($type);
1151: 
1152:         switch ($load) {
1153:             case 'model':
1154:                 if (!class_exists('Model')) {
1155:                     require LIBS . 'model' . DS . 'model.php';
1156:                 }
1157:                 if (!class_exists('AppModel')) {
1158:                     App::import($type, 'AppModel', false);
1159:                 }
1160:                 if ($plugin) {
1161:                     if (!class_exists($plugin . 'AppModel')) {
1162:                         App::import($type, $plugin . '.' . $plugin . 'AppModel', false, array(), $pluginPath . DS . $pluginPath . '_app_model.php');
1163:                     }
1164:                     $path = $pluginPath . DS . 'models' . DS;
1165:                 }
1166:                 return array('class' => null, 'suffix' => null, 'path' => $path);
1167:             break;
1168:             case 'behavior':
1169:                 if ($plugin) {
1170:                     $path = $pluginPath . DS . 'models' . DS . 'behaviors' . DS;
1171:                 }
1172:                 return array('class' => $type, 'suffix' => null, 'path' => $path);
1173:             break;
1174:             case 'datasource':
1175:                 if ($plugin) {
1176:                     $path = $pluginPath . DS . 'models' . DS . 'datasources' . DS;
1177:                 }
1178:                 return array('class' => $type, 'suffix' => null, 'path' => $path);
1179:             case 'controller':
1180:                 App::import($type, 'AppController', false);
1181:                 if ($plugin) {
1182:                     App::import($type, $plugin . '.' . $plugin . 'AppController', false, array(), $pluginPath . DS . $pluginPath . '_app_controller.php');
1183:                     $path = $pluginPath . DS . 'controllers' . DS;
1184:                 }
1185:                 return array('class' => $type, 'suffix' => $type, 'path' => $path);
1186:             break;
1187:             case 'component':
1188:                 if ($plugin) {
1189:                     $path = $pluginPath . DS . 'controllers' . DS . 'components' . DS;
1190:                 }
1191:                 return array('class' => $type, 'suffix' => null, 'path' => $path);
1192:             break;
1193:             case 'lib':
1194:                 if ($plugin) {
1195:                     $path = $pluginPath . DS . 'libs' . DS;
1196:                 }
1197:                 return array('class' => null, 'suffix' => null, 'path' => $path);
1198:             break;
1199:             case 'view':
1200:                 if ($plugin) {
1201:                     $path = $pluginPath . DS . 'views' . DS;
1202:                 }
1203:                 return array('class' => $type, 'suffix' => null, 'path' => $path);
1204:             break;
1205:             case 'helper':
1206:                 if (!class_exists('AppHelper')) {
1207:                     App::import($type, 'AppHelper', false);
1208:                 }
1209:                 if ($plugin) {
1210:                     $path = $pluginPath . DS . 'views' . DS . 'helpers' . DS;
1211:                 }
1212:                 return array('class' => $type, 'suffix' => null, 'path' => $path);
1213:             break;
1214:             case 'vendor':
1215:                 if ($plugin) {
1216:                     $path = $pluginPath . DS . 'vendors' . DS;
1217:                 }
1218:                 return array('class' => null, 'suffix' => null, 'path' => $path);
1219:             break;
1220:             default:
1221:                 $type = $suffix = $path = null;
1222:             break;
1223:         }
1224:         return array('class' => null, 'suffix' => null, 'path' => null);
1225:     }
1226: 
1227: /**
1228:  * Returns default search paths.
1229:  *
1230:  * @param string $type type of object to be searched
1231:  * @return array list of paths
1232:  * @access private
1233:  */
1234:     function __paths($type) {
1235:         $type = strtolower($type);
1236:         $paths = array();
1237: 
1238:         if ($type === 'core') {
1239:             return App::core('libs');
1240:         }
1241:         if (isset($this->{$type . 's'})) {
1242:             return $this->{$type . 's'};
1243:         }
1244:         return $paths;
1245:     }
1246: 
1247: /**
1248:  * Removes file location from map if the file has been deleted.
1249:  *
1250:  * @param string $name name of object
1251:  * @param string $type type of object
1252:  * @param string $plugin camelized name of plugin
1253:  * @return void
1254:  * @access private
1255:  */
1256:     function __remove($name, $type, $plugin) {
1257:         if ($plugin) {
1258:             unset($this->__map['Plugin'][$plugin][$type][$name]);
1259:         } else {
1260:             unset($this->__map[$type][$name]);
1261:         }
1262:     }
1263: 
1264: /**
1265:  * Returns an array of filenames of PHP files in the given directory.
1266:  *
1267:  * @param string $path Path to scan for files
1268:  * @param string $suffix if false, return only directories. if string, match and return files
1269:  * @return array  List of directories or files in directory
1270:  * @access private
1271:  */
1272:     function __list($path, $suffix = false, $extension = false) {
1273:         if (!class_exists('Folder')) {
1274:             require LIBS . 'folder.php';
1275:         }
1276:         $items = array();
1277:         $Folder =& new Folder($path);
1278:         $contents = $Folder->read(false, true);
1279: 
1280:         if (is_array($contents)) {
1281:             if (!$suffix) {
1282:                 return $contents[0];
1283:             } else {
1284:                 foreach ($contents[1] as $item) {
1285:                     if (substr($item, - strlen($suffix)) === $suffix) {
1286:                         if ($extension) {
1287:                             $items[] = $item;
1288:                         } else {
1289:                             $items[] = substr($item, 0, strlen($item) - strlen($suffix));
1290:                         }
1291:                     }
1292:                 }
1293:             }
1294:         }
1295:         return $items;
1296:     }
1297:     
1298: /**
1299:  * Determines if $__maps, $__objects and $__paths cache should be reset.
1300:  *
1301:  * @param boolean $reset 
1302:  * @return boolean
1303:  * @access private
1304:  */ 
1305:     function __resetCache($reset = null) {
1306:         static $cache = array();
1307:         if (!$cache && $reset === true) {
1308:             $cache = true;  
1309:         }
1310:         return $cache;
1311:     }
1312: 
1313: /**
1314:  * Object destructor.
1315:  *
1316:  * Writes cache file if changes have been made to the $__map or $__paths
1317:  *
1318:  * @return void
1319:  * @access private
1320:  */
1321:     function __destruct() {
1322:         if ($this->__resetCache() === true) {
1323:             $core = App::core('cake');
1324:             unset($this->__paths[rtrim($core[0], DS)]);
1325:             Cache::write('dir_map', array_filter($this->__paths), '_cake_core_');
1326:             Cache::write('file_map', array_filter($this->__map), '_cake_core_');
1327:             Cache::write('object_map', $this->__objects, '_cake_core_');
1328:         }
1329:     }
1330: }
1331: 
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