mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-02 09:32:43 +00:00
some more updates to path handling
This commit is contained in:
parent
24d78dd671
commit
c3643767bf
20 changed files with 113 additions and 96 deletions
|
@ -214,7 +214,7 @@ class ShellDispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
$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)) {
|
||||
|
@ -222,7 +222,7 @@ class ShellDispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
$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 @@ class ShellDispatcher {
|
|||
|
||||
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 @@ class ApiShell extends Shell {
|
|||
$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 @@ class TestSuiteShell extends Shell {
|
|||
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 @@ class Dispatcher extends Object {
|
|||
$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,6 +598,9 @@ 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
|
||||
|
@ -605,15 +608,19 @@ class App extends Object {
|
|||
*/
|
||||
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 @@ class App extends Object {
|
|||
}
|
||||
|
||||
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 @@ class I18n extends Object {
|
|||
$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 @@ class CakeSchema extends Object {
|
|||
}
|
||||
|
||||
if (!is_array($models) && $models !== false) {
|
||||
$models = Configure::listObjects('model');
|
||||
$models = App::objects('model');
|
||||
}
|
||||
|
||||
if (is_array($models)) {
|
||||
|
|
|
@ -593,7 +593,7 @@ class Router extends Object {
|
|||
$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 @@ class ShellTest extends CakeTestCase {
|
|||
*/
|
||||
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 @@ class DispatcherTest extends CakeTestCase {
|
|||
$_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 @@ class DispatcherTest extends CakeTestCase {
|
|||
$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 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
**/
|
||||
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 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
*/
|
||||
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 @@ class ConfigureTest extends CakeTestCase {
|
|||
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 @@ class AppImportTest extends UnitTestCase {
|
|||
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 @@ class ControllerTest extends CakeTestCase {
|
|||
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 @@ class ScaffoldViewTest extends CakeTestCase {
|
|||
$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 @@ class ObjectTest extends CakeTestCase {
|
|||
$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));
|
||||
|
|
|
@ -758,7 +758,7 @@ if (function_exists('caketestsgetreporter')) {
|
|||
ob_start();
|
||||
$groups = $_SERVER['PHP_SELF'].'?show=groups';
|
||||
$cases = $_SERVER['PHP_SELF'].'?show=cases';
|
||||
$plugins = Configure::listObjects('plugin');
|
||||
$plugins = App::objects('plugin');
|
||||
include CAKE_TESTS_LIB . 'content.php';
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue