2017 © Pedro Peláez
 

library slim3annotation-router

Enables to define routes via the @Route(...) annotation

image

giacomofurlan/slim3annotation-router

Enables to define routes via the @Route(...) annotation

  • Tuesday, March 13, 2018
  • by giacomofurlan
  • Repository
  • 1 Watchers
  • 1 Stars
  • 29 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

Slim3 Annotation Router

by Giacomo Furlan, (*1)

This library allows routes to be defined in Slim3 with annotations instead of defining them programmatically (in a similar way Symfony does)., (*2)


This is free software under the GNU GPL v3. See the licence file for more information., (*3)


Supported syntax:, (*4)

/**
* @Route("/class/route/prefix")
*/
class MyController {
    /**
    * @Route("/path/{arg}/{arg2}", name="route.name" methods=["GET", "POST"])
    */
    public function myAction(ServerRequestInterface $request, ResponseInterface $response, $arg1, $arg2)
    { ... }
}

Rules: - Controller classes' names MUST end with the suffix "Controller", i.e. MyTestController. - Controller constructors MAY ONLY have App or ContainerInterface dependencies. - @Route annotation needs at least the route (first argument in quotes) - Classes MAY have the @Route annotation specifying only the prefix for the whole class' actions - Methods MAY specify the @Route annotation. Optional values are: - name: the name of the route (in order to be called somewhere else) - methods: to specify at which methods the action responds. Default: all - Methods can specify any argument written in the route (as placeholders) and are mapped per-name, case sensitive. This means that if there is a route placeholder {myArgument}, there MAY be a method's argument $myArgument. If there is a method's argument called $myArgument there MUST be a {myArgument} route placeholder. Exceptions are the ServerRequestInterface, ResponseInterface and ContainerInterface arguments, that MAY be called with any variable name and are always the standard $request, $response and $app->getContainer() Slim3 objects., (*5)


Setup

<?php
use giacomofurlan\slim3AnnotationRouter\Router;

# include your autoload

$app = new \Slim\App(...);

# define variables
new Router($app, $controllersDirectory, $globalRoutePrefix, $cacheDir);

$app->run();

$controllersDirectory can either be a string, or an array of strings. You can thus define multiple controller directories, if needed. Subdirectories will be scanned automatically., (*6)

$globalRoutePrefix is optional, default ''. If set, a global route prefix will be applied to all the parsed routes., (*7)

$cacheDir is optional, default null. If set, cache files will be generated, so that the second time the app is loaded it won't have to scan the directories again avoiding reflection classes. Cache is written again every time a controller file has been modified., (*8)

The Versions

13/03 2018

dev-master

9999999-dev https://github.com/elegos

Enables to define routes via the @Route(...) annotation

  Sources   Download

GNU GPL V3

The Requires

 

route annotation slim3

13/06 2016

v1.0.2

1.0.2.0 https://github.com/elegos

Enables to define routes via the @Route(...) annotation

  Sources   Download

GNU GPL V3

The Requires

 

route annotation slim3

08/06 2016

v1.0.1

1.0.1.0 https://github.com/elegos

Enables to define routes via the @Route(...) annotation

  Sources   Download

GNU GPL V3

The Requires

 

route annotation slim3

08/06 2016

v1.0.0

1.0.0.0 https://github.com/elegos

Enables to define routes via the @Route(...) annotation

  Sources   Download

GNU GPL V3

The Requires

 

route annotation slim3