Skip to content

Backend PHP Router driven by YAML configuration files and dependency injection.

License

Notifications You must be signed in to change notification settings

ryan-mahoney/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

route:
    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

Backend PHP Router driven by YAML configuration files and dependency injection.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •