|
| 1 | +diff --git a/composer.json b/composer.json |
| 2 | +index 52e5602..5aff5e1 100644 |
| 3 | +--- a/composer.json |
| 4 | ++++ b/composer.json |
| 5 | +@@ -1,6 +1,7 @@ |
| 6 | + { |
| 7 | + "require": { |
| 8 | + "symfony/http-foundation": "~2.5", |
| 9 | +- "aura/router": "~2.1" |
| 10 | ++ "aura/router": "~2.1", |
| 11 | ++ "pimple/pimple": "~3.0" |
| 12 | + } |
| 13 | + } |
| 14 | +diff --git a/composer.lock b/composer.lock |
| 15 | +index aee9a74..9642f7c 100644 |
| 16 | +--- a/composer.lock |
| 17 | ++++ b/composer.lock |
| 18 | +@@ -4,7 +4,7 @@ |
| 19 | + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
| 20 | + "This file is @generated automatically" |
| 21 | + ], |
| 22 | +- "hash": "05160fed37a43d33fa4fa22bcc76836f", |
| 23 | ++ "hash": "bb1db9d97f1d15cc2909421fd8279bc0", |
| 24 | + "packages": [ |
| 25 | + { |
| 26 | + "name": "aura/router", |
| 27 | +@@ -61,6 +61,52 @@ |
| 28 | + "time": "2014-10-22 14:14:56" |
| 29 | + }, |
| 30 | + { |
| 31 | ++ "name": "pimple/pimple", |
| 32 | ++ "version": "v3.0.0", |
| 33 | ++ "source": { |
| 34 | ++ "type": "git", |
| 35 | ++ "url": "https://github.com/fabpot/Pimple.git", |
| 36 | ++ "reference": "876bf0899d01feacd2a2e83f04641e51350099ef" |
| 37 | ++ }, |
| 38 | ++ "dist": { |
| 39 | ++ "type": "zip", |
| 40 | ++ "url": "https://api.github.com/repos/fabpot/Pimple/zipball/876bf0899d01feacd2a2e83f04641e51350099ef", |
| 41 | ++ "reference": "876bf0899d01feacd2a2e83f04641e51350099ef", |
| 42 | ++ "shasum": "" |
| 43 | ++ }, |
| 44 | ++ "require": { |
| 45 | ++ "php": ">=5.3.0" |
| 46 | ++ }, |
| 47 | ++ "type": "library", |
| 48 | ++ "extra": { |
| 49 | ++ "branch-alias": { |
| 50 | ++ "dev-master": "3.0.x-dev" |
| 51 | ++ } |
| 52 | ++ }, |
| 53 | ++ "autoload": { |
| 54 | ++ "psr-0": { |
| 55 | ++ "Pimple": "src/" |
| 56 | ++ } |
| 57 | ++ }, |
| 58 | ++ "notification-url": "https://packagist.org/downloads/", |
| 59 | ++ "license": [ |
| 60 | ++ "MIT" |
| 61 | ++ ], |
| 62 | ++ "authors": [ |
| 63 | ++ { |
| 64 | ++ "name": "Fabien Potencier", |
| 65 | ++ "email": "fabien@symfony.com" |
| 66 | ++ } |
| 67 | ++ ], |
| 68 | ++ "description": "Pimple is a simple Dependency Injection Container for PHP 5.3", |
| 69 | ++ "homepage": "http://pimple.sensiolabs.org", |
| 70 | ++ "keywords": [ |
| 71 | ++ "container", |
| 72 | ++ "dependency injection" |
| 73 | ++ ], |
| 74 | ++ "time": "2014-07-24 09:48:15" |
| 75 | ++ }, |
| 76 | ++ { |
| 77 | + "name": "symfony/http-foundation", |
| 78 | + "version": "v2.5.6", |
| 79 | + "target-dir": "Symfony/Component/HttpFoundation", |
| 80 | +diff --git a/index.php b/index.php |
| 81 | +index d8c644d..029e7d9 100644 |
| 82 | +--- a/index.php |
| 83 | ++++ b/index.php |
| 84 | +@@ -12,30 +12,52 @@ try { |
| 85 | + use Symfony\Component\HttpFoundation\Request; |
| 86 | + use Symfony\Component\HttpFoundation\Response; |
| 87 | + use Aura\Router\RouterFactory; |
| 88 | ++use Pimple\Container; |
| 89 | + |
| 90 | +-$request = Request::createFromGlobals(); |
| 91 | +-$uri = $request->getPathInfo(); |
| 92 | ++$c = new Container(); |
| 93 | + |
| 94 | +-$routerFactory = new RouterFactory(); |
| 95 | +-$router = $routerFactory->newInstance(); |
| 96 | ++// configuration |
| 97 | ++$c['connection_string'] = 'sqlite:'.__DIR__.'/data/database.sqlite'; |
| 98 | + |
| 99 | +-// create a router, build the routes, and then execute it |
| 100 | +-$router->add('attendees_list', '/attendees') |
| 101 | +- ->addValues(['controller' => 'attendees_controller']); |
| 102 | +-$router->add('homepage', '{/name}') |
| 103 | +- ->addValues(['controller' => 'homepage_controller']); |
| 104 | +-$route = $router->match($uri, $request->server->all()); |
| 105 | ++// Service setup |
| 106 | ++$c['connection'] = function(Container $c) { |
| 107 | ++ return new PDO($c['connection_string']); |
| 108 | ++}; |
| 109 | ++ |
| 110 | ++$c['request'] = function() { |
| 111 | ++ return Request::createFromGlobals(); |
| 112 | ++}; |
| 113 | ++ |
| 114 | ++$c['router'] = function() { |
| 115 | ++ $routerFactory = new RouterFactory(); |
| 116 | ++ |
| 117 | ++ $router = $routerFactory->newInstance(); |
| 118 | ++ |
| 119 | ++ // create a router, build the routes, and then execute it |
| 120 | ++ $router->add('attendees_list', '/attendees') |
| 121 | ++ ->addValues(['controller' => 'attendees_controller']); |
| 122 | ++ $router->add('homepage', '{/name}') |
| 123 | ++ ->addValues(['controller' => 'homepage_controller']); |
| 124 | ++ |
| 125 | ++ return $router; |
| 126 | ++}; |
| 127 | ++ |
| 128 | ++ |
| 129 | ++$uri = $c['request']->getPathInfo(); |
| 130 | ++ |
| 131 | ++ |
| 132 | ++$route = $c['router']->match($uri, $c['request']->server->all()); |
| 133 | + |
| 134 | + // merge the matched attributes back into Symfony's request |
| 135 | + if ($route) { |
| 136 | +- $request->attributes->add($route->params); |
| 137 | ++ $c['request']->attributes->add($route->params); |
| 138 | + } |
| 139 | + |
| 140 | + // get the "controller" out, or default to error404_controller |
| 141 | +-$controller = $request->attributes->get('controller', 'error404_controller'); |
| 142 | ++$controller = $c['request']->attributes->get('controller', 'error404_controller'); |
| 143 | + |
| 144 | + // execute the controller and get the response |
| 145 | +-$response = call_user_func_array($controller, array($request)); |
| 146 | ++$response = call_user_func_array($controller, array($c['request'], $c)); |
| 147 | + if (!$response instanceof Response) { |
| 148 | + throw new Exception(sprintf('Your controller "%s" did not return a response!!', $controller)); |
| 149 | + } |
| 150 | +@@ -56,8 +78,8 @@ function homepage_controller(Request $request) { |
| 151 | + return new Response($content); |
| 152 | + } |
| 153 | + |
| 154 | +-function attendees_controller(Request $request) { |
| 155 | +- global $dbh; |
| 156 | ++function attendees_controller(Request $request, Container $c) { |
| 157 | ++ $dbh = $c['connection']; |
| 158 | + |
| 159 | + $sql = 'SELECT * FROM php_camp'; |
| 160 | + $content = '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />'; |
0 commit comments