Browse Source

Make plugin names an option.

This will make it possible to use PluginApp as an 'auto-plugin'
placeholder.
mark_story 8 years ago
parent
commit
6f09ad6289
2 changed files with 19 additions and 2 deletions
  1. 13 2
      src/Core/PluginApp.php
  2. 6 0
      tests/TestCase/Core/PluginAppTest.php

+ 13 - 2
src/Core/PluginApp.php

@@ -74,6 +74,13 @@ class PluginApp implements PluginInterface
     protected $configPath;
 
     /**
+     * The name of this plugin
+     *
+     * @var string
+     */
+    protected $name;
+
+    /**
      * Constructor
      *
      * @param array $options Options
@@ -85,7 +92,7 @@ class PluginApp implements PluginInterface
                 $this->{"{$key}Enabled"} = (bool)$options[$key];
             }
         }
-        foreach (['path', 'classPath', 'configPath'] as $path) {
+        foreach (['name', 'path', 'classPath', 'configPath'] as $path) {
             if (isset($options[$path])) {
                 $this->{$path} = $options[$path];
             }
@@ -106,10 +113,14 @@ class PluginApp implements PluginInterface
      */
     public function getName()
     {
+        if ($this->name) {
+            return $this->name;
+        }
         $parts = explode('\\', get_class($this));
         array_pop($parts);
+        $this->name = implode('/', $parts);
 
-        return implode('/', $parts);
+        return $this->name;
     }
 
     /**

+ 6 - 0
tests/TestCase/Core/PluginAppTest.php

@@ -63,6 +63,12 @@ class PluginAppTest extends TestCase
         $this->assertSame('Company/TestPluginThree', $plugin->getName());
     }
 
+    public function testGetNameOption()
+    {
+        $plugin = new TestPlugin(['name' => 'Elephants']);
+        $this->assertSame('Elephants', $plugin->getName());
+    }
+
     public function testMiddleware()
     {
         $plugin = new PluginApp();