junker / yaml-route-service-provider
Silex Service provider for using YAML routing files
0.2.2
2020-06-18 18:25 UTC
Requires
- silex/silex: ^2.0
- symfony/config: ~3.0|~4.0
- symfony/yaml: ~3.0|~4.0
Requires (Dev)
- symfony/browser-kit: ~3.0|~4.0
README
Silex Service provider for using YAML routing files
Requirements
silex 2.x
Installation
The best way to install YamlRouteServiceProvider is to use a Composer:
php composer.phar require junker/yaml-route-service-provider
Examples
use Junker\Silex\Provider\YamlRouteServiceProvider; $app->register(new YamlRouteServiceProvider('routes.yml')); # or $app->register(new YamlRouteServiceProvider('routes.yml', ['cache_dir' => '/tmp/routes_cache']));
Routes config example:
# routes.yml home: path: / defaults: { _controller: 'Acme\Controller\AppController::indexAction' } articles.list: path: /articles defaults: { _controller: 'Acme\Controller\ArticlesController::indexAction' } articles.view: path: /articles/{slug} defaults: { _controller: 'Acme\Controller\ArticlesController::viewAction' }
Controller example:
# Acme\Controller\ArticlesController.php use Silex\Application; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; namespace Acme\Controller; class ArticlesController { public function indexAction(Request $request, Application $app) { ... return new Response($articles); } public function viewAction(Request $request, Application $app, $slug) { ... return new Response($article); } }