Permalink
Browse files

Remove App::build() for plugins.

Plugins should use the 'path' option for custom paths. This removes
directory scanning and makes plugin configuration explicit. A default
path can be set using `App.pluginPath` in Configure.

Now that the TestApp is the 'app' when core tests run many of the calls
to App::build() are no longer relevant or necessary. Remove them to
simplify tests.
  • Loading branch information...
markstory committed Sep 8, 2013
1 parent 44b31a0 commit 6dd16b874074cb4f8ed7af7106366af4ee5be909
View
@@ -173,19 +173,13 @@ public static function classname($class, $type = '', $suffix = '') {
*/
public static function path($type, $plugin = null) {
if (!empty($plugin)) {
$path = array();
$path = [];
$pluginPath = static::pluginPath($plugin);
$packageFormat = static::_packageFormat();
if (!empty($packageFormat[$type])) {
foreach ($packageFormat[$type] as $f) {
$path[] = sprintf($f, $pluginPath);
}
}
$path[] = $pluginPath . $type;
return $path;
}
if (!isset(static::$_packages[$type])) {
return array();
return [APP . DS . $type];
}
return static::$_packages[$type];
}
@@ -451,60 +445,12 @@ public static function init() {
protected static function _packageFormat() {
if (empty(static::$_packageFormat)) {
static::$_packageFormat = array(
'Model' => array(
'%s' . 'Model' . DS
),
'Model/Behavior' => array(
'%s' . 'Model' . DS . 'Behavior' . DS
),
'Model/Datasource' => array(
'%s' . 'Model' . DS . 'Datasource' . DS
),
'Model/Datasource/Database' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Database' . DS
),
'Model/Datasource/Session' => array(
'%s' . 'Model' . DS . 'Datasource' . DS . 'Session' . DS
),
'Controller' => array(
'%s' . 'Controller' . DS
),
'Controller/Component' => array(
'%s' . 'Controller' . DS . 'Component' . DS
),
'Controller/Component/Auth' => array(
'%s' . 'Controller' . DS . 'Component' . DS . 'Auth' . DS
),
'Controller/Component/Acl' => array(
'%s' . 'Controller' . DS . 'Component' . DS . 'Acl' . DS
),
'View' => array(
'%s' . 'View' . DS
),
'View/Helper' => array(
'%s' . 'View' . DS . 'Helper' . DS
),
'Console' => array(
'%s' . 'Console' . DS
),
'Console/Command' => array(
'%s' . 'Console' . DS . 'Command' . DS
),
'Console/Command/Task' => array(
'%s' . 'Console' . DS . 'Command' . DS . 'Task' . DS
),
'Lib' => array(
'%s' . 'Lib' . DS
),
'Locale' => array(
'%s' . 'Locale' . DS
),
'Vendor' => array(
ROOT . DS . 'vendor' . DS,
),
'Plugin' => array(
ROOT . DS . 'Plugin' . DS,
)
);
}
View
@@ -100,8 +100,7 @@ class Plugin {
* - `routes` - boolean - Whether or not you want to load the $plugin/Config/routes.php file.
* - `namespace` - string - A custom namespace for the plugin. It will default to the plugin name.
* - `ignoreMissing` - boolean - Set to true to ignore missing bootstrap/routes files.
* - `path` - string - The path the plugin can be found on. If empty the plugin paths will scanned
* for a directory with a name matching the namespace.
* - `path` - string - The path the plugin can be found on. If empty the default plugin path will be used.
*
* @param string|array $plugin name of the plugin to be loaded in CamelCase format or array or plugins to load
* @param array $config configuration options for the plugin
@@ -119,24 +118,22 @@ public static function load($plugin, $config = array()) {
$config += array('bootstrap' => false, 'routes' => false, 'namespace' => $plugin, 'ignoreMissing' => false);
if (empty($config['path'])) {
$path = Configure::read('App.pluginPath');
$namespacePath = str_replace('\\', DS, $config['namespace']);
foreach (App::path('Plugin') as $path) {
if (is_dir($path . $plugin)) {
$config += array('path' => $path . $plugin . DS);
break;
}
if ($plugin !== $config['namespace'] && is_dir($path . $namespacePath)) {
$config += array('path' => $path . $namespacePath . DS);
break;
}
if (is_dir($path . $plugin)) {
$config += array('path' => $path . $plugin . DS);
}
if ($plugin !== $config['namespace'] && is_dir($path . $namespacePath)) {
$config += array('path' => $path . $namespacePath . DS);
}
}
static::$_plugins[$plugin] = $config;
if (empty(static::$_plugins[$plugin]['path'])) {
if (empty($config['path'])) {
throw new Error\MissingPluginException(array('plugin' => $plugin));
}
static::$_plugins[$plugin] = $config;
if (!empty(static::$_plugins[$plugin]['bootstrap'])) {
static::bootstrap($plugin);
}
@@ -31,18 +31,6 @@
*/
class BasicsTest extends TestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
App::build(array(
'Locale' => array(CAKE . 'Test/TestApp/Locale/')
));
}
/**
* test the array_diff_key compatibility function.
*
@@ -76,10 +76,6 @@ public function testNonFatalErrorsWithCachedisable() {
* @return void
*/
public function testConfigWithLibAndPluginEngines() {
App::build(array(
'Lib' => array(CAKE . 'Test/TestApp/Lib/'),
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Configure::write('App.namespace', 'TestApp');
Plugin::load('TestPlugin');
@@ -298,10 +294,6 @@ public function testConfigured() {
* @return void
*/
public function testDrop() {
App::build(array(
'Lib' => array(CAKE . 'Test/TestApp/Lib/'),
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Configure::write('App.namespace', 'TestApp');
$result = Cache::drop('some_config_that_does_not_exist');
@@ -346,10 +338,6 @@ public function testWriteEmptyValues() {
* @return void
*/
public function testWriteTriggerError() {
App::build(array(
'Lib' => array(CAKE . 'Test/TestApp/Lib/'),
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Configure::write('App.namespace', 'TestApp');
Cache::config('test_trigger', [
'engine' => 'TestAppCache',
@@ -363,7 +351,6 @@ public function testWriteTriggerError() {
$this->assertTrue(true);
}
Cache::drop('test_trigger');
App::build();
}
/**
@@ -215,9 +215,6 @@ public function testReadWithDots() {
* @return void
*/
public function testReadPluginValue() {
App::build(array(
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Plugin::load('TestPlugin');
$engine = new IniConfig($this->path);
$result = $engine->read('TestPlugin.nested');
@@ -238,9 +235,6 @@ public function testReadPluginValue() {
* @return void
*/
public function testReadPluginSpecialAclIniPhpValue() {
App::build(array(
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Plugin::load('TestPlugin');
$engine = new IniConfig($this->path);
$result = $engine->read('TestPlugin.acl.ini.php');
@@ -122,9 +122,6 @@ public function testReadWithDots() {
* @return void
*/
public function testReadPluginValue() {
App::build(array(
'Plugin' => array(CAKE . 'Test/TestApp/Plugin/')
), App::RESET);
Plugin::load('TestPlugin');
$engine = new PhpConfig($this->path);
$result = $engine->read('TestPlugin.load');
@@ -54,14 +54,6 @@ class CommandListShellTest extends TestCase {
*/
public function setUp() {
parent::setUp();
App::build(array(
'Plugin' => array(
CAKE . 'Test/TestApp/Plugin/'
),
'Console/Command' => array(
CAKE . 'Test/TestApp/Console/Command/'
)
), App::RESET);
Plugin::load(array('TestPlugin', 'TestPluginTwo'));
$out = new TestStringOutput();

0 comments on commit 6dd16b8

Please sign in to comment.