Browse Source

Merge pull request #11785 from cakephp/plugin-bootstrap

Fix duplicate plugin bootstrapping.
Mark Story 8 years ago
parent
commit
e0da2a64e9
3 changed files with 19 additions and 8 deletions
  1. 0 7
      src/Core/BasePlugin.php
  2. 4 1
      src/Core/Plugin.php
  3. 15 0
      tests/TestCase/Core/PluginTest.php

+ 0 - 7
src/Core/BasePlugin.php

@@ -34,13 +34,6 @@ class BasePlugin implements PluginInterface
     protected $bootstrapEnabled = true;
 
     /**
-     * Are events enabled.
-     *
-     * @var bool
-     */
-    protected $eventsEnabled = true;
-
-    /**
      * Load routes or not
      *
      * @var bool

+ 4 - 1
src/Core/Plugin.php

@@ -173,7 +173,10 @@ class Plugin
             );
         }
 
-        if ($config['bootstrap'] === true) {
+        // Defer the bootstrap process if an Application class exists.
+        // Immediate plugin bootstrapping is deprecated and will be removed in 4.x
+        $appClass = Configure::read('App.namespace') . '\\' . 'Application';
+        if ($config['bootstrap'] === true && !class_exists($appClass)) {
             static::bootstrap($plugin);
         }
     }

+ 15 - 0
tests/TestCase/Core/PluginTest.php

@@ -111,6 +111,7 @@ class PluginTest extends TestCase
     /**
      * Tests loading a plugin and its bootstrap file
      *
+     * @deprecated Immediate plugin bootstrap should be removed in 4.x
      * @return void
      */
     public function testLoadSingleWithBootstrap()
@@ -125,6 +126,20 @@ class PluginTest extends TestCase
     }
 
     /**
+     * Tests loading a plugin defers bootstrap when an application exists
+     *
+     * @return void
+     */
+    public function testLoadSingleDeferBootstrap()
+    {
+        static::setAppNamespace('TestApp');
+
+        Plugin::load('TestPlugin', ['bootstrap' => true]);
+        $this->assertTrue(Plugin::loaded('TestPlugin'));
+        $this->assertNull(Configure::read('PluginTest.test_plugin.bootstrap'), 'Normally this value would be loaded');
+    }
+
+    /**
      * Tests loading a plugin with bootstrap file and routes file
      *
      * @return void