Adds the following annotations to the Symfony3 framework:
The bundle also:
which (if properly configured) leaves the controllers to work only with valid and structured request data. Useful when you like working with DTOs and you are not a big fan of forms.
The bundle uses value resolvers which were introduced in Symfony 3.1
$ composer require alks/http-extra-bundle
2.Enable the bundle in your symfony project
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Alks\HttpExtraBundle\HttpExtraBundle(),
// ...
);
}
Please note the examples below only demonstrate the bundles basic usage they are not suitable for proper application use. For more detailed examples please check the documentation.
<?php
use Alks\HttpExtraBundle\Annotation as Http;
class FooController extends \Symfony\Bundle\FrameworkBundle\Controller\Controller
{
/**
* This will match the "/user?username=foo" and will automatically call the user repository to find a user with the foo
* username.
*
* @Route("/user", methods={"GET"})
* @Http\RequestParam(name="username", bindTo="user", repository="AppBundle\Repository\UserRepository")
* @return User
*/
public function getUserByUsernameAction(User $user)
{
return $user;
}
/**
* This will match a GET request with optional page and limit query parameters like "/posts?page=3&limit=20"
*
* @Route("/posts", methods={"GET"})
* @Http\RequestParams({"page","limit"})
* @Http\Response(context={"groups":{"list"}}, type="json")
*/
public function getPostsAction($page=1, $limit=10)
{
return $this->getDoctrine()->getRepository('AppBundle:Post')->findAllByPage($page,$limit);
}
}
Learn more about the bundle here
How can I help you explore Laravel packages today?