diff --git a/src/Core/PluginApp.php b/src/Core/PluginApp.php index b66687efd2a..68ebd6fd288 100644 --- a/src/Core/PluginApp.php +++ b/src/Core/PluginApp.php @@ -1,15 +1,58 @@ disableBootstrap((bool)$options['bootstrap']); + } + if (isset($options['routes'])) { + $this->disableRoutes((bool)$options['routes']); + } + $this->initialize(); } @@ -21,6 +64,38 @@ public function initialize() } + /** + * {@inheritdoc} + */ + public function disableRoutes($disabled) + { + $this->loadRoutes = $disabled; + } + + /** + * {@inheritdoc} + */ + public function disableBootstrap($disabled) + { + $this->doBootstrap = $disabled; + } + + /** + * {@inheritdoc} + */ + public function isRouteLoadingEnabled() + { + return $this->loadRoutes; + } + + /** + * {@inheritdoc} + */ + public function isBootstrapEnabled() + { + return $this->doBootstrap; + } + /** * {@inheritdoc} */ @@ -60,12 +135,7 @@ public function middleware($middleware) } /** - * Invoke the application. - * - * @param \Psr\Http\Message\ServerRequestInterface $request The request - * @param \Psr\Http\Message\ResponseInterface $response The response - * @param callable $next The next middleware - * @return \Psr\Http\Message\ResponseInterface + * {@inheritdoc} */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { diff --git a/src/Core/PluginInterface.php b/src/Core/PluginInterface.php new file mode 100644 index 00000000000..9f940ab2465 --- /dev/null +++ b/src/Core/PluginInterface.php @@ -0,0 +1,51 @@ +bootstrap(); + if ($plugin->isBootstrapEnabled()) { + $plugin->bootstrap(); + } } } @@ -110,7 +130,9 @@ public function console($commands) public function routes($routes) { foreach ($this as $plugin) { - $plugin->middleware($routes); + if ($plugin->isRouteLoadingEnabled()) { + $plugin->routes($routes); + } } } diff --git a/tests/TestCase/Core/PluginAppTest.php b/tests/TestCase/Core/PluginAppTest.php index ab1f7bc6f15..1462a45db61 100644 --- a/tests/TestCase/Core/PluginAppTest.php +++ b/tests/TestCase/Core/PluginAppTest.php @@ -13,10 +13,9 @@ */ namespace Cake\Test\TestCase\Core; -use Cake\Core\App; use Cake\Core\Plugin; +use Cake\Core\PluginApp; use Cake\TestSuite\TestCase; -use TestApp\Core\TestApp; /** * AppTest class @@ -29,8 +28,25 @@ class PluginAppTest extends TestCase * * @return void */ - public function tearDown() { + public function tearDown() + { parent::tearDown(); Plugin::unload(); } + + /** + * testConfigForRoutesAndBootstrap + * + * @return void + */ + public function testConfigForRoutesAndBootstrap() + { + $plugin = new PluginApp([ + 'bootstrap' => false, + 'routes' => false + ]); + + $this->assertFalse($plugin->isBootstrapEnabled()); + $this->assertFalse($plugin->isRouteLoadingEnabled()); + } } diff --git a/tests/TestCase/Core/PluginRegistryTest.php b/tests/TestCase/Core/PluginRegistryTest.php index 070f8e42213..cbd474d8614 100644 --- a/tests/TestCase/Core/PluginRegistryTest.php +++ b/tests/TestCase/Core/PluginRegistryTest.php @@ -42,4 +42,27 @@ public function testRegistry() $result = $registry->loaded(); $this->assertEquals(['TestPlugin'], $result); } + + public function testDotSyntax() + { + /* + $registry = new PluginRegistry(); + //$result = $registry->load('TestPlugin'); + //$this->assertInstanceOf(TestPlugin::class, $result); + + $result = $registry->load('Company\TestPluginFive'); + //$this->assertInstanceOf(TestPlugin::class, $result); + debug($result); + */ + } + + /** + * @expectedException \Error + * @expectedExceptionMessage Class 'DoesNotExist\Plugin' not found + */ + public function testClassNotFoundException() + { + $registry = new PluginRegistry(); + $registry->load('DoesNotExist'); + } } diff --git a/tests/test_app/Plugin/Company/TestPluginFive/src/Plugin.php b/tests/test_app/Plugin/Company/TestPluginFive/src/Plugin.php index b240045999c..302bc8c6262 100644 --- a/tests/test_app/Plugin/Company/TestPluginFive/src/Plugin.php +++ b/tests/test_app/Plugin/Company/TestPluginFive/src/Plugin.php @@ -11,7 +11,7 @@ * @since 3.6.0 * @license https://opensource.org/licenses/mit-license.php MIT License */ -namespace TestPlugin; +namespace Company\TestPluginFive; use Cake\Core\PluginApp;