mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Removing unneeded code in Dispatcher::cached();
Fixing path search for themes
This commit is contained in:
parent
21d2226f75
commit
43fdde2dad
6 changed files with 42 additions and 28 deletions
|
@ -123,13 +123,11 @@ class Dispatcher extends Object {
|
||||||
$url = $this->getUrl();
|
$url = $this->getUrl();
|
||||||
$this->params = array_merge($this->parseParams($url), $additionalParams);
|
$this->params = array_merge($this->parseParams($url), $additionalParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->here = $this->base . '/' . $url;
|
$this->here = $this->base . '/' . $url;
|
||||||
|
|
||||||
if ($this->cached($url)) {
|
if ($this->cached($url)) {
|
||||||
$this->_stop();
|
$this->_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
$controller =& $this->__getController();
|
$controller =& $this->__getController();
|
||||||
|
|
||||||
if (!is_object($controller)) {
|
if (!is_object($controller)) {
|
||||||
|
@ -141,7 +139,6 @@ class Dispatcher extends Object {
|
||||||
'base' => $this->base
|
'base' => $this->base
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$privateAction = $this->params['action'][0] === '_';
|
$privateAction = $this->params['action'][0] === '_';
|
||||||
$prefixes = Router::prefixes();
|
$prefixes = Router::prefixes();
|
||||||
|
|
||||||
|
@ -167,7 +164,6 @@ class Dispatcher extends Object {
|
||||||
'base' => $this->base
|
'base' => $this->base
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$controller->base = $this->base;
|
$controller->base = $this->base;
|
||||||
$controller->here = $this->here;
|
$controller->here = $this->here;
|
||||||
$controller->webroot = $this->webroot;
|
$controller->webroot = $this->webroot;
|
||||||
|
@ -377,21 +373,21 @@ class Dispatcher extends Object {
|
||||||
$this->webroot = $base .'/';
|
$this->webroot = $base .'/';
|
||||||
return $base;
|
return $base;
|
||||||
}
|
}
|
||||||
$file = '/' . basename($baseUrl);
|
$file = '/' . basename($baseUrl);
|
||||||
$base = dirname($baseUrl);
|
$base = dirname($baseUrl);
|
||||||
|
|
||||||
if ($base === DS || $base === '.') {
|
if ($base === DS || $base === '.') {
|
||||||
$base = '';
|
$base = '';
|
||||||
}
|
}
|
||||||
$this->webroot = $base .'/';
|
$this->webroot = $base .'/';
|
||||||
|
|
||||||
if (strpos($this->webroot, $dir) === false) {
|
if (strpos($this->webroot, $dir) === false) {
|
||||||
$this->webroot .= $dir . '/' ;
|
$this->webroot .= $dir . '/' ;
|
||||||
}
|
}
|
||||||
if (strpos($this->webroot, $webroot) === false) {
|
if (strpos($this->webroot, $webroot) === false) {
|
||||||
$this->webroot .= $webroot . '/';
|
$this->webroot .= $webroot . '/';
|
||||||
}
|
}
|
||||||
return $base . $file;
|
return $base . $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -615,9 +611,8 @@ class Dispatcher extends Object {
|
||||||
if (isset($Media->mimeType[$ext])) {
|
if (isset($Media->mimeType[$ext])) {
|
||||||
$pos = 0;
|
$pos = 0;
|
||||||
$parts = explode('/', $url);
|
$parts = explode('/', $url);
|
||||||
if ($parts[0] === 'css' || $parts[0] === 'js' || $parts[0] === 'img') {
|
|
||||||
$pos = 0;
|
if ($parts[0] === 'theme') {
|
||||||
} elseif ($parts[0] === 'theme') {
|
|
||||||
$pos = strlen($parts[0] . $parts[1]) + 1;
|
$pos = strlen($parts[0] . $parts[1]) + 1;
|
||||||
} elseif (count($parts) > 2) {
|
} elseif (count($parts) > 2) {
|
||||||
$pos = strlen($parts[0]);
|
$pos = strlen($parts[0]);
|
||||||
|
|
|
@ -56,8 +56,7 @@ class ThemeView extends View {
|
||||||
$count = count($paths);
|
$count = count($paths);
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if (strpos($paths[$i], DS . 'plugins' . DS) === false
|
if (strpos($paths[$i], DS . 'plugins' . DS) === false
|
||||||
&& strpos($paths[$i], DS . 'libs' . DS . 'view') === false
|
&& strpos($paths[$i], DS . 'libs' . DS . 'view') === false) {
|
||||||
&& strpos($paths[$i], DS . $plugin . DS) === false) {
|
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . 'plugins' . DS . $plugin . DS;
|
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . 'plugins' . DS . $plugin . DS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1811,13 +1811,24 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
|
||||||
$this->assertEqual($file, $result);
|
$this->assertEqual($file, $result);
|
||||||
|
|
||||||
|
|
||||||
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
|
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/css/test_asset.css');
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->cached('theme/test_theme/css/test_asset.css');
|
$Dispatcher->cached('theme/test_theme/css/test_asset.css');
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
$this->assertEqual('this is the test asset css file', $result);
|
$this->assertEqual('this is the test asset css file', $result);
|
||||||
|
|
||||||
|
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/theme.js');
|
||||||
|
ob_start();
|
||||||
|
$Dispatcher->cached('theme/test_theme/js/theme.js');
|
||||||
|
$result = ob_get_clean();
|
||||||
|
$this->assertEqual('root theme js file', $result);
|
||||||
|
|
||||||
|
$Dispatcher->params = $Dispatcher->parseParams('theme/test_theme/js/one/theme_one.js');
|
||||||
|
ob_start();
|
||||||
|
$Dispatcher->cached('theme/test_theme/js/one/theme_one.js');
|
||||||
|
$result = ob_get_clean();
|
||||||
|
$this->assertEqual('nested theme js file', $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
|
$Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
@ -1856,8 +1867,6 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .DS . 'webroot' . DS . 'img' . DS . 'cake.icon.gif');
|
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' .DS . 'webroot' . DS . 'img' . DS . 'cake.icon.gif');
|
||||||
$this->assertEqual($file, $result);
|
$this->assertEqual($file, $result);
|
||||||
|
|
||||||
|
|
||||||
Configure::write('debug', $debug);
|
|
||||||
$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
|
$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/plugin_js.js');
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->cached('plugin_js/js/plugin_js.js');
|
$Dispatcher->cached('plugin_js/js/plugin_js.js');
|
||||||
|
@ -1865,7 +1874,15 @@ class DispatcherTest extends CakeTestCase {
|
||||||
$expected = "alert('win sauce');";
|
$expected = "alert('win sauce');";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
header('Content-type: text/html');//reset the header content-type without page can render as plain text.
|
$Dispatcher->params = $Dispatcher->parseParams('plugin_js/js/one/plugin_one.js');
|
||||||
|
ob_start();
|
||||||
|
$Dispatcher->cached('plugin_js/js/one/plugin_one.js');
|
||||||
|
$result = ob_get_clean();
|
||||||
|
$expected = "alert('plugin one nested js file');";
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
Configure::write('debug', $debug);
|
||||||
|
//reset the header content-type without page can render as plain text.
|
||||||
|
header('Content-type: text/html');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
alert('plugin one nested js file');
|
|
@ -0,0 +1 @@
|
||||||
|
nested theme js file
|
|
@ -0,0 +1 @@
|
||||||
|
root theme js file
|
Loading…
Reference in a new issue