Browse Source

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.
ADmad 11 years ago
parent
commit
9aca863b48
2 changed files with 6 additions and 50 deletions
  1. 3 24
      src/Core/Plugin.php
  2. 3 26
      tests/TestCase/Core/PluginTest.php

+ 3 - 24
src/Core/Plugin.php

@@ -123,23 +123,18 @@ class Plugin {
 			'autoload' => false,
 			'bootstrap' => false,
 			'routes' => false,
-			'namespace' => $plugin,
 			'classBase' => 'src',
 			'ignoreMissing' => false
 		];
+
 		if (empty($config['path'])) {
 			$paths = App::path('Plugin');
 			foreach ($paths as $path) {
-				$namespacePath = str_replace('\\', DS, $config['namespace']);
 				$pluginPath = str_replace('\\', DS, $plugin);
 				if (is_dir($path . $pluginPath)) {
 					$config += ['path' => $path . $pluginPath . DS];
 					break;
 				}
-				if ($plugin !== $config['namespace'] && is_dir($path . $namespacePath)) {
-					$config += ['path' => $path . $namespacePath . DS];
-					break;
-				}
 			}
 		}
 
@@ -164,11 +159,11 @@ class Plugin {
 				static::$_loader->register();
 			}
 			static::$_loader->addNamespace(
-				$config['namespace'],
+				$plugin,
 				$config['path'] . $config['classBase'] . DS
 			);
 			static::$_loader->addNamespace(
-				$config['namespace'] . '\Test',
+				$plugin . '\Test',
 				$config['path'] . 'tests' . DS
 			);
 		}
@@ -252,22 +247,6 @@ class Plugin {
 	}
 
 /**
- * Return the namespace for a plugin
- *
- * If a plugin is unknown, the plugin name will be used as the namespace.
- * This lets you access vendor libraries or unloaded plugins using `Plugin.Class`.
- *
- * @param string $plugin name of the plugin in CamelCase format
- * @return string namespace to the plugin
- */
-	public static function getNamespace($plugin) {
-		if (empty(static::$_plugins[$plugin])) {
-			return $plugin;
-		}
-		return static::$_plugins[$plugin]['namespace'];
-	}
-
-/**
  * Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
  *
  * @param string $plugin name of the plugin

+ 3 - 26
tests/TestCase/Core/PluginTest.php

@@ -45,24 +45,6 @@ class PluginTest extends TestCase {
 	}
 
 /**
- * Test the plugin namespace
- *
- * @return void
- */
-	public function testGetNamespace() {
-		Plugin::load('TestPlugin');
-		$this->assertEquals('TestPlugin', Plugin::getNamespace('TestPlugin'));
-
-		$this->assertEquals('TestPluginTwo', Plugin::getNamespace('TestPluginTwo'));
-
-		Plugin::load('Company\TestPluginThree');
-		$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('Company\TestPluginThree'));
-
-		Plugin::load('CustomPlugin', array('namespace' => 'Company\TestPluginThree'));
-		$this->assertEquals('Company\TestPluginThree', Plugin::getNamespace('CustomPlugin'));
-	}
-
-/**
  * Tests loading a single plugin
  *
  * @return void
@@ -124,11 +106,6 @@ class PluginTest extends TestCase {
 		Plugin::load('Company\TestPluginThree', array('bootstrap' => true));
 		$this->assertTrue(Plugin::loaded('Company\TestPluginThree'));
 		$this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
-
-		Configure::delete('PluginTest.test_plugin_three.bootstrap');
-		Plugin::load('NewName', array('namespace' => 'Company\TestPluginThree', 'bootstrap' => true));
-		$this->assertTrue(Plugin::loaded('NewName'));
-		$this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
 	}
 
 /**
@@ -291,9 +268,9 @@ class PluginTest extends TestCase {
  * @return void
  */
 	public function testLoadAllWithPluginAlreadyLoaded() {
-		Plugin::load('PluginJs', ['namespace' => 'Company\TestPluginJs']);
-		Plugin::loadAll();
-		$this->assertEquals('Company\TestPluginJs', Plugin::getNamespace('PluginJs'));
+		Plugin::load('Company\TestPluginThree', ['bootstrap' => false]);
+		Plugin::loadAll(['bootstrap' => true, 'ignoreMissing' => true]);
+		$this->assertEmpty(Configure::read('PluginTest.test_plugin_three.bootstrap'));
 	}
 
 /**