index.php 749 B

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