Container-Klassenparameter entfernt • DI statt Service Locator • Update auf willdurand/negotiation 2.0 • Symfony >= 2.7, PHP >= 5.5.9 • ParamFetcher und Exception-Handling überarbeitet Neu in 2.0
use FOS\RestBundle\Controller\Annotations\Route; class UserController { /** * @Route("/users/{id}", methods={"LOCK"}) */ public function lockUserAction($id) { } }
use FOS\RestBundle\Controller\ControllerTrait; use Symfony\Component\HttpFoundation\Response; class PostController { use ControllerTrait; public function getPostAction($id) { if (null === $post = $this->findPost($id)) { $view = $this->view(null, Response::HTTP_NOT_FOUND); } else { $view = $this->view($post); } return $this->handleView($view); } }
app/console debug:router ------------------------------- -------- -------- ------ ----------------------------- Name Method Scheme Host Path ------------------------------- -------- -------- ------ ----------------------------- api_article_v1_get_articles GET ANY ANY /v1/articles.{_format} api_article_v1_get_article GET ANY ANY /v1/articles/{id}.{_format} api_article_v1_post_article POST ANY ANY /v1/articles.{_format} api_article_v1_put_article PUT ANY ANY /v1/articles/{id}.{_format} api_article_v1_delete_article DELETE ANY ANY /v1/articles/{id}.{_format} api_article_v2_get_articles GET ANY ANY /v2/articles.{_format} api_article_v2_get_article GET ANY ANY /v2/articles/{id}.{_format} api_article_v2_post_article POST ANY ANY /v2/articles.{_format} api_article_v2_put_article PUT ANY ANY /v2/articles/{id}.{_format} api_article_v2_delete_article DELETE ANY ANY /v2/articles/{id}.{_format} ------------------------------- -------- -------- ------ -----------------------------
use Symfony\Component\HttpFoundation\Request; class ArticleController { public function getArticlesAction(Request $request) { if ($request->attributes->get('version', 'v1') === 'v2') { // v2-spezifischer Code } // ... } }