mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
moving some bootstrapped stuff to dispatch and updating tests, added paginator counter to bake index template, added option to do "bake controller Posts admin" for baking just admin methods
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5490 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
a03b688062
commit
43b3b1a0fe
8 changed files with 213 additions and 192 deletions
|
@ -650,7 +650,7 @@
|
||||||
*/
|
*/
|
||||||
function listClasses($path) {
|
function listClasses($path) {
|
||||||
$dir = opendir($path);
|
$dir = opendir($path);
|
||||||
$classes=array();
|
$classes = array();
|
||||||
while (false !== ($file = readdir($dir))) {
|
while (false !== ($file = readdir($dir))) {
|
||||||
if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
|
if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
|
||||||
$classes[] = $file;
|
$classes[] = $file;
|
||||||
|
@ -977,81 +977,20 @@
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the REQUEST_URI from the server environment, or, failing that,
|
* see Dispatcher::uri();
|
||||||
* constructs a new one, using the PHP_SELF constant and other variables.
|
|
||||||
*
|
*
|
||||||
* @return string URI
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
function setUri() {
|
function setUri() {
|
||||||
if (env('HTTP_X_REWRITE_URL')) {
|
return null;
|
||||||
$uri = env('HTTP_X_REWRITE_URL');
|
|
||||||
} elseif (env('REQUEST_URI')) {
|
|
||||||
$uri = env('REQUEST_URI');
|
|
||||||
} else {
|
|
||||||
if ($uri = env('argv')) {
|
|
||||||
if (defined('SERVER_IIS') && SERVER_IIS) {
|
|
||||||
if (key($_GET) && strpos(key($_GET), '?') !== false) {
|
|
||||||
unset($_GET[key($_GET)]);
|
|
||||||
}
|
|
||||||
$uri = preg_split('/\?/', $uri[0], 2);
|
|
||||||
if (isset($uri[1])) {
|
|
||||||
foreach (preg_split('/&/', $uri[1]) as $var) {
|
|
||||||
@list($key, $val) = explode('=', $var);
|
|
||||||
$_GET[$key] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$uri = BASE_URL . $uri[0];
|
|
||||||
} else {
|
|
||||||
$uri = env('PHP_SELF') . '/' . $uri[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$uri = env('PHP_SELF') . '/' . env('QUERY_STRING');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str_replace('//', '/', preg_replace('/\?url=/', '/', $uri));
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns and sets the $_GET[url] derived from the REQUEST_INFO
|
* see Dispatcher::getUrl();
|
||||||
*
|
*
|
||||||
* @param string $uri
|
* @deprecated
|
||||||
* @return string URL
|
|
||||||
*/
|
*/
|
||||||
function setUrl($uri = null, $script = null) {
|
function setUrl() {
|
||||||
if ($uri == null) {
|
return null;
|
||||||
$uri = setUri();
|
|
||||||
}
|
|
||||||
if ($script == null) {
|
|
||||||
if (defined('BASE_URL')) {
|
|
||||||
$script = BASE_URL;
|
|
||||||
} else {
|
|
||||||
$script = env('SCRIPT_NAME');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$url = null;
|
|
||||||
if ($uri === '/' || $uri === $script || $uri === '/'.APP_DIR.'/') {
|
|
||||||
$url = $_GET['url'] = '/';
|
|
||||||
} else {
|
|
||||||
if (strpos($uri, $script) !== false) {
|
|
||||||
$elements = explode($script, $uri);
|
|
||||||
} elseif (strpos($uri, APP_DIR) !== false) {
|
|
||||||
$elements = explode(APP_DIR, $uri);
|
|
||||||
} elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) {
|
|
||||||
$elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri));
|
|
||||||
} else {
|
|
||||||
$elements = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($elements[1])) {
|
|
||||||
$_GET['url'] = $elements[1];
|
|
||||||
$url = $elements[1];
|
|
||||||
} else {
|
|
||||||
$url = $_GET['url'] = '/';
|
|
||||||
}
|
|
||||||
if (strpos($url, '/') === 0 && $url != '/') {
|
|
||||||
$url = $_GET['url'] = substr($url, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $url;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Gets an environment variable from available sources, and provides emulation
|
* Gets an environment variable from available sources, and provides emulation
|
||||||
|
@ -1577,13 +1516,12 @@
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* chmod recursively on a directory
|
* See Folder::chmod
|
||||||
*
|
*
|
||||||
* @param string $path Path to chmod
|
* @deprecated
|
||||||
* @param int $mode Mode to apply
|
|
||||||
* @return boolean Success
|
|
||||||
*/
|
*/
|
||||||
function chmodr($path, $mode = 0755) {
|
function chmodr($path, $mode = 0755) {
|
||||||
|
trigger_error("Deprecated. See Folder::chmod()", E_USER_ERROR);
|
||||||
if (!is_dir($path)) {
|
if (!is_dir($path)) {
|
||||||
return chmod($path, $mode);
|
return chmod($path, $mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,17 +34,16 @@ if (!defined('PHP5')) {
|
||||||
*/
|
*/
|
||||||
if (!isset($bootstrap)) {
|
if (!isset($bootstrap)) {
|
||||||
require CORE_PATH . 'cake' . DS . 'basics.php';
|
require CORE_PATH . 'cake' . DS . 'basics.php';
|
||||||
|
$TIME_START = getMicrotime();
|
||||||
require APP_PATH . 'config' . DS . 'core.php';
|
require APP_PATH . 'config' . DS . 'core.php';
|
||||||
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
|
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
|
||||||
require LIBS . 'object.php';
|
require LIBS . 'object.php';
|
||||||
require LIBS . 'configure.php';
|
require LIBS . 'configure.php';
|
||||||
}
|
}
|
||||||
$TIME_START = getMicrotime();
|
|
||||||
require LIBS . 'cache.php';
|
require LIBS . 'cache.php';
|
||||||
require LIBS . 'session.php';
|
require LIBS . 'session.php';
|
||||||
require LIBS . 'security.php';
|
require LIBS . 'security.php';
|
||||||
require LIBS . 'inflector.php';
|
require LIBS . 'inflector.php';
|
||||||
$paths = Configure::getInstance();
|
|
||||||
|
|
||||||
if (isset($cakeCache)) {
|
if (isset($cakeCache)) {
|
||||||
$cache = 'File';
|
$cache = 'File';
|
||||||
|
@ -60,6 +59,7 @@ if (!defined('PHP5')) {
|
||||||
} else {
|
} else {
|
||||||
Cache::engine();
|
Cache::engine();
|
||||||
}
|
}
|
||||||
|
|
||||||
Configure::store(null, 'class.paths');
|
Configure::store(null, 'class.paths');
|
||||||
Configure::load('class.paths');
|
Configure::load('class.paths');
|
||||||
Configure::write('debug', DEBUG);
|
Configure::write('debug', DEBUG);
|
||||||
|
@ -69,53 +69,7 @@ if (!defined('PHP5')) {
|
||||||
if (!defined('SERVER_IIS') && php_sapi_name() == 'isapi') {
|
if (!defined('SERVER_IIS') && php_sapi_name() == 'isapi') {
|
||||||
define('SERVER_IIS', true);
|
define('SERVER_IIS', true);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Get the application path and request URL
|
|
||||||
*/
|
|
||||||
if (empty($uri) && defined('BASE_URL')) {
|
|
||||||
$url = setUrl();
|
|
||||||
} else {
|
|
||||||
if (empty($_GET['url'])) {
|
|
||||||
$url = null;
|
$url = null;
|
||||||
} else {
|
|
||||||
$url = $_GET['url'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($url, 'ccss/') === 0) {
|
|
||||||
include WWW_ROOT . DS . 'css.php';
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$folders = array('js' => 'text/javascript', 'css' => 'text/css');
|
|
||||||
$requestPath = explode('/', $url);
|
|
||||||
|
|
||||||
if (in_array($requestPath[0], array_keys($folders))) {
|
|
||||||
if (file_exists(VENDORS . join(DS, $requestPath))) {
|
|
||||||
header('Content-type: ' . $folders[$requestPath[0]]);
|
|
||||||
include (VENDORS . join(DS, $requestPath));
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
require CAKE . 'dispatcher.php';
|
require CAKE . 'dispatcher.php';
|
||||||
|
|
||||||
if (defined('CACHE_CHECK') && CACHE_CHECK === true) {
|
|
||||||
if (empty($uri)) {
|
|
||||||
$uri = setUri();
|
|
||||||
}
|
|
||||||
$filename = CACHE . 'views' . DS . convertSlash($uri) . '.php';
|
|
||||||
|
|
||||||
if (file_exists($filename)) {
|
|
||||||
uses('controller' . DS . 'component', DS . 'view' . DS . 'view');
|
|
||||||
$v = null;
|
|
||||||
$view = new View($v);
|
|
||||||
$view->renderCache($filename, $TIME_START);
|
|
||||||
} elseif (file_exists(CACHE . 'views' . DS . convertSlash($uri) . '_index.php')) {
|
|
||||||
uses('controller' . DS . 'component', DS . 'view' . DS . 'view');
|
|
||||||
$v = null;
|
|
||||||
$view = new View($v);
|
|
||||||
$view->renderCache(CACHE . 'views' . DS . convertSlash($uri) . '_index.php', $TIME_START);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
|
@ -64,7 +64,7 @@ class ControllerTask extends Shell {
|
||||||
} else {
|
} else {
|
||||||
$actions = 'scaffold';
|
$actions = 'scaffold';
|
||||||
}
|
}
|
||||||
if (isset($this->args[2]) && $this->args[2] == 'admin') {
|
if ((isset($this->args[1]) && $this->args[1] == 'admin') || (isset($this->args[2]) && $this->args[2] == 'admin')) {
|
||||||
if ($admin = $this->getAdmin()) {
|
if ($admin = $this->getAdmin()) {
|
||||||
$this->out('Adding ' . CAKE_ADMIN .' methods');
|
$this->out('Adding ' . CAKE_ADMIN .' methods');
|
||||||
if ($actions == 'scaffold') {
|
if ($actions == 'scaffold') {
|
||||||
|
|
|
@ -26,6 +26,13 @@
|
||||||
?>
|
?>
|
||||||
<div class="<?php echo $pluralVar;?>">
|
<div class="<?php echo $pluralVar;?>">
|
||||||
<h2><?php echo "<?php __('{$pluralHumanName}');?>";?></h2>
|
<h2><?php echo "<?php __('{$pluralHumanName}');?>";?></h2>
|
||||||
|
<p>
|
||||||
|
<?php echo "<?php
|
||||||
|
echo $paginator->counter(array(
|
||||||
|
'format' => 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%'
|
||||||
|
));
|
||||||
|
?>";?>
|
||||||
|
</p>
|
||||||
<table cellpadding="0" cellspacing="0">
|
<table cellpadding="0" cellspacing="0">
|
||||||
<tr>
|
<tr>
|
||||||
<?php foreach ($fields as $field):?>
|
<?php foreach ($fields as $field):?>
|
||||||
|
|
|
@ -47,6 +47,13 @@ class Dispatcher extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $base = false;
|
var $base = false;
|
||||||
|
/**
|
||||||
|
* webroot path
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $webroot = '/';
|
||||||
/**
|
/**
|
||||||
* Current URL
|
* Current URL
|
||||||
*
|
*
|
||||||
|
@ -88,13 +95,10 @@ class Dispatcher extends Object {
|
||||||
*/
|
*/
|
||||||
function __construct($url = null, $base = false) {
|
function __construct($url = null, $base = false) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if($base !== false) {
|
if($base !== false) {
|
||||||
Configure::write('App.base', $base);
|
Configure::write('App.base', $base);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->base = Configure::read('App.base');
|
$this->base = Configure::read('App.base');
|
||||||
|
|
||||||
if ($url !== null) {
|
if ($url !== null) {
|
||||||
return $this->dispatch($url);
|
return $this->dispatch($url);
|
||||||
}
|
}
|
||||||
|
@ -112,13 +116,22 @@ class Dispatcher extends Object {
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function dispatch($url, $additionalParams = array()) {
|
function dispatch($url = null, $additionalParams = array()) {
|
||||||
$this->params = array_merge($this->parseParams($url), $additionalParams);
|
if ($this->base === false) {
|
||||||
$missingAction = $missingView = $privateAction = false;
|
|
||||||
|
|
||||||
$this->base = $this->baseUrl();
|
$this->base = $this->baseUrl();
|
||||||
$controller = $this->__getController();
|
}
|
||||||
|
if ($url !== null) {
|
||||||
|
$_GET['url'] = $url;
|
||||||
|
}
|
||||||
|
$url = $this->getUrl();
|
||||||
|
|
||||||
|
$this->here = $this->base . '/' . $url;
|
||||||
|
|
||||||
|
$this->cached();
|
||||||
|
|
||||||
|
$this->params = array_merge($this->parseParams($url), $additionalParams);
|
||||||
|
|
||||||
|
$controller = $this->__getController();
|
||||||
if(!is_object($controller)) {
|
if(!is_object($controller)) {
|
||||||
if (preg_match('/([\\.]+)/', $controller)) {
|
if (preg_match('/([\\.]+)/', $controller)) {
|
||||||
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
|
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
|
||||||
|
@ -139,23 +152,21 @@ class Dispatcher extends Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$missingAction = $missingView = $privateAction = false;
|
||||||
|
|
||||||
if (empty($this->params['action'])) {
|
if (empty($this->params['action'])) {
|
||||||
$this->params['action'] = 'index';
|
$this->params['action'] = 'index';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined('CAKE_ADMIN')) {
|
if (defined('CAKE_ADMIN')) {
|
||||||
if (isset($this->params[CAKE_ADMIN])) {
|
$this->admin = CAKE_ADMIN ;
|
||||||
$this->admin = '/'.CAKE_ADMIN ;
|
if (isset($this->params[$this->admin])) {
|
||||||
$url = preg_replace('/'.CAKE_ADMIN.'(\/|$)/', '', $url);
|
$this->params['action'] = $this->admin.'_'.$this->params['action'];
|
||||||
$this->params['action'] = CAKE_ADMIN.'_'.$this->params['action'];
|
} elseif (strpos($this->params['action'], $this->admin) === 0) {
|
||||||
} elseif (strpos($this->params['action'], CAKE_ADMIN) === 0) {
|
|
||||||
$privateAction = true;
|
$privateAction = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->here = $this->base . $this->admin . '/' . $url;
|
|
||||||
|
|
||||||
|
|
||||||
$protected = array('constructclasses', 'redirect', 'set', 'setAction', 'isauthorized', 'validate', 'validateerrors',
|
$protected = array('constructclasses', 'redirect', 'set', 'setAction', 'isauthorized', 'validate', 'validateerrors',
|
||||||
'render', 'referer', 'disablecache', 'flash', 'generatefieldnames', 'postconditions', 'cleanupfields',
|
'render', 'referer', 'disablecache', 'flash', 'generatefieldnames', 'postconditions', 'cleanupfields',
|
||||||
'paginate', 'beforefilter', 'beforerender', 'afterfilter', 'object', 'tostring', 'requestaction', 'log',
|
'paginate', 'beforefilter', 'beforerender', 'afterfilter', 'object', 'tostring', 'requestaction', 'log',
|
||||||
|
@ -402,9 +413,10 @@ class Dispatcher extends Object {
|
||||||
$base = '';
|
$base = '';
|
||||||
$this->webroot = '/';
|
$this->webroot = '/';
|
||||||
|
|
||||||
$baseUrl = Configure::read('App.baseUrl');
|
$config = Configure::read('App');
|
||||||
$app = Configure::read('App.dir');
|
$baseUrl = $config['baseUrl'];
|
||||||
$webroot = Configure::read('App.webroot');
|
$app = $config['dir'];
|
||||||
|
$webroot = $config['webroot'];
|
||||||
|
|
||||||
$file = $script = null;
|
$file = $script = null;
|
||||||
if (!$baseUrl) {
|
if (!$baseUrl) {
|
||||||
|
@ -417,18 +429,13 @@ class Dispatcher extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
$base = dirname($base);
|
$base = dirname($base);
|
||||||
|
|
||||||
if (in_array($base, array(DS, '.'))) {
|
if (in_array($base, array(DS, '.'))) {
|
||||||
$base = '';
|
$base = '';
|
||||||
$this->webroot = '/';
|
|
||||||
return $base . $file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strpos($script, $app) !== false && $app === 'app') {
|
if(strpos($script, $app) !== false && $app === 'app') {
|
||||||
$base = str_replace('/'.$app, '', $base);
|
$base = str_replace('/'.$app, '', $base);
|
||||||
}
|
}
|
||||||
|
if (!$baseUrl && $webroot === 'webroot') {
|
||||||
if ($webroot === 'webroot') {
|
|
||||||
$base = str_replace('/'.$webroot, '', $base);
|
$base = str_replace('/'.$webroot, '', $base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,7 +448,6 @@ class Dispatcher extends Object {
|
||||||
if (strpos($this->webroot, $app) === false) {
|
if (strpos($this->webroot, $app) === false) {
|
||||||
$this->webroot .= $app . '/' ;
|
$this->webroot .= $app . '/' ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($this->webroot, $webroot) === false) {
|
if (strpos($this->webroot, $webroot) === false) {
|
||||||
$this->webroot .= $webroot . '/';
|
$this->webroot .= $webroot . '/';
|
||||||
}
|
}
|
||||||
|
@ -507,7 +513,7 @@ class Dispatcher extends Object {
|
||||||
return $controller;
|
return $controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!class_exists(low($ctrlClass))) {
|
if (!class_exists(low($ctrlClass))) {
|
||||||
$controller = Inflector::camelize($this->params['controller']);
|
$controller = Inflector::camelize($this->params['controller']);
|
||||||
$this->plugin = null;
|
$this->plugin = null;
|
||||||
return $controller;
|
return $controller;
|
||||||
|
@ -516,6 +522,121 @@ class Dispatcher extends Object {
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
return $controller;
|
return $controller;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns the REQUEST_URI from the server environment, or, failing that,
|
||||||
|
* constructs a new one, using the PHP_SELF constant and other variables.
|
||||||
|
*
|
||||||
|
* @return string URI
|
||||||
|
*/
|
||||||
|
function uri() {
|
||||||
|
if ($uri = env('HTTP_X_REWRITE_URL')) {
|
||||||
|
} elseif ($uri = env('REQUEST_URI')) {
|
||||||
|
} else {
|
||||||
|
if ($uri = env('argv')) {
|
||||||
|
if (defined('SERVER_IIS') && SERVER_IIS) {
|
||||||
|
if (key($_GET) && strpos(key($_GET), '?') !== false) {
|
||||||
|
unset($_GET[key($_GET)]);
|
||||||
|
}
|
||||||
|
$uri = preg_split('/\?/', $uri[0], 2);
|
||||||
|
if (isset($uri[1])) {
|
||||||
|
foreach (preg_split('/&/', $uri[1]) as $var) {
|
||||||
|
@list($key, $val) = explode('=', $var);
|
||||||
|
$_GET[$key] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$uri = $this->base . $uri[0];
|
||||||
|
} else {
|
||||||
|
$uri = env('PHP_SELF') . '/' . $uri[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$uri = env('PHP_SELF') . '/' . env('QUERY_STRING');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str_replace('//', '/', preg_replace('/\?url=/', '/', $uri));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns and sets the $_GET[url] derived from the REQUEST_URI
|
||||||
|
*
|
||||||
|
* @param string $uri
|
||||||
|
* @param string $script
|
||||||
|
* @return string URL
|
||||||
|
*/
|
||||||
|
function getUrl($uri = null, $base = null) {
|
||||||
|
if (empty($_GET['url'])) {
|
||||||
|
if ($uri == null) {
|
||||||
|
$uri = $this->uri();
|
||||||
|
}
|
||||||
|
if ($base == null) {
|
||||||
|
$base = $this->base;
|
||||||
|
}
|
||||||
|
$url = null;
|
||||||
|
if ($uri === '/' || $uri == dirname($base).'/' || $url == $base) {
|
||||||
|
$url = $_GET['url'] = '/';
|
||||||
|
} else {
|
||||||
|
if (strpos($uri, $base) !== false) {
|
||||||
|
$elements = explode($base, $uri);
|
||||||
|
} elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) {
|
||||||
|
$elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri));
|
||||||
|
} else {
|
||||||
|
$elements = array();
|
||||||
|
}
|
||||||
|
if (!empty($elements[1])) {
|
||||||
|
$_GET['url'] = $elements[1];
|
||||||
|
$url = $elements[1];
|
||||||
|
} else {
|
||||||
|
$url = $_GET['url'] = '/';
|
||||||
|
}
|
||||||
|
if (strpos($url, '/') === 0 && $url != '/') {
|
||||||
|
$url = $_GET['url'] = substr($url, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$url = $_GET['url'];
|
||||||
|
}
|
||||||
|
if($url{0} == '/') {
|
||||||
|
$url = substr($url, 1);
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Outputs cached dispatch for js, css, view cache
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @return string URL
|
||||||
|
*/
|
||||||
|
function cached($uri = null) {
|
||||||
|
if($uri == null) {
|
||||||
|
$uri = $this->here;
|
||||||
|
}
|
||||||
|
if (strpos($uri, 'ccss/') === 0) {
|
||||||
|
include WWW_ROOT . DS . 'css.php';
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$folders = array('js' => 'text/javascript', 'css' => 'text/css');
|
||||||
|
$requestPath = explode('/', $uri);
|
||||||
|
|
||||||
|
if (in_array($requestPath[0], array_keys($folders))) {
|
||||||
|
if (file_exists(VENDORS . join(DS, $requestPath))) {
|
||||||
|
header('Content-type: ' . $folders[$requestPath[0]]);
|
||||||
|
include (VENDORS . join(DS, $requestPath));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined('CACHE_CHECK') && CACHE_CHECK === true) {
|
||||||
|
$filename = CACHE . 'views' . DS . convertSlash($uri) . '.php';
|
||||||
|
if (!file_exists($filename)) {
|
||||||
|
$filename = CACHE . 'views' . DS . convertSlash($uri) . '_index.php';
|
||||||
|
}
|
||||||
|
if (file_exists($filename)) {
|
||||||
|
uses('controller' . DS . 'component', DS . 'view' . DS . 'view');
|
||||||
|
$v = null;
|
||||||
|
$view = new View($v);
|
||||||
|
$view->renderCache($filename, getMicrotime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -24,7 +24,11 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<?php Debugger::checkSessionKey(); ?>
|
<?php
|
||||||
|
if(Configure::read() > 0):
|
||||||
|
Debugger::checkSessionKey();
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
<p>
|
<p>
|
||||||
<span class="notice">
|
<span class="notice">
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -195,24 +195,28 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
|
$this->assertPattern('/\\A(?:0000400)\\z/', $test['pass'][5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSetUrl() {
|
function testGetUrl() {
|
||||||
|
$dispatcher =& new Dispatcher();
|
||||||
|
$dispatcher->base = '/app/webroot/index.php';
|
||||||
$uri = '/app/webroot/index.php/posts/add';
|
$uri = '/app/webroot/index.php/posts/add';
|
||||||
$_SERVER['SCRIPT_NAME'] = '/app/webroot/index.php';
|
$result = $dispatcher->getUrl($uri);
|
||||||
$result = setUrl($uri);
|
|
||||||
$expected = 'posts/add';
|
$expected = 'posts/add';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
$uri = APP_DIR . '/posts/add';
|
Configure::write('App.baseUrl', '/app/webroot/index.php');
|
||||||
$_SERVER['SCRIPT_NAME'] = APP_DIR . '/webroot/index.php';
|
|
||||||
$result = setUrl($uri);
|
|
||||||
$expected = 'posts/add';
|
|
||||||
$this->assertEqual($expected, $result);
|
|
||||||
|
|
||||||
$uri = '/posts/add';
|
$uri = '/posts/add';
|
||||||
$_SERVER['SCRIPT_NAME'] = '/app/webroot/index.php';
|
$result = $dispatcher->getUrl($uri);
|
||||||
$result = setUrl($uri);
|
|
||||||
$expected = 'posts/add';
|
$expected = 'posts/add';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
|
|
||||||
|
$_GET['url'] = array();
|
||||||
|
Configure::write('App.base', '/control');
|
||||||
|
$dispatcher =& new Dispatcher();
|
||||||
|
$uri = '/control/students/browse';
|
||||||
|
$result = $dispatcher->getUrl($uri);
|
||||||
|
$expected = 'students/browse';
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testBaseUrlAndWebrootWithModRewrite() {
|
function testBaseUrlAndWebrootWithModRewrite() {
|
||||||
|
@ -299,14 +303,14 @@ class DispatcherTest extends UnitTestCase {
|
||||||
|
|
||||||
Configure::write('App.baseUrl', '/app/webroot/index.php');
|
Configure::write('App.baseUrl', '/app/webroot/index.php');
|
||||||
$result = $dispatcher->baseUrl();
|
$result = $dispatcher->baseUrl();
|
||||||
$expected = '/app/index.php';
|
$expected = '/app/webroot/index.php';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$expectedWebroot = '/app/webroot/';
|
$expectedWebroot = '/app/webroot/';
|
||||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||||
|
|
||||||
Configure::write('App.baseUrl', '/app/webroot/test.php');
|
Configure::write('App.baseUrl', '/app/webroot/test.php');
|
||||||
$result = $dispatcher->baseUrl();
|
$result = $dispatcher->baseUrl();
|
||||||
$expected = '/app/test.php';
|
$expected = '/app/webroot/test.php';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$expectedWebroot = '/app/webroot/';
|
$expectedWebroot = '/app/webroot/';
|
||||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||||
|
@ -322,12 +326,12 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$result = $dispatcher->baseUrl();
|
$result = $dispatcher->baseUrl();
|
||||||
$expected = '/index.php';
|
$expected = '/index.php';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$expectedWebroot = '/';
|
$expectedWebroot = '/app/webroot/';
|
||||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||||
|
|
||||||
Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
|
Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
|
||||||
$result = $dispatcher->baseUrl();
|
$result = $dispatcher->baseUrl();
|
||||||
$expected = '/CakeBB/app/index.php';
|
$expected = '/CakeBB/app/webroot/index.php';
|
||||||
$this->assertEqual($expected, $result);
|
$this->assertEqual($expected, $result);
|
||||||
$expectedWebroot = '/CakeBB/app/webroot/';
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
||||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||||
|
@ -339,7 +343,6 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$expectedWebroot = '/CakeBB/app/webroot/';
|
$expectedWebroot = '/CakeBB/app/webroot/';
|
||||||
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
$this->assertEqual($expectedWebroot, $dispatcher->webroot);
|
||||||
|
|
||||||
|
|
||||||
Configure::write('App.baseUrl', '/CakeBB/index.php');
|
Configure::write('App.baseUrl', '/CakeBB/index.php');
|
||||||
$result = $dispatcher->baseUrl();
|
$result = $dispatcher->baseUrl();
|
||||||
$expected = '/CakeBB/index.php';
|
$expected = '/CakeBB/index.php';
|
||||||
|
@ -377,9 +380,8 @@ class DispatcherTest extends UnitTestCase {
|
||||||
|
|
||||||
function testMissingController() {
|
function testMissingController() {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = '/index.php';
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = setUrl('/some_controller/home/param:value/param2:value2');
|
$url = 'some_controller/home/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
set_error_handler('simpleTestErrorHandler');
|
set_error_handler('simpleTestErrorHandler');
|
||||||
|
@ -390,8 +392,8 @@ class DispatcherTest extends UnitTestCase {
|
||||||
|
|
||||||
function testPrivate() {
|
function testPrivate() {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = '/index.php';
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = setUrl('/some_pages/redirect/param:value/param2:value2');
|
$url = 'some_pages/redirect/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
|
@ -403,8 +405,8 @@ class DispatcherTest extends UnitTestCase {
|
||||||
|
|
||||||
function testMissingAction() {
|
function testMissingAction() {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = '/index.php';
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = setUrl('/some_pages/home/param:value/param2:value2');
|
$url = 'some_pages/home/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
|
@ -415,8 +417,8 @@ class DispatcherTest extends UnitTestCase {
|
||||||
|
|
||||||
function testDispatch() {
|
function testDispatch() {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = '/index.php';
|
Configure::write('App.baseUrl','/index.php');
|
||||||
$url = setUrl('/pages/home/param:value/param2:value2');
|
$url = 'pages/home/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
|
@ -431,17 +433,12 @@ class DispatcherTest extends UnitTestCase {
|
||||||
|
|
||||||
function testAdminDispatch() {
|
function testAdminDispatch() {
|
||||||
$_POST = array();
|
$_POST = array();
|
||||||
|
|
||||||
if (!defined('CAKE_ADMIN')) {
|
if (!defined('CAKE_ADMIN')) {
|
||||||
define('CAKE_ADMIN', 'admin');
|
define('CAKE_ADMIN', 'admin');
|
||||||
}
|
}
|
||||||
$_SERVER['DOCUMENT_ROOT'] = '';
|
|
||||||
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
|
|
||||||
|
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = false;
|
Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
|
||||||
$url = setUrl('/admin/test_dispatch_pages/index/param:value/param2:value2');
|
$url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
|
||||||
|
|
||||||
Router::reload();
|
Router::reload();
|
||||||
$Router =& Router::getInstance();
|
$Router =& Router::getInstance();
|
||||||
if (defined('CAKE_ADMIN')) {
|
if (defined('CAKE_ADMIN')) {
|
||||||
|
@ -468,10 +465,10 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$expected = 'admin';
|
$expected = 'admin';
|
||||||
$this->assertIdentical($expected, $controller->params['admin']);
|
$this->assertIdentical($expected, $controller->params['admin']);
|
||||||
|
|
||||||
$expected = '/cake/repo/branches/1.2.x.x/admin/test_dispatch_pages/index/param:value/param2:value2';
|
$expected = '/cake/repo/branches/1.2.x.x/index.php/admin/test_dispatch_pages/index/param:value/param2:value2';
|
||||||
$this->assertIdentical($expected, $controller->here);
|
$this->assertIdentical($expected, $controller->here);
|
||||||
|
|
||||||
$expected = '/cake/repo/branches/1.2.x.x';
|
$expected = '/cake/repo/branches/1.2.x.x/index.php';
|
||||||
$this->assertIdentical($expected, $controller->base);
|
$this->assertIdentical($expected, $controller->base);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -486,7 +483,7 @@ class DispatcherTest extends UnitTestCase {
|
||||||
Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
|
Router::connect('/my_plugin/:controller/*', array('plugin'=>'my_plugin', 'controller'=>'pages', 'action'=>'display'));
|
||||||
|
|
||||||
$dispatcher->base = false;
|
$dispatcher->base = false;
|
||||||
$url = setUrl('/my_plugin/some_pages/home/param:value/param2:value2');
|
$url = 'my_plugin/some_pages/home/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
|
@ -530,7 +527,7 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = false;
|
$dispatcher->base = false;
|
||||||
|
|
||||||
$url = setUrl('/my_plugin/other_pages/index/param:value/param2:value2');
|
$url = 'my_plugin/other_pages/index/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
|
@ -564,7 +561,7 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = false;
|
$dispatcher->base = false;
|
||||||
|
|
||||||
$url = setUrl('/my_plugin/add/param:value/param2:value2');
|
$url = 'my_plugin/add/param:value/param2:value2';
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
|
@ -589,7 +586,7 @@ class DispatcherTest extends UnitTestCase {
|
||||||
$dispatcher =& new TestDispatcher();
|
$dispatcher =& new TestDispatcher();
|
||||||
$dispatcher->base = false;
|
$dispatcher->base = false;
|
||||||
|
|
||||||
$url = setUrl('/my_plugin/param:value/param2:value2');
|
$url = 'my_plugin/param:value/param2:value2';
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||||
set_error_handler('simpleTestErrorHandler');
|
set_error_handler('simpleTestErrorHandler');
|
||||||
|
|
|
@ -52,13 +52,13 @@
|
||||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||||
}
|
}
|
||||||
require CORE_PATH . 'cake' . DS . 'basics.php';
|
require CORE_PATH . 'cake' . DS . 'basics.php';
|
||||||
|
$TIME_START = getMicrotime();
|
||||||
require APP_PATH . 'config' . DS . 'core.php';
|
require APP_PATH . 'config' . DS . 'core.php';
|
||||||
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
|
require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
|
||||||
require LIBS . 'object.php';
|
require LIBS . 'object.php';
|
||||||
require LIBS . 'configure.php';
|
require LIBS . 'configure.php';
|
||||||
|
|
||||||
$bootstrap = true;
|
$bootstrap = true;
|
||||||
$url = setUrl();
|
$url = null;
|
||||||
|
|
||||||
require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
|
require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue