Skip to content

Commit 91f8e22

Browse files
committed
Adding App::themePath(). Will be used to reduce code duplication in a variety of places.
1 parent e023350 commit 91f8e22

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

cake/libs/configure.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ function build($paths = array(), $reset = false) {
702702
/**
703703
* Get the path that a plugin is on. Searches through the defined plugin paths.
704704
*
705-
* @param string $plugin CamelCased plugin name to find the path of.
705+
* @param string $plugin CamelCased/lower_cased plugin name to find the path of.
706706
* @return string full path to the plugin.
707707
*/
708708
function pluginPath($plugin) {
@@ -716,6 +716,23 @@ function pluginPath($plugin) {
716716
return $_this->plugins[0] . $pluginDir . DS;
717717
}
718718

719+
/**
720+
* Find the path that a theme is on. Search through the defined theme paths.
721+
*
722+
* @param string $theme lower_cased theme name to find the path of.
723+
* @return string full path to the theme.
724+
*/
725+
function themePath($theme) {
726+
$_this =& App::getInstance();
727+
$themeDir = 'themed' . DS . Inflector::underscore($theme);
728+
for ($i = 0, $length = count($_this->views); $i < $length; $i++) {
729+
if (is_dir($_this->views[$i] . $themeDir)) {
730+
return $_this->views[$i] . $themeDir . DS ;
731+
}
732+
}
733+
return $_this->views[0] . $themeDir . DS;
734+
}
735+
719736
/**
720737
* Returns a key/value list of all paths where core libs are found.
721738
* Passing $type only returns the values for a given value of $key.

cake/tests/cases/libs/configure.test.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,26 @@ function testPluginPath() {
460460
App::build();
461461
}
462462

463+
/**
464+
* test that pluginPath can find paths for plugins.
465+
*
466+
* @return void
467+
*/
468+
function testThemePath() {
469+
App::build(array(
470+
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
471+
));
472+
$path = App::themePath('test_theme');
473+
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
474+
$this->assertEqual($path, $expected);
475+
476+
$path = App::themePath('TestTheme');
477+
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
478+
$this->assertEqual($path, $expected);
479+
480+
App::build();
481+
}
482+
463483
/**
464484
* testClassLoading method
465485
*

0 commit comments

Comments
 (0)