|
|
@@ -16,9 +16,10 @@ namespace Cake\Http;
|
|
|
|
|
|
use Cake\Core\HttpApplicationInterface;
|
|
|
use Cake\Core\PluginApplicationInterface;
|
|
|
-use Cake\Event\EventApplicationInterface;
|
|
|
use Cake\Event\EventDispatcherInterface;
|
|
|
use Cake\Event\EventDispatcherTrait;
|
|
|
+use Cake\Event\EventManager;
|
|
|
+use InvalidArgumentException;
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
use RuntimeException;
|
|
|
@@ -30,7 +31,14 @@ use Zend\Diactoros\Response\EmitterInterface;
|
|
|
class Server implements EventDispatcherInterface
|
|
|
{
|
|
|
|
|
|
- use EventDispatcherTrait;
|
|
|
+ /**
|
|
|
+ * Alias methods away so we can implement proxying methods.
|
|
|
+ */
|
|
|
+ use EventDispatcherTrait {
|
|
|
+ eventManager as private _eventManager;
|
|
|
+ getEventManager as private _getEventManager;
|
|
|
+ setEventManager as private _setEventManager;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @var \Cake\Core\HttpApplicationInterface
|
|
|
@@ -49,7 +57,7 @@ class Server implements EventDispatcherInterface
|
|
|
*/
|
|
|
public function __construct(HttpApplicationInterface $app)
|
|
|
{
|
|
|
- $this->setApp($app);
|
|
|
+ $this->app = $app;
|
|
|
$this->setRunner(new Runner());
|
|
|
}
|
|
|
|
|
|
@@ -115,9 +123,10 @@ class Server implements EventDispatcherInterface
|
|
|
if ($this->app instanceof PluginApplicationInterface) {
|
|
|
$this->app->pluginBootstrap();
|
|
|
|
|
|
- $events = $this->app->events($this->getEventManager());
|
|
|
+ $events = $this->app->getEventManager();
|
|
|
+ $events = $this->app->events($events);
|
|
|
$events = $this->app->pluginEvents($events);
|
|
|
- $this->setEventManager($events);
|
|
|
+ $this->app->setEventManager($events);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -138,42 +147,76 @@ class Server implements EventDispatcherInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set the application.
|
|
|
+ * Get the current application.
|
|
|
+ *
|
|
|
+ * @return \Cake\Core\HttpApplicationInterface The application that will be run.
|
|
|
+ */
|
|
|
+ public function getApp()
|
|
|
+ {
|
|
|
+ return $this->app;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set the runner
|
|
|
*
|
|
|
- * @param \Cake\Core\HttpApplicationInterface $app The application to set.
|
|
|
+ * @param \Cake\Http\Runner $runner The runner to use.
|
|
|
* @return $this
|
|
|
*/
|
|
|
- public function setApp(HttpApplicationInterface $app)
|
|
|
+ public function setRunner(Runner $runner)
|
|
|
{
|
|
|
- $this->app = $app;
|
|
|
+ $this->runner = $runner;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
|
|
|
- if ($app instanceof EventDispatcherInterface) {
|
|
|
- $this->setEventManager($app->getEventManager());
|
|
|
+ /**
|
|
|
+ * Get the application's event manager or the global one.
|
|
|
+ *
|
|
|
+ * @return \Cake\Event\EventManagerInterface
|
|
|
+ */
|
|
|
+ public function getEventManager()
|
|
|
+ {
|
|
|
+ if ($this->app instanceof PluginApplicationInterface) {
|
|
|
+ return $this->app->getEventManager();
|
|
|
}
|
|
|
|
|
|
- return $this;
|
|
|
+ return EventManager::instance();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the current application.
|
|
|
+ * Get/set the application's event manager.
|
|
|
*
|
|
|
- * @return \Cake\Core\HttpApplicationInterface The application that will be run.
|
|
|
+ * If the application does not support events and this method is used as
|
|
|
+ * a setter, an exception will be raised.
|
|
|
+ *
|
|
|
+ * @param \Cake\Event\EventManagerInterface $events The event manager to set.
|
|
|
+ * @return \Cake\Event\EventManagerInterface|$this
|
|
|
+ * @deprecated Will be removed in 4.0
|
|
|
*/
|
|
|
- public function getApp()
|
|
|
+ public function eventManager(EventManager $events = null)
|
|
|
{
|
|
|
- return $this->app;
|
|
|
+ if ($eventManager === null) {
|
|
|
+ return $this->getEventManager();
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->setEventManager($events);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set the runner
|
|
|
+ * Get/set the application's event manager.
|
|
|
*
|
|
|
- * @param \Cake\Http\Runner $runner The runner to use.
|
|
|
+ * If the application does not support events and this method is used as
|
|
|
+ * a setter, an exception will be raised.
|
|
|
+ *
|
|
|
+ * @param \Cake\Event\EventManagerInterface $events The event manager to set.
|
|
|
* @return $this
|
|
|
*/
|
|
|
- public function setRunner(Runner $runner)
|
|
|
+ public function setEventManager(EventManager $events)
|
|
|
{
|
|
|
- $this->runner = $runner;
|
|
|
+ if ($this->app instanceof PluginApplicationInterface) {
|
|
|
+ return $this->app->setEventManager($events);
|
|
|
+ }
|
|
|
|
|
|
- return $this;
|
|
|
+ throw new InvalidArgumentException('Cannot set the event manager, the application does not support events.');
|
|
|
}
|
|
|
}
|