updating dispatcher, fixes #3773, fixes #3783, fixes #3779, updating default layouts, adding Debugger::dump($var); and some other changes for exporting string vars

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6272 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-12-29 19:05:22 +00:00
parent d38bb91d1c
commit 99da081907
8 changed files with 75 additions and 49 deletions

View file

@ -16,7 +16,7 @@
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.templates.pages
* @subpackage cake.cake.console.libs.templates.skel.views.layouts
* @since CakePHP(tm) v 0.10.0.1076
* @version $Revision$
* @modifiedby $LastChangedBy$
@ -31,13 +31,14 @@
<?php __('CakePHP: the rapid development php framework:'); ?>
<?php echo $title_for_layout;?>
</title>
<?php
echo $html->charset();
echo $html->meta('icon');
<?php echo $html->charset();?>
echo $html->css('cake.generic');
<link rel="icon" href="<?php echo $this->webroot;?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->webroot;?>favicon.ico" type="image/x-icon" />
<?php echo $html->css('cake.generic');?>
<?php echo $scripts_for_layout;?>
echo $scripts_for_layout;
?>
</head>
<body>
<div id="container">

View file

@ -125,7 +125,7 @@ class Dispatcher extends Object {
$url = $this->getUrl();
$this->here = $this->base . '/' . $url;
if ($this->cached($url) && Configure::read() < 1) {
if ($this->cached($url)) {
exit();
}
@ -163,11 +163,11 @@ class Dispatcher extends Object {
$protected = array_map('strtolower', get_class_methods('controller'));
$classMethods = array_map('strtolower', get_class_methods($controller));
if (in_array(low($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
if (in_array(strtolower($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
$privateAction = true;
}
if (!in_array(low($this->params['action']), $classMethods)) {
if (!in_array(strtolower($this->params['action']), $classMethods)) {
$missingAction = true;
}
@ -329,9 +329,8 @@ class Dispatcher extends Object {
* @access public
*/
function parseParams($fromUrl) {
$Route = Router::getInstance();
extract(Router::getNamedExpressions());
include CONFIGS.'routes.php';
include CONFIGS . 'routes.php';
$params = Router::parse($fromUrl);
if (isset($_POST)) {
@ -500,11 +499,8 @@ class Dispatcher extends Object {
$ctrlClass = $ctrlClass . 'Controller';
if (class_exists($ctrlClass)) {
if (low(get_parent_class($ctrlClass)) === low($name . 'AppController')) {
$count = count(explode('/', $params['url']['url']));
if ((isset($params['admin']) && $params['action'] === 'index') || (!empty($params['pass']) || $count > 2) || ($params['action'] !== 'index')) {
$params = $this->_restructureParams($params);
}
if (strtolower(get_parent_class($ctrlClass)) === strtolower($name . 'AppController') && empty($params['plugin'])) {
$params = $this->_restructureParams($params);
$params = $this->_restructureParams($params, true);
}
$this->params = $params;
@ -634,7 +630,8 @@ class Dispatcher extends Object {
$assets = array('js' => 'text/javascript', 'css' => 'text/css');
$isAsset = false;
foreach ($assets as $type => $contentType) {
if (strpos($url, $type . '/') !== false) {
$pos = strpos($url, $type . '/');
if ($pos !== false) {
$isAsset = true;
break;
}
@ -650,18 +647,17 @@ class Dispatcher extends Object {
$assetFile = null;
$paths = array();
$vendorPaths = Configure::read('vendorPaths');
if ($this->plugin !== null) {
$url = str_replace($this->plugin . '/', '', $url);
if ($pos > 0) {
$plugin = substr($url, 0, $pos - 1);
$url = str_replace($plugin . '/', '', $url);
$pluginPaths = Configure::read('pluginPaths');
$count = count($pluginPaths);
for ($i = 0; $i < $count; $i++) {
$paths[] = $pluginPaths[$i] . $this->plugin . DS . 'vendors' . DS;
$paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS;
}
}
$paths = array_merge($paths, $vendorPaths);
$paths = array_merge($paths, Configure::read('vendorPaths'));
foreach ($paths as $path) {
if (is_file($path . $url) && file_exists($path . $url)) {
@ -694,15 +690,14 @@ class Dispatcher extends Object {
}
if (file_exists($filename)) {
if (!class_exists('View')) {
App::import('Core', 'Component');
App::import('Core', 'View');;
App::import('Core', 'View');
}
$controller = null;
$view = new View($controller);
$view->renderCache($filename, getMicrotime());
return true;
return $view->renderCache($filename, getMicrotime());
}
}
return false;
}
}
?>

View file

@ -105,6 +105,13 @@ class Debugger extends Object {
}
return $instance[0];
}
/**
* formats and outputs the passed var
*/
function dump($var) {
$_this = Debugger::getInstance();
pr($_this->exportVar($var));
}
/**
* Overrides PHP's default error handling
*
@ -325,8 +332,10 @@ class Debugger extends Object {
return $var;
break;
case 'string':
if (trim($var) == "") {
return '"[empty string]"';
}
return '"' . h($var) . '"';
return $echo;
break;
case 'object':
return get_class($var) . "\n" . $_this->__object($var);
@ -370,7 +379,6 @@ class Debugger extends Object {
$objectVars = get_object_vars($var);
foreach($objectVars as $key => $value) {
$value = ife((!is_object($value) && !is_array($value) && trim($value) == ""), "[empty string]", $value);
$inline = null;
if(strpos($key, '_', 0) !== 0) {
$inline = "$className::$key = ";
@ -386,7 +394,7 @@ class Debugger extends Object {
if(in_array(gettype($value), array('boolean', 'integer', 'double', 'string', 'array', 'resource', 'object', 'null'))) {
$out[] = "$className::$$key = " . Debugger::exportVar($value);
} else {
$out[] = $value;
$out[] = "$className::$$key = " . var_export($value, true);
}
}

View file

@ -201,7 +201,7 @@ class Helper extends Overloadable {
$webPath = "{$this->webroot}" . $this->themeWeb . $file;
}
}
return $webPath;
return str_replace('//', '/', $webPath);
}
/**

View file

@ -343,7 +343,15 @@ class HtmlHelper extends AppHelper {
$path .= '.css';
}
$url = $this->webroot((COMPRESS_CSS ? 'c' : '') . CSS_URL . $path);
if ($path{0} !== '/') {
$path = CSS_URL . $path;
}
if (COMPRESS_CSS) {
$path = str_replace('css/', 'ccss/', $path);
}
$url = $this->webroot($path);
if ($rel == 'import') {
$out = sprintf($this->tags['style'], $this->_parseAttributes($htmlAttributes, null, '', ' '), '@import url(' . $url . ');');
} else {
@ -414,11 +422,16 @@ class HtmlHelper extends AppHelper {
* @return string
*/
function image($path, $htmlAttributes = array()) {
if (is_array($path) || strpos($path, '/') === 0 || strpos($path, '://')) {
if (is_array($path)) {
$url = Router::url($path);
} elseif ($path{0} === '/') {
$url = $this->webroot($path);
} elseif (strpos($path, '://') !== false) {
$url = $path;
} else {
$url = $this->webroot(IMAGES_URL . $path);
}
if (!isset($htmlAttributes['alt'])) {
$htmlAttributes['alt'] = '';
}

View file

@ -31,13 +31,14 @@
<?php __('CakePHP: the rapid development php framework:'); ?>
<?php echo $title_for_layout; ?>
</title>
<?php
echo $html->charset();
echo $html->meta('icon');
<?php echo $html->charset(); ?>
echo $html->css('cake.generic');
<link rel="icon" href="<?php echo $this->webroot; ?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->webroot; ?>favicon.ico" type="image/x-icon" />
<?php echo $html->css('cake.generic'); ?>
<?php echo $scripts_for_layout; ?>
echo $scripts_for_layout;
?>
</head>
<body>
<div id="container">

View file

@ -478,13 +478,14 @@ class View extends Object {
if (time() >= $match['1']) {
@unlink($filename);
unset ($out);
return;
return false;
} else {
if ($this->layout === 'xml') {
header('Content-type: text/xml');
}
$out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out);
echo $out;
return true;
}
}
}

View file

@ -181,6 +181,7 @@ class DispatcherTest extends UnitTestCase {
Configure::write('App.baseUrl', false);
Configure::write('App.dir', 'app');
Configure::write('App.webroot', 'webroot');
Configure::write('Cache.disable', true);
}
function testParseParamsWithoutZerosAndEmptyPost() {
@ -669,7 +670,6 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual($controller->passedArgs, $expected);
Router::reload();
Router::connect('/admin/:controller/:action/*', array('controller' => 'pages', 'action' => 'index', 'admin' => true, 'prefix' => 'admin'));
$Dispatcher =& new TestDispatcher();
$Dispatcher->base = false;
@ -688,6 +688,7 @@ class DispatcherTest extends UnitTestCase {
$expected = 'admin_index';
$this->assertIdentical($controller->action, $expected);
$expected = array('pass'=> array(), 'named' => array(), 'controller' => 'articles_test', 'plugin' => 'articles_test', 'action' => 'admin_index',
'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' => array('url' => 'admin/articles_test'),
'bare' => 0, 'webservices' => null, 'return' => 1
@ -751,12 +752,18 @@ class DispatcherTest extends UnitTestCase {
}
function testStaticAssets() {
$Dispatcher =& new TestDispatcher();
Router::reload();
$Configure = Configure::getInstance();
$Configure->__objects = null;
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
Configure::write('vendorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS));
$Dispatcher =& new TestDispatcher();
Configure::write('debug', 0);
$Dispatcher->params = $Dispatcher->parseParams('css/test_asset.css');
restore_error_handler();
ob_start();
$Dispatcher->cached('css/test_asset.css');
@ -765,10 +772,10 @@ class DispatcherTest extends UnitTestCase {
$this->assertEqual('this is the test asset css file', $result);
Configure::write('debug', 0);
$Dispatcher->plugin = 'test_plugin';
$Dispatcher->params = $Dispatcher->parseParams('test_plugin/css/test_plugin_asset.css');
restore_error_handler();
ob_start();
$Dispatcher->cached('/test_plugin/css/test_plugin_asset.css');
$Dispatcher->cached('test_plugin/css/test_plugin_asset.css');
$result = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$this->assertEqual('this is the test plugin asset css file', $result);
@ -776,8 +783,10 @@ class DispatcherTest extends UnitTestCase {
}
function testFullPageCachingDispatch() {
Configure::write('Cache.disable', false);
Configure::write('Cache.check', true);
Configure::write('debug', 2);
$_POST = array();
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
@ -789,17 +798,14 @@ class DispatcherTest extends UnitTestCase {
$dispatcher->base = false;
$url = 'test_cached_pages/index';
restore_error_handler();
restore_error_handler();
ob_start();
$out = $dispatcher->dispatch($url, array('return' => 1));
$dispatcher->dispatch($url);
$out = ob_get_clean();
$controller = null;
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php';
$view = new View($controller);
ob_start();
$view->renderCache($filename, getMicrotime());
$dispatcher->cached($url);
$cached = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
@ -809,6 +815,7 @@ class DispatcherTest extends UnitTestCase {
$expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
$this->assertEqual($result, $expected);
$filename = CACHE . 'views' . DS . Inflector::slug($dispatcher->here) . '.php';
unlink($filename);
}