Service wrapper for FastRoute providing a more slim-like interface.
FastRoute is an extremely fast PHP routing library.
Opine\Route is a service wrapper that makes it easy to define routes via a YAML file, cache routes and execute them.
routes:
GET:
/sample: controller@sampleOutput
/api/add: controller@sampleOutput
/api/edit: controller@sampleOutput
/api/list: controller@sampleOutput
/api/upload: controller@sampleOutput
/api/upload/file: controller@sampleOutput
/api/upload/file/{name}: controller@sampleOutput2
/api2/add: [controller@sampleOutput, {before: controller@beforeFilter, after: controller@afterFilter}]
/api2/edit: [controller@sampleOutput, {before: controller@beforeFilter, after: controller@afterFilter}]
/api2/list: [controller@sampleOutput, {before: controller@beforeFilter, after: controller@afterFilter}]
/api2/upload: [controller@sampleOutput, {before: controller@beforeFilter, after: controller@afterFilter}]
/api2/upload/file: [controller@sampleOutput, {before: controller@beforeFilter, after: controller@afterFilter}]
/api2/upload/file/{name}: [controller@sampleOutput2, {before: controller@beforeFilter, after: controller@afterFilter}]
/sample2: [controller@sampleOutput, {name: Sample}]
/sample3/{name}: [controller@sampleOutput2, {name: SampleParam}]
/sample3/{name}/{age}/{location}: [controller@sampleOutput3, {name: SampleParamAssoc}]
/redirect: controller@sampleRedirect
$routeFile = '/var/www/project/config/routes/route.yml';
$containerFile = '/var/www/project/config/containers/container.yml';
$webroot = '/var/www/project/public';
$config = new \Opine\Config\Service($webroot);
$config->cacheSet();
$container = \Opine\Container\Service::instance($webroot, $config, $containerFile);
$routeService = new Opine\Route\Service($webroot, $container);
$routeModel = new Opine\Route\Model($webroot, $routeService);
$routeModel->yaml($routeFile);
$response = $this->route->run('GET', '/sample');
var_dump($response);
composer require "opine/route:dev-master"
composer install
Ryan Mahoney can be reached at [email protected] or @vcryan on Twitter.