Skip to content

Commit 9aca863

Browse files
committed
Remove plugin namespace aliasing and shortening.
Aliasing a plugin namespace in app won't work as the plugin itself could be using plugin notation with hardcoded name.
1 parent 555d941 commit 9aca863

File tree

2 files changed

+6
-50
lines changed

2 files changed

+6
-50
lines changed

src/Core/Plugin.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,18 @@ public static function load($plugin, array $config = []) {
123123
'autoload' => false,
124124
'bootstrap' => false,
125125
'routes' => false,
126-
'namespace' => $plugin,
127126
'classBase' => 'src',
128127
'ignoreMissing' => false
129128
];
129+
130130
if (empty($config['path'])) {
131131
$paths = App::path('Plugin');
132132
foreach ($paths as $path) {
133-
$namespacePath = str_replace('\\', DS, $config['namespace']);
134133
$pluginPath = str_replace('\\', DS, $plugin);
135134
if (is_dir($path . $pluginPath)) {
136135
$config += ['path' => $path . $pluginPath . DS];
137136
break;
138137
}
139-
if ($plugin !== $config['namespace'] && is_dir($path . $namespacePath)) {
140-
$config += ['path' => $path . $namespacePath . DS];
141-
break;
142-
}
143138
}
144139
}
145140

@@ -164,11 +159,11 @@ public static function load($plugin, array $config = []) {
164159
static::$_loader->register();
165160
}
166161
static::$_loader->addNamespace(
167-
$config['namespace'],
162+
$plugin,
168163
$config['path'] . $config['classBase'] . DS
169164
);
170165
static::$_loader->addNamespace(
171-
$config['namespace'] . '\Test',
166+
$plugin . '\Test',
172167
$config['path'] . 'tests' . DS
173168
);
174169
}
@@ -251,22 +246,6 @@ public static function configPath($plugin) {
251246
return static::$_plugins[$plugin]['configPath'];
252247
}
253248

254-
/**
255-
* Return the namespace for a plugin
256-
*
257-
* If a plugin is unknown, the plugin name will be used as the namespace.
258-
* This lets you access vendor libraries or unloaded plugins using `Plugin.Class`.
259-
*
260-
* @param string $plugin name of the plugin in CamelCase format
261-
* @return string namespace to the plugin
262-
*/
263-
public static function getNamespace($plugin) {
264-
if (empty(static::$_plugins[$plugin])) {
265-
return $plugin;
266-
}
267-
return static::$_plugins[$plugin]['namespace'];
268-
}
269-
270249
/**
271250
* Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
272251
*

tests/TestCase/Core/PluginTest.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,6 @@ public function tearDown() {
4444
Plugin::unload();
4545
}
4646

47-
/**
48-
* Test the plugin namespace
49-
*
50-
* @return void
51-
*/
52-
public function testGetNamespace() {
53-
Plugin::load('TestPlugin');
54-
$this->assertEquals('TestPlugin', Plugin::getNamespace('TestPlugin'));
55-
56-
$this->assertEquals('TestPluginTwo', Plugin::getNamespace('TestPluginTwo'));
57-
58-
Plugin::load('Company\TestPluginThree');
59-
$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('Company\TestPluginThree'));
60-
61-
Plugin::load('CustomPlugin', array('namespace' => 'Company\TestPluginThree'));
62-
$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('CustomPlugin'));
63-
}
64-
6547
/**
6648
* Tests loading a single plugin
6749
*
@@ -124,11 +106,6 @@ public function testLoadSingleWithBootstrap() {
124106
Plugin::load('Company\TestPluginThree', array('bootstrap' => true));
125107
$this->assertTrue(Plugin::loaded('Company\TestPluginThree'));
126108
$this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
127-
128-
Configure::delete('PluginTest.test_plugin_three.bootstrap');
129-
Plugin::load('NewName', array('namespace' => 'Company\TestPluginThree', 'bootstrap' => true));
130-
$this->assertTrue(Plugin::loaded('NewName'));
131-
$this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
132109
}
133110

134111
/**
@@ -291,9 +268,9 @@ public function testLoadAll() {
291268
* @return void
292269
*/
293270
public function testLoadAllWithPluginAlreadyLoaded() {
294-
Plugin::load('PluginJs', ['namespace' => 'Company\TestPluginJs']);
295-
Plugin::loadAll();
296-
$this->assertEquals('Company\TestPluginJs', Plugin::getNamespace('PluginJs'));
271+
Plugin::load('Company\TestPluginThree', ['bootstrap' => false]);
272+
Plugin::loadAll(['bootstrap' => true, 'ignoreMissing' => true]);
273+
$this->assertEmpty(Configure::read('PluginTest.test_plugin_three.bootstrap'));
297274
}
298275

299276
/**

0 commit comments

Comments
 (0)