Skip to content

Commit

Permalink
Add names to plugins & remove middleware interfaces.
Browse files Browse the repository at this point in the history
Plugins do not have to implement the Application interfaces as they are
hook based plugins and not the same as applications.

While they could be the same, it doesn't make sense for plugins to add
themselves as a middleware layer when they have a middleware hook. The
Application adds itself as a middleware to ensure there is an 'end' to
the middleware queue and ensure that a response is always generated.
  • Loading branch information
markstory committed Feb 13, 2018
1 parent 22b4ca7 commit d3f8b55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
13 changes: 1 addition & 12 deletions src/Core/PluginApp.php
Expand Up @@ -13,16 +13,13 @@
*/
namespace Cake\Core;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

/**
* Base Plugin Class
*
* Every plugin should extends from this class or implement the interfaces and
* include a plugin class in it's src root folder.
*/
class PluginApp implements ConsoleApplicationInterface, HttpApplicationInterface, PluginInterface
class PluginApp implements PluginInterface
{

/**
Expand Down Expand Up @@ -198,12 +195,4 @@ public function middleware($middleware)
{
return $middleware;
}

/**
* {@inheritdoc}
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
{
return $next($request, $response);
}
}
31 changes: 29 additions & 2 deletions tests/TestCase/Core/PluginAppTest.php
Expand Up @@ -13,12 +13,16 @@
*/
namespace Cake\Test\TestCase\Core;

use Cake\Console\CommandCollection;
use Cake\Core\Plugin;
use Cake\Core\PluginApp;
use Cake\Http\MiddlewareQueue;
use Cake\TestSuite\TestCase;
use Company\TestPluginThree\Plugin as TestPluginThree;
use TestPlugin\Plugin as TestPlugin;

/**
* AppTest class
* PluginAppTest class
*/
class PluginAppTest extends TestCase
{
Expand Down Expand Up @@ -47,6 +51,29 @@ public function testConfigForRoutesAndBootstrap()
]);

$this->assertFalse($plugin->isBootstrapEnabled());
$this->assertFalse($plugin->isRouteLoadingEnabled());
$this->assertFalse($plugin->isRoutesEnabled());
}

public function testGetName()
{
$plugin = new TestPlugin();
$this->assertSame('TestPlugin', $plugin->getName());

$plugin = new TestPluginThree();
$this->assertSame('Company/TestPluginThree', $plugin->getName());
}

public function testMiddleware()
{
$plugin = new PluginApp();
$middleware = new MiddlewareQueue();
$this->assertSame($middleware, $plugin->middleware($middleware));
}

public function testConsole()
{
$plugin = new PluginApp();
$commands = new CommandCollection();
$this->assertSame($commands, $plugin->console($commands));
}
}

0 comments on commit d3f8b55

Please sign in to comment.