Skip to content

Commit

Permalink
Run events hook after bootstrap both in CLI and web.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Feb 12, 2018
1 parent 970ea1e commit d465251
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 81 deletions.
22 changes: 17 additions & 5 deletions src/Console/CommandRunner.php
Expand Up @@ -117,11 +117,7 @@ public function setAliases(array $aliases)
*/
public function run(array $argv, ConsoleIo $io = null)
{
$this->app->bootstrap();
if ($this->app instanceof EventApplicationInterface) {
$eventManager = $this->app->events($this->getEventManager());
$this->setEventManager($eventManager);
}
$this->bootstrap();

$commands = new CommandCollection([
'version' => VersionCommand::class,
Expand Down Expand Up @@ -165,6 +161,22 @@ public function run(array $argv, ConsoleIo $io = null)
return Shell::CODE_ERROR;
}

/**
* Application bootstrap wrapper.
*
* Calls `bootstrap()` and `events()` if application implements `EventApplicationInterface`.
*
* @return void
*/
protected function bootstrap()
{
$this->app->bootstrap();
if ($this->app instanceof EventApplicationInterface) {
$eventManager = $this->app->events($this->getEventManager());
$this->setEventManager($eventManager);
}
}

/**
* Get the shell instance for a given command name
*
Expand Down
74 changes: 0 additions & 74 deletions src/Event/Middleware/EventMiddleware.php

This file was deleted.

23 changes: 21 additions & 2 deletions src/Http/Server.php
Expand Up @@ -15,6 +15,8 @@
namespace Cake\Http;

use Cake\Core\HttpApplicationInterface;
use Cake\Event\EventApplicationInterface;
use Cake\Event\EventDispatcherInterface;
use Cake\Event\EventDispatcherTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -24,7 +26,7 @@
/**
* Runs an application invoking all the PSR7 middleware and the registered application.
*/
class Server
class Server implements EventDispatcherInterface
{

use EventDispatcherTrait;
Expand Down Expand Up @@ -68,7 +70,8 @@ public function __construct(HttpApplicationInterface $app)
*/
public function run(ServerRequestInterface $request = null, ResponseInterface $response = null)
{
$this->app->bootstrap();
$this->bootstrap();

$response = $response ?: new Response();
$request = $request ?: ServerRequestFactory::fromGlobals();

Expand All @@ -90,6 +93,22 @@ public function run(ServerRequestInterface $request = null, ResponseInterface $r
return $response;
}

/**
* Application bootstrap wrapper.
*
* Calls `bootstrap()` and `events()` if application implements `EventApplicationInterface`.
*
* @return void
*/
protected function bootstrap()
{
$this->app->bootstrap();
if ($this->app instanceof EventApplicationInterface) {
$eventManager = $this->app->events($this->getEventManager());
$this->setEventManager($eventManager);
}
}

/**
* Emit the response using the PHP SAPI.
*
Expand Down

0 comments on commit d465251

Please sign in to comment.