Skip to content

Service wrapper for FastRoute providing a more slim-like interface

License

Notifications You must be signed in to change notification settings

rmahoney-bl/Route

 
 

Repository files navigation

Opine\Route

Service wrapper for FastRoute providing a more slim-like interface.

Stories in Ready

Build Status

Scrutinizer Quality Score

Code Coverage

Background

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.

Route Sample

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

Load / Execute Routes

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

Installation

composer require "opine/route:dev-master"
composer install

Author

Ryan Mahoney can be reached at [email protected] or @vcryan on Twitter.

About

Service wrapper for FastRoute providing a more slim-like interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%