Table Of Contents

Support

You can obtain free community support for example through stackoverflow.

If you think you found a bug, please create a ticket in the bug tracker.


Continuous Inspections

If you take code quality seriously, try out the new continuous inspection service.
scrutinizer-ci.com

GitHub

Object Routing Library

This library makes generating routes for objects a breeze, and is not tied to any concrete router implementation. As part of the library, we ship an adapter for Symfony 2.1’s router.

Installation

You can install this library through composer:

composer require jms/object-routing

or add it to your composer.json file directly.

Usage

At the moment, routes can only be defined via Doctrine annotations:

use JMS\ObjectRouting\Annotation\ObjectRoute;

/**
 * @ObjectRoute(type = "view", name = "the-actual-route-name", params = {
 *     "slug": "slug",
 * })
 */
class BlogPost
{
    public function getSlug()
    {
        /** .. */
    }
}

Route parameters are key-value pairs where keys represent the placeholder in the URL template, and values can be any value that is supported by Symfony2’s PropertyAccess Component.

If you are using Symfony2 and you defined a route like this:

class BlogPostController
{
    /**
     * @Route("/blog-posts/{slug}", name = "the-actual-route-name")
     */
    public function viewAction(BlogPost $post)
    {
    }
}

you can generate this route with the object router very easily:

$objectRouter->generate('view', $blogPost);
// equivalent to
$router->generate('the-actual-route-name', array('slug' => $blogPost->getSlug()));

For Twig, this library also provides two new functions:

{{ object_path('view', blogPost) }}
{# equivalent to #}
{{ path('the-actual-route-name', {'slug': blogPost.slug}) }}

{{ object_url('view', blogPost) }}
{# equivalent to #}
{{ url('the-actual-route-name', {'slug': blogPost.slug}) }}

License

The code is released under the business-friendly Apache2 license.

Documentation is subject to the Attribution-NonCommercial-NoDerivs 3.0 Unported license.