Created
June 4, 2018 18:16
-
-
Save pmartin/e9140e0450c721efd1a51c3317722846 to your computer and use it in GitHub Desktop.
Silex deprecated. Now what for a very simple case?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Avec silex, on pouvait écrire ceci (routing + formatage de la sortie) en quelques | |
// lignes, tout dans un seul fichier (pour peu qu'on ait composer requiré silex, bien sûr). | |
// Il y a moyen de faire pareil avec Symfony ? | |
// -> Un seul fichier, code super court et lisible, pas 36 classes ni config à créer ? | |
// Sinon, quelle alternative ? Slim ? Lumen ? | |
require __DIR__ . '/vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
$app = new Silex\Application(); | |
$app->get('/user/{id}', function ($id) { | |
// Cas réel : la donnée viendra d'une DB ;-) | |
$data = [ | |
'id' => $id, | |
'nom' => 'MARTIN', | |
'prenom' => 'Pascal', | |
]; | |
return new JsonResponse($data); | |
}); | |
$app->delete('/user/{id}', function ($id) { | |
// Suppression de l'utilisateur | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code seems to be full of erroneous comments.. something went wrong with your encoding scheme; the English is no longer readable.