12345678910111213141516171819202122232425262728293031 |
- <?php
- use Silex\Application;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- const BACKBONE = '/client/index.html';
- $app->get('/', function (Application $app) {
- return $app->redirect(BACKBONE);
- });
- $app->get('/server', function (Application $app) {
- return $app->redirect(BACKBONE);
- });
- $app->get('/todos/{id}', function (Application $app, int $id) {
- /** @var \Model $model */
- $model = $app['model'];
- $todos = $model->load();
- $todo = $todos[$id] ?? NULL;
- return $app->json($todo);
- });
- $app->put('/todos/{id}', function (Application $app, Request $request, int $id) {
- /** @var \Model $model */
- $model = $app['model'];
- $data = json_decode($request->getContent(), true);
- $created = $model->save($data);
- return new Response('Saved', $created ? Response::HTTP_CREATED : Response::HTTP_OK);
- });
- $app->match('{url}', function ($url) {
- var_dump($url);
- });
|