2017 © Pedro Peláez
 

symfony1-plugin axis-s2-routing-plugin

symfony 1.x plugin that integrates Symfony2 routing component into your application

image

axis/axis-s2-routing-plugin

symfony 1.x plugin that integrates Symfony2 routing component into your application

  • Sunday, December 16, 2012
  • by 7heaven
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

AxisS2RoutingPlugin

symfony 1.x plugin that integrates Symfony2 routing component into your application., (*1)

It is kinda failed try to bring Symfony2 routes into symfony1. But sfPatternRouting class is way too deeply interwoven into symfony1 that it is practically impossible to replace it with another routing implementation., (*2)

See AxisCurlyRoutingPlugin. It uses Symfony2 routing system on a lower level (without replaceing sfPatternRouting but just introducing new route class)., (*3)

Installation

Use Composer. Just add this dependency to your composer.json:, (*4)

  "require": {
    "axis/axis-s2-routing-plugin": "dev-master"
  }

Configuration

First, you should replace standard routing.yml config handler with the new one. Add this to your config_handlers.yml:, (*5)

config/routing.yml:
  class:    \Axis\S1\S2Routing\Config\ConfigHandler
  file:     %SF_PLUGINS_DIR%/AxisS2RoutingPlugin/lib/Axis/S1/S2Routing/Config/ConfigHandler.php

Than replace symfony's default sfPatternRouting with the plugin's routing class by adding this to your factories.yml:, (*6)

all:
  routing:
    class: \Axis\S1\S2Routing\Routing
    param:
      router: @axis.s2routing.router
      generate_shortest_url:            true
      extra_parameters_as_query_string: true

Usage

Now you can define routes in routing.yml files using new Symfony2 Routing Component syntax along with the old routes. Just define sf2Route as route class and it's all., (*7)

s2_hello: # Symfony2 route
  class: sf2Route
  url:   '/s2/{name}'
  param: { module: test, action: hello }

s1_hello: # symfony1 route
  url:   '/s1/:name'
  param: { module: test, action: hello }

Important notes

  • sfActions::getRoute() will return sf2Route class for new S2 routes and sfRoute (or subclass) instances for the old ones as it was before. Be careful: sf2Route is not compatible with symfony1 sfRoute instances.
  • This is plugin is not compatible with AxisModuleRoutingPlugin at the moment. But I'm working on that.
  • There is no support of collection and object routes for S2 routes for now.

Advantages

So why is this for?, (*8)

Symfony1 routing system went out of date. The main problem is that it strictly constrains how your routes should look like and what you can use as variable value., (*9)

Powerful caching

S2RoutingPlugin brings powerful Symfony2 routing cache to your project., (*10)

Hierarchical URLs

The trigger reason of integrating S2 Routing was the ability to use path variables in routes. For example you want to use something like hierarchical structure in your urls:, (*11)

You could do this with default symfony1 routing:, (*12)

asset:
  url: /:path/:filename.:sf_format
  param: { ... }
  requirements:
    path: .*

This works well routing requests from /my/assets/path/image.png to defined controller but when you need to generate url for that path you'll get this: /my%2Fassets%2Fpath/image.png., (*13)

Yeah, the custom coded Route class could handle that. But S2 Routing does this out of the box:, (*14)

asset:
  url: /{path}/{filename}.{sf_format}
  param: { ... }
  class: sf2Route
  requirements:
    path: .*

And there is many other handy features you can use., (*15)

Variables delimited by any symbols

blog_post:
  url: /blog/{slug}-{id}.html # you cannot use path like '/blog/:slug-:id.html' using symfony1 routing
  param: { ... }
  class: sf2Route
  requirements:
    slug: .+
    id:   \d+

Scheme requirement

login:
  url:  /login
  param: { ... }
  class: sfRoute
  requirements:
    _scheme: https

The Versions

16/12 2012

dev-master

9999999-dev https://github.com/e1himself/axis-s2-routing-plugin

symfony 1.x plugin that integrates Symfony2 routing component into your application

  Sources   Download

MIT

The Requires

 

plugin symfony routing symfony2 routing