Skip to content

Instantly share code, notes, and snippets.

@peterlafferty
Created October 25, 2017 20:21
Show Gist options
  • Save peterlafferty/0191df195091bb7d8a7e6e278968088d to your computer and use it in GitHub Desktop.
Save peterlafferty/0191df195091bb7d8a7e6e278968088d to your computer and use it in GitHub Desktop.
web/index.php showing how to not passing di container in to controllers
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use pl\tddcontroller\TddController;
$app = new Silex\Application();
$app['controller.tdd'] = function () use ($app) {
return new TddController(
$app['charset']
);
};
$app->get('/cities/{id}', function (int $id) use ($app) {
return $app['controller.tdd']->get($id);
})->assert("id", "\d+");
$app->get('/cities/', function (Request $request) use ($app) {
return $app['controller.tdd']->getAll(
$request->query->all()
);
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment