Skip to content

Commit d3f8b55

Browse files
committed
Add names to plugins & remove middleware interfaces.
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.
1 parent 22b4ca7 commit d3f8b55

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/Core/PluginApp.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
*/
1414
namespace Cake\Core;
1515

16-
use Psr\Http\Message\ResponseInterface;
17-
use Psr\Http\Message\ServerRequestInterface;
18-
1916
/**
2017
* Base Plugin Class
2118
*
2219
* Every plugin should extends from this class or implement the interfaces and
2320
* include a plugin class in it's src root folder.
2421
*/
25-
class PluginApp implements ConsoleApplicationInterface, HttpApplicationInterface, PluginInterface
22+
class PluginApp implements PluginInterface
2623
{
2724

2825
/**
@@ -198,12 +195,4 @@ public function middleware($middleware)
198195
{
199196
return $middleware;
200197
}
201-
202-
/**
203-
* {@inheritdoc}
204-
*/
205-
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
206-
{
207-
return $next($request, $response);
208-
}
209198
}

tests/TestCase/Core/PluginAppTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
*/
1414
namespace Cake\Test\TestCase\Core;
1515

16+
use Cake\Console\CommandCollection;
1617
use Cake\Core\Plugin;
1718
use Cake\Core\PluginApp;
19+
use Cake\Http\MiddlewareQueue;
1820
use Cake\TestSuite\TestCase;
21+
use Company\TestPluginThree\Plugin as TestPluginThree;
22+
use TestPlugin\Plugin as TestPlugin;
1923

2024
/**
21-
* AppTest class
25+
* PluginAppTest class
2226
*/
2327
class PluginAppTest extends TestCase
2428
{
@@ -47,6 +51,29 @@ public function testConfigForRoutesAndBootstrap()
4751
]);
4852

4953
$this->assertFalse($plugin->isBootstrapEnabled());
50-
$this->assertFalse($plugin->isRouteLoadingEnabled());
54+
$this->assertFalse($plugin->isRoutesEnabled());
55+
}
56+
57+
public function testGetName()
58+
{
59+
$plugin = new TestPlugin();
60+
$this->assertSame('TestPlugin', $plugin->getName());
61+
62+
$plugin = new TestPluginThree();
63+
$this->assertSame('Company/TestPluginThree', $plugin->getName());
64+
}
65+
66+
public function testMiddleware()
67+
{
68+
$plugin = new PluginApp();
69+
$middleware = new MiddlewareQueue();
70+
$this->assertSame($middleware, $plugin->middleware($middleware));
71+
}
72+
73+
public function testConsole()
74+
{
75+
$plugin = new PluginApp();
76+
$commands = new CommandCollection();
77+
$this->assertSame($commands, $plugin->console($commands));
5178
}
5279
}

0 commit comments

Comments
 (0)