junker/yaml-route-service-provider

Silex Service provider for using YAML routing files

0.2.2 2020-06-18 18:25 UTC

This package is auto-updated.

Last update: 2024-10-19 03:42:33 UTC


README

Silex Service provider for using YAML routing files

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality License

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);
	}
}

Documentation

Symfony Routing