Skip to content

Commit 955885a

Browse files
committed
Add an interface for the Application.
I wasn't too happy about the coupling between Console and Http, and this new interface lets us not have that. Instead Http and Console will depend on Core (which they already do). I contemplated adding a ConsoleApplication and HttpApplication interface as well, but thought that might be a bit much.
1 parent 3a52dfc commit 955885a

File tree

4 files changed

+71
-17
lines changed

4 files changed

+71
-17
lines changed

src/Console/CommandRunner.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Cake\Console\Exception\StopException;
2121
use Cake\Console\Shell;
2222
use Cake\Event\EventManagerTrait;
23-
use Cake\Http\BaseApplication;
23+
use Cake\Core\ApplicationInterface;
2424
use Cake\Shell\HelpShell;
2525
use Cake\Shell\VersionShell;
2626
use RuntimeException;
@@ -35,7 +35,7 @@ class CommandRunner
3535
/**
3636
* The application console commands are being run for.
3737
*
38-
* @var \Cake\Http\BaseApplication
38+
* @var \Cake\Core\ApplicationInterface
3939
*/
4040
protected $app;
4141

@@ -56,10 +56,10 @@ class CommandRunner
5656
/**
5757
* Constructor
5858
*
59-
* @param \Cake\Http\BaseApplication $app The application to run CLI commands for.
59+
* @param \Cake\Core\ApplicationInterface $app The application to run CLI commands for.
6060
* @param string $root The root command name to be removed from argv.
6161
*/
62-
public function __construct(BaseApplication $app, $root = 'cake')
62+
public function __construct(ApplicationInterface $app, $root = 'cake')
6363
{
6464
$this->app = $app;
6565
$this->root = $root;

src/Core/ApplicationInterface.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4+
* Copyright 2005-2011, Cake Software Foundation, Inc. (https://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* Redistributions of files must retain the above copyright notice.
8+
*
9+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
10+
* @link https://cakephp.org CakePHP(tm) Project
11+
* @since 3.5.0
12+
* @license https://opensource.org/licenses/mit-license.php MIT License
13+
*/
14+
namespace Cake\Core;
15+
16+
/**
17+
* An interface defining the methods that the
18+
* console runner/http server depend on.
19+
*/
20+
interface ApplicationInterface
21+
{
22+
/**
23+
* Load all the application configuration and bootstrap logic.
24+
*
25+
* Override this method to add additional bootstrap logic for your application.
26+
*
27+
* @return void
28+
*/
29+
public function bootstrap();
30+
31+
/**
32+
* Define the routes for an application.
33+
*
34+
* Use the provided RouteBuilder to define an application's routing.
35+
*
36+
* @param \Cake\Routing\RouteBuilder $routes A route builder to add routes into.
37+
* @return void
38+
*/
39+
public function routes($routes);
40+
41+
/**
42+
* Define the console commands for an application.
43+
*
44+
* @param \Cake\Console\CommandCollection $commands The CommandCollection to add commands into.
45+
* @return \Cake\Console\CommandCollection The updated collection.
46+
*/
47+
public function console($commands);
48+
49+
/**
50+
* Define the HTTP middleware layers for an application.
51+
*
52+
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to set in your App Class
53+
* @return \Cake\Http\MiddlewareQueue
54+
*/
55+
public function middleware($middleware);
56+
}

src/Http/BaseApplication.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
namespace Cake\Http;
1616

17+
use Cake\Core\ApplicationInterface;
1718
use Cake\Routing\DispatcherFactory;
1819
use Psr\Http\Message\ResponseInterface;
1920
use Psr\Http\Message\ServerRequestInterface;
@@ -25,7 +26,7 @@
2526
* and ensuring that middleware is attached. It is also invoked as the last piece
2627
* of middleware, and delegates request/response handling to the correct controller.
2728
*/
28-
abstract class BaseApplication
29+
abstract class BaseApplication implements ApplicationInterface
2930
{
3031

3132
/**
@@ -50,19 +51,15 @@ public function __construct($configDir)
5051
abstract public function middleware($middleware);
5152

5253
/**
53-
* Load all the application configuration and bootstrap logic.
54-
*
55-
* Override this method to add additional bootstrap logic for your application.
56-
*
57-
* @return void
54+
* {@inheritDoc}
5855
*/
5956
public function bootstrap()
6057
{
6158
require_once $this->configDir . '/bootstrap.php';
6259
}
6360

6461
/**
65-
* Define the routes for an application.
62+
* {@inheritDoc}
6663
*
6764
* By default this will load `config/routes.php` for ease of use and backwards compatibility.
6865
*

src/Http/Server.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
namespace Cake\Http;
1616

17+
use Cake\Core\ApplicationInterface;
1718
use Cake\Event\EventDispatcherTrait;
1819
use Psr\Http\Message\ResponseInterface;
1920
use Psr\Http\Message\ServerRequestInterface;
@@ -29,7 +30,7 @@ class Server
2930
use EventDispatcherTrait;
3031

3132
/**
32-
* @var \Cake\Http\BaseApplication
33+
* @var \Cake\Core\ApplicationInterface
3334
*/
3435
protected $app;
3536

@@ -41,9 +42,9 @@ class Server
4142
/**
4243
* Constructor
4344
*
44-
* @param \Cake\Http\BaseApplication $app The application to use.
45+
* @param \Cake\Core\ApplicationInterface $app The application to use.
4546
*/
46-
public function __construct(BaseApplication $app)
47+
public function __construct(ApplicationInterface $app)
4748
{
4849
$this->setApp($app);
4950
$this->setRunner(new Runner());
@@ -108,10 +109,10 @@ public function emit(ResponseInterface $response, EmitterInterface $emitter = nu
108109
/**
109110
* Set the application.
110111
*
111-
* @param BaseApplication $app The application to set.
112+
* @param Cake\Core\ApplicationInterface $app The application to set.
112113
* @return $this
113114
*/
114-
public function setApp(BaseApplication $app)
115+
public function setApp(ApplicationInterface $app)
115116
{
116117
$this->app = $app;
117118

@@ -121,7 +122,7 @@ public function setApp(BaseApplication $app)
121122
/**
122123
* Get the current application.
123124
*
124-
* @return \Cake\Http\BaseApplication The application that will be run.
125+
* @return \Cake\Core\ApplicationInterface The application that will be run.
125126
*/
126127
public function getApp()
127128
{

0 commit comments

Comments
 (0)