bilgorajskim / yaml-router
Service provider for loading routes from YAML files
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
pkg:composer/bilgorajskim/yaml-router
Requires
- php: >=5.3.0
- symfony/config: ~2.8|~3.0
- symfony/yaml: ~2.8|~3.0
Requires (Dev)
- silex/silex: ~2.0|dev-master
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.