mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding App::themePath(). Will be used to reduce code duplication in a variety of places.
This commit is contained in:
parent
e023350af5
commit
91f8e220e4
2 changed files with 38 additions and 1 deletions
|
@ -702,7 +702,7 @@ class App extends Object {
|
|||
/**
|
||||
* Get the path that a plugin is on. Searches through the defined plugin paths.
|
||||
*
|
||||
* @param string $plugin CamelCased plugin name to find the path of.
|
||||
* @param string $plugin CamelCased/lower_cased plugin name to find the path of.
|
||||
* @return string full path to the plugin.
|
||||
*/
|
||||
function pluginPath($plugin) {
|
||||
|
@ -716,6 +716,23 @@ class App extends Object {
|
|||
return $_this->plugins[0] . $pluginDir . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the path that a theme is on. Search through the defined theme paths.
|
||||
*
|
||||
* @param string $theme lower_cased theme name to find the path of.
|
||||
* @return string full path to the theme.
|
||||
*/
|
||||
function themePath($theme) {
|
||||
$_this =& App::getInstance();
|
||||
$themeDir = 'themed' . DS . Inflector::underscore($theme);
|
||||
for ($i = 0, $length = count($_this->views); $i < $length; $i++) {
|
||||
if (is_dir($_this->views[$i] . $themeDir)) {
|
||||
return $_this->views[$i] . $themeDir . DS ;
|
||||
}
|
||||
}
|
||||
return $_this->views[0] . $themeDir . DS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a key/value list of all paths where core libs are found.
|
||||
* Passing $type only returns the values for a given value of $key.
|
||||
|
|
|
@ -460,6 +460,26 @@ class AppImportTest extends CakeTestCase {
|
|||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* test that pluginPath can find paths for plugins.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testThemePath() {
|
||||
App::build(array(
|
||||
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
|
||||
));
|
||||
$path = App::themePath('test_theme');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
|
||||
$this->assertEqual($path, $expected);
|
||||
|
||||
$path = App::themePath('TestTheme');
|
||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
|
||||
$this->assertEqual($path, $expected);
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
* testClassLoading method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue