Skip to content

Commit

Permalink
Merge pull request #11 from samsonasik/update-composer
Browse files Browse the repository at this point in the history
Upgrade to Penny 0.7.0
  • Loading branch information
fntlnz committed Nov 29, 2015
2 parents 9503463 + a741dcb commit 7d82bc7
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 177 deletions.
28 changes: 18 additions & 10 deletions app/Dispatcher/SymfonyDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@

namespace App\Dispatcher;

use Penny\Exception\MethodNotAllowed;
use Penny\Exception\RouteNotFound;
use FastRoute\Dispatcher;
use Penny\Exception\MethodNotAllowedException;
use Penny\Exception\RouteNotFoundException;
use Penny\Route\RouteInfo;
use Symfony\Component\HttpFoundation\Request;

class SymfonyDispatcher
{
private $router;
private $container;

public function __construct($router)
public function __construct($router, $container)
{
$this->router = $router;
$this->container = $container;
}

public function __invoke(Request $request)
{
$routeInfo = $this->router->dispatch($request->getMethod(), $request->getPathInfo());
switch ($routeInfo[0]) {
case \FastRoute\Dispatcher::NOT_FOUND:
throw new RouteNotFound;
case Dispatcher::NOT_FOUND:
throw new RouteNotFoundException;
break;
case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
throw new MethodNotAllowed;
case Dispatcher::METHOD_NOT_ALLOWED:
throw new MethodNotAllowedException;
break;
case \FastRoute\Dispatcher::FOUND:
return $routeInfo;
case Dispatcher::FOUND:
$controller = $this->container->get($routeInfo[1][0]);
$eventName = sprintf('%s.%s', strtolower($routeInfo[1][0]), $routeInfo[1][1]);

return new RouteInfo($eventName, [$controller, $routeInfo[1][1]], $routeInfo[2]);

break;
default:
throw new \Exception(null, 500);
break;
}
}
}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "penny/classic-app",
"name": "penny/bookshelf",
"type": "project",
"require": {
"gianarb/penny": "~0.5",
"gianarb/penny": "~0.7",
"doctrine/orm": ">=2.5,<2.7",
"symfony/form": "~2.7,>=2.7.2",
"twig/twig": "~1.20|~2.0",
Expand All @@ -11,7 +11,7 @@
"symfony/http-foundation": "^2.7"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "~5.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 7d82bc7

Please sign in to comment.