Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Drop run() and response emitter from application
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerkus committed Feb 8, 2018
1 parent 6ccf60c commit 99a2bf1
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 258 deletions.
50 changes: 0 additions & 50 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

namespace Zend\Mvc;

use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface;
use UnexpectedValueException;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Diactoros\ServerRequestFactory;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
Expand Down Expand Up @@ -98,11 +94,6 @@ class Application implements
*/
protected $container;

/**
* @var EmitterInterface
*/
private $emitter;

/**
* @var RouteStackInterface
*/
Expand All @@ -121,22 +112,18 @@ class Application implements
* @param ContainerInterface $container IoC container from which to pull services
* @param RouteStackInterface $router Configured router for RouteListener
* @param EventManagerInterface $events
* @param EmitterInterface $emitter Response emitter to use when `run()`
* is invoked
* @param array $listeners Extra listeners to attach on bootstrap
* Can be container keys or instances of ListenerAggregateInterface
*/
public function __construct(
ContainerInterface $container,
RouteStackInterface $router,
EventManagerInterface $events,
EmitterInterface $emitter,
array $listeners = []
) {
$this->container = $container;
$this->router = $router;
$this->setEventManager($events);
$this->emitter = $emitter;
$this->listeners = $listeners;

// @TODO response prototype?
Expand Down Expand Up @@ -236,38 +223,6 @@ public function getEventManager() : EventManagerInterface
return $this->events;
}

/**
* Run the application
*
* @triggers route(MvcEvent)
* Routes the request, and sets the RouteMatch object in the event.
* @triggers dispatch(MvcEvent)
* Dispatches a request, using the discovered RouteMatch and
* provided request.
* @triggers dispatch.error(MvcEvent)
* On errors (controller not found, action not supported, etc.),
* populates the event with information about the error type,
* discovered controller, and controller class (if known).
* Typically, a handler should return a populated Response object
* that can be returned immediately.
* @param Request|null $request
* @return void
*/
public function run(Request $request = null) : void
{
try {
$request = $request ?: ServerRequestFactory::fromGlobals();
} catch (InvalidArgumentException | UnexpectedValueException $e) {
// emit bad request
throw new \Exception('Not implemented');
}

$response = $this->handle($request);

$emitter = $this->getEmitter();
$emitter->emit($response);
}

public function handle(Request $request) : ResponseInterface
{
if (! $this->bootstrapped) {
Expand Down Expand Up @@ -328,11 +283,6 @@ public function handle(Request $request) : ResponseInterface
return $this->completeRequest($event);
}

public function getEmitter() : EmitterInterface
{
return $this->emitter;
}

/**
* Complete the request
*
Expand Down
9 changes: 0 additions & 9 deletions src/ApplicationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\Mvc;

use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\EventManager\EventsCapableInterface;

Expand All @@ -22,12 +21,4 @@ interface ApplicationInterface extends EventsCapableInterface, RequestHandlerInt
* @return ContainerInterface
*/
public function getContainer() : ContainerInterface;

/**
* Run the application
*
* @param ServerRequestInterface|null $request
* @return void
*/
public function run(ServerRequestInterface $request = null) : void;
}
11 changes: 0 additions & 11 deletions src/Container/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
namespace Zend\Mvc\Container;

use Psr\Container\ContainerInterface;
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Mvc\Application;
use Zend\Mvc\Emitter\EmitterStack;

class ApplicationFactory
{
Expand All @@ -29,21 +26,13 @@ class ApplicationFactory
*/
public function __invoke(ContainerInterface $container, string $name, array $options = null) : Application
{
if ($container->has(EmitterInterface::class)) {
$emitter = $container->get(EmitterInterface::class);
} else {
$emitter = new EmitterStack();
$emitter->push(new SapiEmitter());
}

$config = $container->get('config') ?? [];
$listeners = $config[Application::class]['listeners'] ?? [];

$application = new Application(
$container,
$container->get('Zend\Mvc\Router'),
$container->get('EventManager'),
$emitter,
$listeners
);

Expand Down
107 changes: 0 additions & 107 deletions src/Emitter/EmitterStack.php

This file was deleted.

5 changes: 0 additions & 5 deletions test/Application/BadControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace ZendTest\Mvc\Application;

use Zend\Diactoros\Response\EmitterInterface;
use Zend\Mvc\Application;
use Zend\Mvc\Controller\ControllerManager;
use Zend\Mvc\View\Http\ViewManager;
Expand All @@ -32,10 +31,6 @@ public function prepareApplication()
},
]]);
},
EmitterInterface::class => function () {
$emitter = $this->prophesize(EmitterInterface::class);
return $emitter->reveal();
},
],
'invokables' => [
ViewManager::class => TestAsset\MockViewManager::class,
Expand Down
5 changes: 0 additions & 5 deletions test/Application/InvalidControllerTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace ZendTest\Mvc\Application;

use stdClass;
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Mvc\Application;
use Zend\Mvc\Controller\ControllerManager;
use Zend\Mvc\View\Http\ViewManager;
Expand All @@ -32,10 +31,6 @@ public function prepareApplication()
},
]]);
},
EmitterInterface::class => function () {
$emitter = $this->prophesize(EmitterInterface::class);
return $emitter->reveal();
},
],
'invokables' => [
ViewManager::class => TestAsset\MockViewManager::class,
Expand Down
5 changes: 0 additions & 5 deletions test/Application/MissingControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace ZendTest\Mvc\Application;

use Zend\Diactoros\Response\EmitterInterface;
use Zend\Mvc\Application;
use Zend\Mvc\View\Http\ViewManager;
use Zend\Router;
Expand All @@ -23,10 +22,6 @@ public function prepareApplication()
$config = ApplicationConfigHelper::getConfig([
'dependencies' => [
'factories' => [
EmitterInterface::class => function () {
$emitter = $this->prophesize(EmitterInterface::class);
return $emitter->reveal();
},
],
'invokables' => [
ViewManager::class => TestAsset\MockViewManager::class,
Expand Down
5 changes: 0 additions & 5 deletions test/Application/PathControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace ZendTest\Mvc\Application;

use Zend\Diactoros\Response\EmitterInterface;
use Zend\Mvc\Application;
use Zend\Mvc\Controller\ControllerManager;
use Zend\Mvc\View\Http\ViewManager;
Expand All @@ -31,10 +30,6 @@ public function prepareApplication()
},
]]);
},
EmitterInterface::class => function () {
$emitter = $this->prophesize(EmitterInterface::class);
return $emitter->reveal();
},
],
'invokables' => [
ViewManager::class => TestAsset\MockViewManager::class,
Expand Down
Loading

0 comments on commit 99a2bf1

Please sign in to comment.