Browse Source

Allow plugins to be loaded by short plugin names.

Mark Story 8 years ago
parent
commit
a855b7d088
2 changed files with 16 additions and 0 deletions
  1. 3 0
      src/Http/BaseApplication.php
  2. 13 0
      tests/TestCase/Http/BaseApplicationTest.php

+ 3 - 0
src/Http/BaseApplication.php

@@ -138,6 +138,9 @@ abstract class BaseApplication implements
     public function makePlugin($name, array $config)
     {
         if (!class_exists($name)) {
+            $name = str_replace('/', '\\', $name) . '\\' . 'Plugin';
+        }
+        if (!class_exists($name)) {
             throw new InvalidArgumentException("The `{$name}` plugin cannot be found");
         }
         $plugin = new $name($config);

+ 13 - 0
tests/TestCase/Http/BaseApplicationTest.php

@@ -77,6 +77,19 @@ class BaseApplicationTest extends TestCase
         $app->addPlugin(__CLASS__);
     }
 
+    public function testAddPluginValidShortName()
+    {
+        $app = $this->getMockForAbstractClass(BaseApplication::class, [$this->path]);
+        $app->addPlugin('TestPlugin');
+
+        $this->assertCount(1, $app->getPlugins());
+        $this->assertTrue($app->getPlugins()->has('TestPlugin'));
+
+        $app->addPlugin('Company/TestPluginThree');
+        $this->assertCount(2, $app->getPlugins());
+        $this->assertTrue($app->getPlugins()->has('Company/TestPluginThree'));
+    }
+
     public function testAddPluginValid()
     {
         $app = $this->getMockForAbstractClass(BaseApplication::class, [$this->path]);