Skip to content

Commit

Permalink
Improved coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed Mar 9, 2016
1 parent 45609c6 commit 0607d7f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Starter.php
Expand Up @@ -54,20 +54,14 @@ public function __construct(
Http\Response $response,
Http\Request $httpRequest
) {
if (!($router instanceof RouteList)) {
return;
}

$this->generator = $generator;
$this->router = $router;

$this->response = $response;
$this->httpRequest = $httpRequest;

foreach ($router as $route) {
if ($route instanceof ApiRoute) {
$route->onMatch[] = [$this, 'routeMatched'];
}
if ($router instanceof RouteList) {
$this->attachEvents();
}
}

Expand All @@ -93,4 +87,18 @@ public function routeMatched(ApiRoute $route, Request $request)
}
}


/**
* Find ApiRoutes and add listener to each ApiRoute::onMatch event
* @return void
*/
protected function attachEvents()
{
foreach ($this->router as $route) {
if ($route instanceof ApiRoute) {
$route->onMatch[] = [$this, 'routeMatched'];
}
}
}

}

0 comments on commit 0607d7f

Please sign in to comment.