Skip to content

Instantly share code, notes, and snippets.

@pmartin
Created June 4, 2018 18:16
Show Gist options
  • Save pmartin/e9140e0450c721efd1a51c3317722846 to your computer and use it in GitHub Desktop.
Save pmartin/e9140e0450c721efd1a51c3317722846 to your computer and use it in GitHub Desktop.
Silex deprecated. Now what for a very simple case?
<?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();
@hvanmegen
Copy link

This code seems to be full of erroneous comments.. something went wrong with your encoding scheme; the English is no longer readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment