Skip to content

Commit

Permalink
Merge branch '1.x' of github.com:radarphp/Radar.Adr into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed May 18, 2015
2 parents 9d1fa8d + a335b62 commit 132bc23
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 39 deletions.
10 changes: 5 additions & 5 deletions src/Adr.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public function __call($method, $params)
return call_user_func_array([$this->map, $method], $params);
}

public function __invoke()
{
return call_user_func($this->dispatcher);
}

public function before($spec)
{
$this->middle->before($spec);
Expand Down Expand Up @@ -74,4 +69,9 @@ public function sendingHandler($spec)
{
$this->dispatcher->sendingHandler($spec);
}

public function run()
{
return $this->dispatcher->run();
}
}
2 changes: 1 addition & 1 deletion src/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct($envPath)
$this->envPath = $envPath;
}

public function __invoke(array $config = [])
public function adr(array $config = [])
{
$loader = new Loader($this->envPath);
$loader->parse();
Expand Down
25 changes: 8 additions & 17 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __get($key)
return $this->$key;
}

public function __invoke()
public function run()
{
try {
$this->inbound();
Expand Down Expand Up @@ -71,22 +71,18 @@ public function sendingHandler($spec)

protected function inbound()
{
$middle = $this->middle;

$early = $middle($this->request, $this->response, 'before');
$early = $this->middle->run($this->request, $this->response, 'before');
if ($early) {
return;
}

$this->response = $this->action($this->route());
$middle($this->request, $this->response, 'after');
$this->middle->run($this->request, $this->response, 'after');
}

protected function route()
{
$factory = $this->factory;

$routingHandler = $factory($this->routingHandler);
$routingHandler = $this->factory->invokable($this->routingHandler);
$route = $routingHandler($this->request);
foreach ($route->attributes as $key => $val) {
$this->request = $this->request->withAttribute($key, $val);
Expand All @@ -96,26 +92,21 @@ protected function route()

protected function action(Route $route)
{
$factory = $this->factory;
$actionHandler = $factory($this->actionHandler);
$actionHandler = $this->factory->invokable($this->actionHandler);
return $actionHandler($this->request, $this->response, $route);
}

protected function outbound()
{
$factory = $this->factory;
$sendingHandler = $factory($this->sendingHandler);
$sendingHandler = $this->factory->invokable($this->sendingHandler);
$sendingHandler($this->response);

$middle = $this->middle;
$middle($this->request, $this->response, 'finish');
$this->middle->run($this->request, $this->response, 'finish');
}


protected function exception(Exception $exception)
{
$factory = $this->factory;
$exceptionHandler = $factory($this->exceptionHandler);
$exceptionHandler = $this->factory->invokable($this->exceptionHandler);
$this->response = $exceptionHandler(
$this->request,
$this->response,
Expand Down
2 changes: 1 addition & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(InjectionFactory $injectionFactory)
$this->injectionFactory = $injectionFactory;
}

public function __invoke($spec)
public function invokable($spec)
{
if (is_string($spec)) {
return $this->injectionFactory->newInstance($spec);
Expand Down
8 changes: 3 additions & 5 deletions src/Handler/ActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public function __invoke(
ResponseInterface $response,
Route $route
) {
$factory = $this->factory;
$responder = $factory($route->responder);
$responder = $this->factory->invokable($route->responder);

if ($route->domain) {
$payload = $this->domain($route, $request);
Expand All @@ -33,12 +32,11 @@ public function __invoke(

protected function domain(Route $route, ServerRequestInterface $request)
{
$factory = $this->factory;
$domain = $factory($route->domain);
$domain = $this->factory->invokable($route->domain);

$input = [];
if ($route->input) {
$input = $factory($route->input);
$input = $this->factory->invokable($route->input);
$input = (array) $input($request);
return call_user_func_array($domain, $input);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/SendingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __invoke(ResponseInterface $response)
$this->sendBody($response);
}

protected function sendStatus($response)
protected function sendStatus(ResponseInterface $response)
{
$version = $response->getProtocolVersion();
$status = $response->getStatusCode();
Expand Down
5 changes: 2 additions & 3 deletions src/Middle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ public function __construct(Factory $factory)
$this->factory = $factory;
}

public function __invoke(
public function run(
ServerRequestInterface &$request,
ResponseInterface &$response,
$key
) {
$factory = $this->factory;
ksort($this->$key);
foreach ($this->$key as $priority => $classes) {
foreach ($classes as $class) {
$object = $factory($class);
$object = $this->factory->invokable($class);
$early = $object($request, $response);
if ($early instanceof ResponseInterface) {
$response = $early;
Expand Down
6 changes: 3 additions & 3 deletions tests/AdrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public function testGetDispatcherParams()
$this->assertSame($expect, $this->fakeMiddle->finish);
}

public function testInvoke()
public function testRun()
{
$expect = 'Radar\Adr\Fake\FakeDispatcher::__invoke';
$actual = $this->adr->__invoke();
$expect = 'Radar\Adr\Fake\FakeDispatcher::run';
$actual = $this->adr->run();
$this->assertSame($expect, $actual);
}
}
4 changes: 2 additions & 2 deletions tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ protected function newAdr(array $server = [])
FakeWare::$count = 0;
$_SERVER = array_merge($_SERVER, $server);
$boot = new Boot(__DIR__ . DIRECTORY_SEPARATOR . '_env');
return $boot();
return $boot->adr();
}

protected function assertOutput($adr, $expectHeaders, $expectBody)
{
ob_start();
$adr();
$adr->run();
$actualBody = ob_get_clean();
$this->assertEquals($expectBody, $actualBody);
$this->assertEquals($expectHeaders, FakePhp::$headers);
Expand Down
2 changes: 1 addition & 1 deletion tests/Fake/FakeDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function __construct(FakeMiddle $middle)
$this->middle = $middle;
}

public function __invoke() {
public function run() {
return __METHOD__;
}
}

0 comments on commit 132bc23

Please sign in to comment.