CakePHPãèµ·åããã¦ããdispatchããã¾ã§
app/webroot/.htaccess
ãªã¯ã¨ã¹ããããURLãã¯ã¨ãªã«ä»ä¸ãã¦index.phpãå¼ã³åºãå½¢å¼ã«æ¸ãæã
RewriteCond %{REQUEST_FILENAME} !-d # ãã£ã¬ã¯ããªãåå¨ããªãå ´å RewriteCond %{REQUEST_FILENAME} !-f # ãã¡ã¤ã«ãåå¨ããªãå ´å RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] # URLãã¯ã¨ãªã«ä»ä¸ãã¦index.phpãå®è¡
- QSA=ãªã¯ã¨ã¹ããããã¯ã¨ãªæååãä»ä¸ãã
app/webroot/index.php
åºæ¬çãªãã¹çã®å®æ°ãã¤ã³ã¯ã«ã¼ããã¹çã®è¨å®ãè¡ããDispatcher::dispatch()ãã³ã¼ã«ã
ã³ã¢ã®è¨å®ã¯cake/bootstrap.phpãincludeãããã¨ã§è¡ãããã
<?php // ç¥(ã¢ããªå¥ã®åºæ¬çãªãã¹çã®å®æ°å®ç¾©) if (!defined('CORE_PATH')) { // ini_setã使ç¨ã§ããå ´åã¯ãinclude_pathãè¨å®ãã if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) { // ç¸å¯¾ãã¹ã§includeã§ããã®ã§null define('APP_PATH', null); define('CORE_PATH', null); } else { // 絶対ãã¹ã§ãã¡ã¤ã«ãincludeã§ããããã«ãã¹ãå®ç¾© define('APP_PATH', ROOT . DS . APP_DIR . DS); define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); } } // cake/bootstrap.phpãèªã¿è¾¼ããã¨ã§Cakephpã®ã³ã¢ã®è¨å®ãè¡ã if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) { trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); } if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') { return; } else { // dispatchãã $Dispatcher = new Dispatcher(); $Dispatcher->dispatch($url); } if (Configure::read() > 0) { // debugã¬ãã«ã1以ä¸ã®å ´åã«ã¢ããªå®è¡ã«ããã£ãæéã表示ãã echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->"; }
cake/bootstrap.php
ã³ã¢ãã¡ã¤ã«ãèªã¿è¾¼ã¿ãConfigure::getInstance()ãã³ã¼ã«ã
<?php // $bootstrapã¯mod_rewriteã.htaccessã使ããªãå ´åã«ã // cakeãã£ã¬ã¯ããªã¨ä¸¦åã®index.phpã§å®ç¾©ããã if (!isset($bootstrap)) { // a()ãh()ãenv()ãªã©ã®ã°ãã¼ãã«ãªé¢æ°å®ç¾©ã®èªè¾¼ã¿ require CORE_PATH . 'cake' . DS . 'basics.php'; // èµ·åéå§æéãä¿æ $TIME_START = getMicrotime(); // å種ãã¹ã®å®æ°å®ç¾©èªè¾¼ã¿ require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php'; // å種ã¯ã©ã¹ã®èªè¾¼ã¿ require LIBS . 'object.php'; require LIBS . 'inflector.php'; require LIBS . 'configure.php'; } require LIBS . 'cache.php'; Configure::getInstance(); // ã³ã¢ã®è¨å®ãè¡ã $url = null; // index.phpã§Dispatcher::dispatch()ã«æ¸¡ãå¼æ° App::import('Core', array('Dispatcher'));
Configure::getInstance()
getInstance()ã¯ååéããå¯ä¸ã®ã¤ã³ã¹ã¿ã³ã¹ãçæã»ä¿æãã¦è¿ãã¡ã½ããã
__loadBootstrap()ã§app以ä¸ã®bootstrapã®èªè¾¼ã¿ã¨å種è¨å®ãè¡ãã
ãªãé
åã«ã¤ã³ã¹ã¿ã³ã¹ãæ ¼ç´ãã¦ãããã¯ãããã¾ããã
<?php class Configure extends Object { function &getInstance($boot = true) { static $instance = array(); if (!$instance) { $instance[0] =& new Configure(); // å¯ä¸ã®ã¤ã³ã¹ã¿ã³ã¹ $instance[0]->__loadBootstrap($boot); } return $instance[0]; } }
Configure::__loadBootstrap()
bootstrap.phpãcore.phpã®èªè¾¼ã¿ã¨ãã£ãã·ã¥ãã¿ã¤ãå¥ã®ãã¹è¨å®ãè¡ã
<?php class Configure extends Object { function __loadBootstrap($boot) { // ä¸è¨ã®bootstrap.phpèªè¾¼ã¿ã§ä¸æ¸ãã§ããå¤ $modelPaths = $behaviorPaths = $controllerPaths = $componentPaths = $viewPaths = $helperPaths = $pluginPaths = $vendorPaths = $localePaths = $shellPaths = null; if ($boot) { Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR)); // app/config/core.phpèªè¾¼ã¿ // ã»ãã¥ãªãã£ãã»ãã·ã§ã³ããã£ãã·ã¥ãªã©ã®è¨å® if (!include(CONFIGS . 'core.php')) { 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); } // app/config/bootstrap.phpèªè¾¼ã¿ if (!include(CONFIGS . 'bootstrap.php')) { 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); } if (Configure::read('Cache.disable') !== true) { // ç¥ (cacheè¨å®) } // modelãviewãcontrollerãªã©ãã¿ã¤ãå¥ã«ããããã®includeãã£ã¬ã¯ããªãè¨å®ã // app/config/bootstrap.phpã§ãã¦ã¼ã¶ã追å ã§ãããã¹è¨å®ãããã§èªè¾¼ã¿ Configure::buildPaths(compact( 'modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths', 'behaviorPaths', 'pluginPaths', 'vendorPaths', 'localePaths', 'shellPaths' )); } } }