Skip to content
Permalink
Browse files

some more updates to path handling

  • Loading branch information...
gwoo
gwoo committed Jun 10, 2009
1 parent 24d78dd commit c3643767bff712cad343740aa94def74c7ac7386
@@ -214,15 +214,15 @@ function __buildPaths() {
}
}
$vendorPaths = array_values(Configure::read('vendorPaths'));
$vendorPaths = array_values(App::path('vendors'));
foreach ($vendorPaths as $vendorPath) {
$path = rtrim($vendorPath, DS) . DS . 'shells' . DS;
if (file_exists($path)) {
$paths[] = $path;
}
}
$this->shellPaths = array_values(array_unique(array_merge($paths, Configure::read('shellPaths'))));
$this->shellPaths = array_values(array_unique(array_merge($paths, App::path('shells'))));
}
/**
* Initializes the environment and loads the Cake core.
@@ -548,7 +548,7 @@ function help() {
foreach ($this->shellPaths as $path) {
if (is_dir($path)) {
$shells = Configure::listObjects('file', $path);
$shells = App::objects('file', $path);
$path = str_replace(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, 'CORE' . DS, $path);
$path = str_replace(APP, 'APP' . DS, $path);
$path = str_replace(ROOT, 'ROOT', $path);
@@ -82,7 +82,7 @@ function main() {
$class = Inflector::camelize($file);
}
$objects = Configure::listObjects('class', $path);
$objects = App::objects('class', $path);
if (in_array($class, $objects)) {
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) {
if (!preg_match('/' . Inflector::camelize($type) . '$/', $class)) {
@@ -58,7 +58,7 @@ class ConsoleShell extends Shell {
function initialize() {
require_once CAKE . 'dispatcher.php';
$this->Dispatcher = new Dispatcher();
$this->models = Configure::listObjects('model');
$this->models = App::objects('model');
App::import('Model', $this->models);
foreach ($this->models as $model) {
@@ -93,7 +93,7 @@ function initialize() {
require_once CAKE . 'tests' . DS . 'lib' . DS . 'test_manager.php';
require_once CAKE . 'tests' . DS . 'lib' . DS . 'cli_reporter.php';
$plugins = Configure::listObjects('plugin');
$plugins = App::objects('plugin');
foreach ($plugins as $p) {
$this->plugins[] = Inflector::underscore($p);
}
@@ -626,7 +626,7 @@ function cached($url) {
$paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS;
}
}
$paths = array_merge($paths, Configure::read('vendorPaths'));
$paths = array_merge($paths, App::path('vendors'));
foreach ($paths as $path) {
if (is_file($path . $url) && file_exists($path . $url)) {
@@ -460,18 +460,18 @@ class App extends Object {
* @var array
* @access public
*/
var $objects = array(
'model' => array('suffix' => '.php', 'base' => 'AppModel', 'core' => false),
'behavior' => array('suffix' => '.php', 'base' => 'ModelBehavior'),
'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'),
'component' => array('suffix' => '.php', 'base' => null),
'view' => array('suffix' => '.php', 'base' => null),
'helper' => array('suffix' => '.php', 'base' => 'AppHelper'),
'plugin' => array('suffix' => '', 'base' => null),
'vendor' => array('suffix' => '', 'base' => null),
'shell' => array('suffix' => 'Shell', 'base' => 'Shell'),
'class' => array('suffix' => '.php', 'base' => null),
'file' => array('suffix' => '.php', 'base' => null)
var $types = array(
'model' => array('suffix' => '.php', 'extends' => 'AppModel'),
'behavior' => array('suffix' => '.php', 'extends' => 'ModelBehavior'),
'controller' => array('suffix' => '_controller.php', 'extends' => 'AppController'),
'component' => array('suffix' => '.php', 'extends' => null),
'view' => array('suffix' => '.php', 'extends' => null),
'helper' => array('suffix' => '.php', 'extends' => 'AppHelper'),
'plugin' => array('suffix' => '', 'extends' => null),
'vendor' => array('suffix' => '', 'extends' => null),
'shell' => array('suffix' => '.php', 'extends' => 'Shell'),
'class' => array('suffix' => '.php', 'extends' => null),
'file' => array('suffix' => '.php', 'extends' => null)
);
/**
@@ -598,22 +598,29 @@ class App extends Object {
*
* Usage
* App::path('models'); will return all paths for models
* App::path('models', array('/path/to/models')); will set and return all paths for models
* App::path(array('models' => array('/path/to/models')); will set and return all paths for models
*
*
* @param string $type type of path
* @return string array
* @access public
*/
function path($type, $value = array()) {
$_this =& App::getInstance();
if (!isset($_this->{"_{$type}"})) {
return array();
}
if (empty($value)) {
if (is_array($type)) {
foreach ($type as $object => $value) {
$_this->{"_{$type}"} = (array)$value;
}
return $value;
}
if (!isset($_this->{"_{$type}"})) {
return array();
}
return $_this->{"_{$type}"};
}
if (!empty($value)) {
return $_this->{"_{$type}"} = (array)$value;
}
return $_this->{"_{$type}"} = (array)$value;
}
/**
* Build path references. Merges the supplied $paths
@@ -744,7 +751,7 @@ function objects($type, $path = null, $cache = true) {
}
if (empty($_this->__objects) || !isset($_this->__objects[$type]) || $cache !== true) {
$types = $_this->objects;
$types = $_this->types;
if (!isset($types[$type])) {
return false;
@@ -251,8 +251,8 @@ function __bindTextDomain($domain) {
$this->__noLocale = true;
$core = true;
$merge = array();
$searchPaths = Configure::read('localePaths');
$plugins = Configure::listObjects('plugin');
$searchPaths = App::path('locales');;
$plugins = App::objects('plugin');
if (!empty($plugins)) {
$pluginPaths = App::path('plugins');
@@ -198,7 +198,7 @@ function read($options = array()) {
}
if (!is_array($models) && $models !== false) {
$models = Configure::listObjects('model');
$models = App::objects('model');
}
if (is_array($models)) {
@@ -593,7 +593,7 @@ function __connectDefaultRoutes() {
$params = array('prefix' => $this->__admin, $this->__admin => true);
}
if ($plugins = Configure::listObjects('plugin')) {
if ($plugins = App::objects('plugin')) {
foreach ($plugins as $key => $value) {
$plugins[$key] = Inflector::underscore($value);
}
@@ -40,7 +40,7 @@ class BasicsTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->_localePaths = Configure::read('localePaths');
$this->_localePaths = App::path('locales');;
App::path('locales', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale'));
$this->_language = Configure::read('Config.language');
}
@@ -124,7 +124,7 @@ class ShellDispatcherTest extends UnitTestCase {
*/
function setUp() {
$this->_pluginPaths = App::path('plugins');
$this->_shellPaths = Configure::read('shellPaths');
$this->_shellPaths = App::path('shells');
App::path('plugins', array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
@@ -120,9 +120,9 @@ function testConstruct() {
*/
function testInitialize() {
$_back = array(
'modelPaths' => Configure::read('modelPaths'),
'pluginPaths' => Configure::read('pluginPaths'),
'viewPaths' => Configure::read('viewPaths'),
'modelPaths' => App::path('models'),
'pluginPaths' => App::path('plugins'),
'viewPaths' => App::path('views'),
);
App::path('plugins', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
App::path('models', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS));
@@ -531,7 +531,7 @@ function endTest() {
$_SERVER = $this->_server;
Configure::write('App', $this->_app);
Configure::write('Cache', $this->_cache);
Configure::write('vendorPaths', $this->_vendorPaths);
App::path('vendors', $this->_vendorPaths);
App::path('plugins', $this->_pluginPaths);
App::path('views', $this->_viewPaths);
App::path('controllers', $this->_controllerPaths);
@@ -1679,7 +1679,7 @@ function testStaticAssets() {
$Configure->__objects = null;
App::path('plugins', 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));
App::path('vendors', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS));
$Dispatcher =& new TestDispatcher();
@@ -239,10 +239,10 @@ function testGetTests() {
**/
function testTestAction() {
$_back = array(
'controller' => Configure::read('controllerPaths'),
'view' => Configure::read('viewPaths'),
'model' => Configure::read('modelPaths'),
'plugin' => Configure::read('pluginPaths')
'controller' => App::path('controllers'),
'view' => App::path('views'),
'model' => App::path('models'),
'plugin' => App::path('plugins')
);
App::path('controllers', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS));
App::path('views', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS));
@@ -389,9 +389,9 @@ function testSkipIf() {
*/
function testTestDispatcher() {
$_back = array(
'controller' => Configure::read('controllerPaths'),
'view' => Configure::read('viewPaths'),
'plugin' => Configure::read('pluginPaths')
'controller' => App::path('controllers'),
'view' => App::path('views'),
'plugin' => App::path('plugins')
);
App::path('controllers', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS));
App::path('views', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS));
@@ -72,50 +72,6 @@ function tearDown() {
Configure::write('debug', $this->_debug);
Configure::write('Cache.disable', $this->_cacheDisable);
}
/**
* testListObjects method
*
* @access public
* @return void
*/
function testListObjects() {
$result = Configure::listObjects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs');
$this->assertTrue(in_array('Xml', $result));
$this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('HttpSocket', $result));
$result = Configure::listObjects('behavior');
$this->assertTrue(in_array('Tree', $result));
$result = Configure::listObjects('controller');
$this->assertTrue(in_array('Pages', $result));
$result = Configure::listObjects('component');
$this->assertTrue(in_array('Auth', $result));
$result = Configure::listObjects('view');
$this->assertTrue(in_array('Media', $result));
$result = Configure::listObjects('helper');
$this->assertTrue(in_array('Html', $result));
$result = Configure::listObjects('model');
$notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema');
foreach ($notExpected as $class) {
$this->assertFalse(in_array($class, $result));
}
$result = Configure::listObjects('file');
$this->assertFalse($result);
$result = Configure::listObjects('file', 'non_existing_configure');
$expected = array();
$this->assertEqual($result, $expected);
$result = Configure::listObjects('NonExistingType');
$this->assertFalse($result);
}
/**
* testRead method
*
@@ -266,7 +222,61 @@ function testBuild() {
App::build();
$models = App::path('models');
$this->assertTrue(!empty($models));
}
/**
* testBuildPaths method
*
* @access public
* @return void
*/
function testCore() {
$model = App::core('model');
$this->assertTrue(!empty($models));
}
/**
* testListObjects method
*
* @access public
* @return void
*/
function testListObjects() {
$result = App::objects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs');
$this->assertTrue(in_array('Xml', $result));
$this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('HttpSocket', $result));
$result = App::objects('behavior');
$this->assertTrue(in_array('Tree', $result));
$result = App::objects('controller');
$this->assertTrue(in_array('Pages', $result));
$result = App::objects('component');
$this->assertTrue(in_array('Auth', $result));
$result = App::objects('view');
$this->assertTrue(in_array('Media', $result));
$result = App::objects('helper');
$this->assertTrue(in_array('Html', $result));
$result = App::objects('model');
$notExpected = array('AppModel', 'Behavior', 'ConnectionManager', 'DbAcl', 'Model', 'Schema');
foreach ($notExpected as $class) {
$this->assertFalse(in_array($class, $result));
}
$result = App::objects('file');
$this->assertFalse($result);
$result = App::objects('file', 'non_existing_configure');
$expected = array();
$this->assertEqual($result, $expected);
$result = App::objects('NonExistingType');
$this->assertFalse($result);
}
/**
* testClassLoading method
*
@@ -395,7 +395,7 @@ function testConstructClasses() {
unset($Controller);
$_back = array(
'pluginPaths' => Configure::read('pluginPaths'),
'pluginPaths' => App::path('plugins'),
);
App::path('plugins', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
@@ -263,8 +263,8 @@ function testGetViewFilename() {
$this->assertEqual($result, $expected);
$_back = array(
'viewPaths' => Configure::read('viewPaths'),
'pluginPaths' => Configure::read('pluginPaths'),
'viewPaths' => App::path('views'),
'pluginPaths' => App::path('plugins'),
);
App::path('views', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS));
App::path('plugins', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
@@ -39,7 +39,7 @@ class I18nTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->_localePaths = Configure::read('localePaths');
$this->_localePaths = App::path('locales');;
App::path('locales', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale'));
}
/**
@@ -613,9 +613,9 @@ function testRequestAction() {
$this->assertEqual($result, $expected);
$_back = array(
'controller' => Configure::read('controllerPaths'),
'view' => Configure::read('viewPaths'),
'plugin' => Configure::read('pluginPaths')
'controller' => App::path('controllers'),
'view' => App::path('views'),
'plugin' => App::path('plugins')
);
App::path('controllers', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS));
App::path('views', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS));
Oops, something went wrong.

0 comments on commit c364376

Please sign in to comment.
You can’t perform that action at this time.