bilgorajskim/yaml-router

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (dev-master) of this package.

Service provider for loading routes from YAML files

dev-master 2016-01-29 04:35 UTC

This package is not auto-updated.

Last update: 2022-01-13 21:38:20 UTC


README

#Yaml Router Provider

Service provider for loading routes from YAML files.

This is a Silex 2 compatible fork of https://github.com/rafamaciel/YamlRouter

Installation

Add the package "bilgorajskim/yaml-router" to the composer.json file and update composer.

{
    "require":{
        ...
        "bilgorajskim/yaml-router":"dev-master"
    }
}

Usage

Parameters:

router.path: Your YAML file path.

Registering

<?php
require_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application();

$app->register(new YamlRouter\YamlRouterServiceProvider(), array(
    'router.path' => __DIR__.'/routing.yml',
));

Example

Below is an example of the routes file.

# routing.yml
home:
  path: /
  defaults: { _controller: 'Foo\HomeController::indexAction' }
 
hello:
  path: /post/{post_id}
  defaults: { _controller: 'Foo\HelloController::postAction' }
  
# Using services as controllers is also possible
article:
  path: /article/{article_id}
  defaults: { _controller: 'article.controller:showAction' }

You may also point to other route files

blog:
  prefix: /blog
  resource: blog.yml

Credits

This service provider has been built based on an article written by Gonzalo Ayuso.