index.php 841 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Lesson19;
  3. use Pimple\Container as Pimple;
  4. use Pimple\Psr11\Container;
  5. use Silex\Application;
  6. use Symfony\Component\HttpFoundation\Request;
  7. require_once __DIR__ . '/vendor/autoload.php';
  8. $app = new Application();
  9. $container = new Container($dic = new Pimple());
  10. $dic[ProjectStore::NAME] = ProjectStore::instantiate($container);
  11. $dic[ProjectManager::NAME] = ProjectManager::instantiate($container);
  12. /** @var \Lesson19\ProjectManager $projectsManager */
  13. $projectsManager = $container->get(ProjectManager::NAME);
  14. $app->get('/projects', function () use($projectsManager) {
  15. return $projectsManager->listAll();
  16. });
  17. $app->post('/projects', function (Request $req) use($projectsManager) {
  18. $data = json_decode($req->getContent());
  19. return $projectsManager->createProject($data->name, $data->description);
  20. });
  21. $app->run();