<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marcojanssen / silex-routing-service-provider example snippets
$routes = array(
'foo' => array(
//'name' => 'foo', --> you can omit the name if a key is set
'pattern' => '/foo',
'controller' => 'Foo\Controller\FooController::fooAction',
'method' => array('get', 'post', 'put', 'delete', 'options', 'head')
)
);
use Silex\Application;
use MJanssen\Provider\RoutingServiceProvider;
$app = new Application();
$routingServiceProvider = new RoutingServiceProvider();
$route = array(
'name' => 'foo',
'pattern' => '/foo',
'controller' => 'Foo\Controller\FooController::fooAction',
'method' => array('get', 'post', 'put', 'delete', 'options', 'head')
);
$routingServiceProvider->addRoute($app, $route);
use Silex\Application;
use MJanssen\Provider\RoutingServiceProvider;
$app = new Application();
$routingServiceProvider = new RoutingServiceProvider();
$routes = array(
'foo' => array(
//'name' => 'foo', --> you can omit the route name if a key is set
'pattern' => '/foo',
'controller' => 'Foo\Controller\FooController::fooAction',
'method' => array('get', 'post', 'put', 'delete', 'options', 'head')
),
'baz' => array(
//'name' => 'baz', --> you can omit the route name if a key is set
'pattern' => '/baz',
'controller' => 'Baz\Controller\BazController::bazAction',
'method' => 'get'
)
);
$routingServiceProvider->addRoutes($app, $route);
class MiddleWare {
public function __invoke(Request $request, Application $app)
{
//do stuff
$x = 1;
}
}
use Silex\Application;
use MJanssen\Provider\RoutingServiceProvider;
$app = new Application();
$routingServiceProvider = new RoutingServiceProvider();
$routes = array(
'foo' => array(
//'name' => 'foo', --> you can omit the route name if a key is set
'pattern' => '/foo',
'controller' => 'Foo\Controller\FooController::fooAction',
'method' => array('get'),
// this is where it all happens!
'before' => array(new MiddleWare())
)
);
$routingServiceProvider->addRoutes($app, $route);
use Silex\Application;
use Igorw\Silex\ConfigServiceProvider;
use MJanssen\Provider\RoutingServiceProvider;
$app = new Application();
//Set all routes
$app->register(
new ConfigServiceProvider(__DIR__."/../app/config/routes.php")
);
//Add all routes
$app->register(new RoutingServiceProvider('custom.routing.key'));
php
$value = array('name' => 'value')
php
$assert = array('id' => '^[\d]+$')
php
$after = array('convert' => function() {})
php
$before = array('before' => function() {})
php
$after = array('after' => function() {})
php
$secure = array('ROLE_ADMIN')
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.