Browse Source

Add class & config path.

These are also required by the current Plugin system. And are
requirements to get parity.
mark_story 8 years ago
parent
commit
d3844d444f
3 changed files with 70 additions and 5 deletions
  1. 46 3
      src/Core/PluginApp.php
  2. 14 0
      src/Core/PluginInterface.php
  3. 10 2
      tests/TestCase/Core/PluginAppTest.php

+ 46 - 3
src/Core/PluginApp.php

@@ -60,6 +60,20 @@ class PluginApp implements PluginInterface
     protected $path;
 
     /**
+     * The class path for this plugin.
+     *
+     * @var string
+     */
+    protected $classPath;
+
+    /**
+     * The config path for this plugin.
+     *
+     * @var string
+     */
+    protected $configPath;
+
+    /**
      * Constructor
      *
      * @param array $options Options
@@ -71,8 +85,10 @@ class PluginApp implements PluginInterface
                 $this->{"{$key}Enabled"} = (bool)$options[$key];
             }
         }
-        if (isset($options['path'])) {
-            $this->path = $options['path'];
+        foreach (['path', 'classPath', 'configPath'] as $path) {
+            if (isset($options[$path])) {
+                $this->{$path} = $options[$path];
+            }
         }
 
         $this->initialize();
@@ -111,8 +127,35 @@ class PluginApp implements PluginInterface
         if (substr($path, -3) === 'src') {
             $path = substr($path, 0, -3);
         }
+        $this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
+
+        return $this->path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getConfigPath()
+    {
+        if ($this->configPath) {
+            return $this->configPath;
+        }
+        $path = $this->getPath();
+
+        return $path . 'config' . DIRECTORY_SEPARATOR;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function getClassPath()
+    {
+        if ($this->classPath) {
+            return $this->classPath;
+        }
+        $path = $this->getPath();
 
-        return rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
+        return $path . 'src' . DIRECTORY_SEPARATOR;
     }
 
     /**

+ 14 - 0
src/Core/PluginInterface.php

@@ -33,6 +33,20 @@ interface PluginInterface
     public function getPath();
 
     /**
+     * Get the filesystem path to configuration for this plugin
+     *
+     * @return void
+     */
+    public function getConfigPath();
+
+    /**
+     * Get the filesystem path to configuration for this plugin
+     *
+     * @return void
+     */
+    public function getClassPath();
+
+    /**
      * Load all the application configuration and bootstrap logic.
      *
      * Override this method to add additional bootstrap logic for your application.

+ 10 - 2
tests/TestCase/Core/PluginAppTest.php

@@ -97,17 +97,25 @@ class PluginAppTest extends TestCase
 
         $expected = CAKE . 'Core' . DS;
         $this->assertSame($expected, $plugin->getPath());
+        $this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
+        $this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
     }
 
     public function testGetPathOptionValue()
     {
         $plugin = new PluginApp(['path' => '/some/path']);
-        $this->assertSame('/some/path', $plugin->getPath());
+        $expected = '/some/path';
+        $this->assertSame($expected, $plugin->getPath());
+        $this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
+        $this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
     }
 
     public function testGetPathSubclass()
     {
         $plugin = new TestPlugin();
-        $this->assertSame(TEST_APP . 'Plugin/TestPlugin' . DS, $plugin->getPath());
+        $expected = TEST_APP . 'Plugin/TestPlugin' . DS;
+        $this->assertSame($expected, $plugin->getPath());
+        $this->assertSame($expected . 'config' . DS, $plugin->getConfigPath());
+        $this->assertSame($expected . 'src' . DS, $plugin->getClassPath());
     }
 }