Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring Dispatcher::asset() to remove code left behind from previous

refactoring.  Simplifies asset location as well.
  • Loading branch information...
commit bff7ce692582e931a97a24eb52bcea616f92f944 1 parent 42a5665
@markstory markstory authored
Showing with 18 additions and 35 deletions.
  1. +18 −35 cake/dispatcher.php
View
53 cake/dispatcher.php
@@ -612,47 +612,30 @@ function asset($url) {
}
$controller = null;
$ext = array_pop(explode('.', $url));
- $pos = 0;
$parts = explode('/', $url);
-
- if ($parts[0] === 'theme') {
- $pos = strlen($parts[0] . $parts[1]) + 1;
- } else {
- $pos = strlen($parts[0]);
- }
$assetFile = null;
- $paths = array();
- $matched = false;
-
- if ($pos > 0) {
- $plugin = substr($url, 0, $pos);
- $url = preg_replace('/^' . preg_quote($plugin, '/') . '\//i', '', $url);
-
- if (strpos($plugin, '/') !== false) {
- list($plugin, $theme) = explode('/', $plugin);
- $themePaths = App::path('views');
-
- foreach ($themePaths as $viewPath) {
- $path = $viewPath . 'themed' . DS . $theme . DS . 'webroot' . DS;
- if ($plugin === 'theme' && (is_file($path . $url) && file_exists($path . $url))) {
- $assetFile = $path . $url;
- break;
- }
- }
- }
- if ($matched === false) {
- $paths[] = App::pluginPath($plugin) . 'webroot' . DS;
- }
- }
-
- if ($matched === false) {
- foreach ($paths as $path) {
- if (is_file($path . $url) && file_exists($path . $url)) {
- $assetFile = $path . $url;
+ if ($parts[0] === 'theme') {
+ $themeName = $parts[1];
+ unset($parts[0], $parts[1]);
+ $fileFragment = implode('/', $parts);
+
+ $viewPaths = App::path('views');
+ foreach ($viewPaths as $viewPath) {
+ $path = $viewPath . 'themed' . DS . $themeName . DS . 'webroot' . DS;
+ if (file_exists($path . $fileFragment)) {
+ $assetFile = $path . $fileFragment;
break;
}
}
+ } else {
+ $plugin = $parts[0];
+ unset($parts[0]);
+ $fileFragment = implode('/', $parts);
+ $pluginWebroot = App::pluginPath($plugin) . 'webroot' . DS;
+ if (file_exists($pluginWebroot . $fileFragment)) {
+ $assetFile = $pluginWebroot . $fileFragment;
+ }
}
if ($assetFile !== null) {
Please sign in to comment.
Something went wrong with that request. Please try again.