loremipsum/route-generator-bundle

Symfony bundle to create routes to resources.

v0.2.0 2019-04-23 11:54 UTC

This package is auto-updated.

Last update: 2024-06-04 07:28:54 UTC


README

Symfony bundle to create routes to resources.

Example route handler

<?php

namespace App\RouteHandlers;

use App\Entity\User;
use LoremIpsum\RouteGeneratorBundle\Model\RouteHandlerInterface;
use Symfony\Component\Routing\RouterInterface;

class DefaultRouteHandler implements RouteHandlerInterface
{
    protected $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    public function handle($value, $view = null, $context = [])
    {
        if ($value instanceof User) {
            return $this->router->generate('userView', array_merge(['user' => $value->getId()], $context));
        }
        return null;
    }
}

Example usage

{% if <entity> is routable %}
    <a href="{{ pathTo(<entity>) }}">{{ <entity> }}</a>
{% else %}
    {{ <entity> }}
{% endif %}