index.php 864 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace Lesson20;
  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 \Lesson20\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. $content = $req->getContent();
  19. $data = json_decode($content);
  20. return $projectsManager->createProject($data->name, $data->description);
  21. });
  22. $app->run();