PHP code example of berenger / adr-bundle

1. Go to this page and download the library: Download berenger/adr-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

berenger / adr-bundle example snippets




return [
    ...
    AdrBundle\AdrBundle::class => ['all' => true],
    ...
];



namespace App\Controller;

use App\Entity\Post;
use Doctrine\ORM\EntityNotFoundException;

class ViewPostAction
{
    public function __invoke(int $id)
    {
        $postRepository = $this->getDoctrine()->getRepository(Post::class);
        $post = $postRepository->findOneById($id);

        if (!$post) {
            throw new EntityNotFoundException('Post not found');
        }

        return [
            'post' => $post,
        ];
    }
}



namespace App\Responder;


use App\Entity\Post;

class ViewPostResponder
{
    /**
     * @param Post $post
     * @return array
     */
    public function __invoke(Post $post)
    {
        return [
            'data' => [
                'post' => $post,
            ],
            'serialization_groups' => 'view',
        ];
    }
}

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

class Post
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer", options={"unsigned"=true})
     * @Groups({"always"})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"list","view"})
     */
    private $title;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups({"view"})
     */
    private $content;

    ...
}