Download the PHP package richardgoldstein/fat-free-routes without Composer
On this page you can find all versions of the php package richardgoldstein/fat-free-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download richardgoldstein/fat-free-routes
More information about richardgoldstein/fat-free-routes
Files in richardgoldstein/fat-free-routes
Package fat-free-routes
Short Description Generate FatFreeFramework Routes from DocBlocks
License MIT
Informations about the package fat-free-routes
FatFreeRoutes
Note:
This tool has been completely refactored into a plugable architecture to allow for future expansion. Note the following:
- The command line parameter names have changed
- The @routeJS tag is no longer supported, and has been replaced by the
[js]
modifier. - The documentation is a work-in-progress.
PHP >= 7.0 (To use the tool), PHP >= 5.4 (For generated code)
This development tool allows one to specify routes in the Fat Free Framework in DocBlock format in the controller class. Furthermore, it is build with a pluggable interface to allow for future expansion beyond route generation.
Example
Adding the @route
tag above is equivalent to calling
or specifying the route in a config file.
The tool, f3routes
produces a php file suitable to be required
in index.php
and
provides a method to install the routes.
Require the generated file in index.php
and call installRoutes($includeDev);
before calling $f3->run();
There is also the option to generate a JavaScript file so that routes can be easily built in Javascript for front-end use.
Tags
The following DocBlock tags can be used
@route
Applies to a class method, and follows the same syntax as Fat Free Framework routes, using
the syntax
Replaceable tokens can be used in the path. The alias is optional, as are the route modifiers
in brackets [ ]
.
f3routes
supports additional values in the route modifier portion surrounded by brackets [ ]
.
This can be a comma-separated list of the existing F3 modifiers (ajax, cli, or sync), and the
following additional modifiers:
ttl=<number>
Set the$ttl
parameter toBase->route()
kbps=<number>
Set the$kbps
parameter toBase->route()
js
Expose the alias in the Javascript code.
The order of the items in the modifier section in unimportant, except that only the last
one of ajax
, sync
, or cli
are preserved.
Here are some examples of @route
tags using modifiers:
@devroute
Same as @route
but only installed if installRoutes() is called with true
.
@routeBase
Specified in the DocBlock for the class, this prepends a path fragment to all
of the route paths specified in the methods by @route
or @devroute
.
@routeMap
and @devrouteMap
The equivalent of the F3 map function, these create routes for
RESTful controllers. These also allow specification of an alias for exposure in the
Javascript output, which is enabled by adding [js]
at the end of the tag:
This is equivalent to
If a @routeBase is set, the map path will also be prepended.
Note that f3routes supports the proposed PSR-5 PHPDoc standard: all tags can be prefixed
or namespaced with f3routes
. The following are equivalent:
Command Line Parameters
-
-f, --force
Force the entire route map to be regenerated. If no cache file is specified, this has no effect, as the route table will be generated from scratch in that case.
-
-v, --verbose
Verbose output.
-
--cache-file=<file>
If specified, a cache-file will save the resulting route map, so that only files that have changed need to be re-parsed. The same cache file should be used on subsequent calls for the same project.
-
--source-dir=<directory>
This is required. Specifies the directory that contains PHP files. This parameter can be specified more than once. Directories are scanned recursively.
-
--output-php=<file>
This is required. Specifies the file to be written with the generated PHP code.
-
--output-js=<file>
This is an optional parameter. If specified, a fle containing JS code and a route map will be produced. Only routes explicitly flagged for JS output will be emitted,
One use case is to incorporate f3routes into a file watcher, and update the routes in real-time as the controller classes are modified.
Example
Installation
f3routes
can be installed via composer:
You may need to specify the minimum stability as this is still in dev.
Once installed via composer, f3routes
can be found in vendor/bin:
or
I include it in a gulp task:
TODO
- Elaborate on the JavaScript output
- Plug-In documentation
- Needs new unit tests since refactoring.
- More examples
- How to use the rendered PHP and JavaScript
All versions of fat-free-routes with dependencies
phpdocumentor/reflection Version dev-develop#208cd4547c822ba40f13955122940553da73c0ce
phpdocumentor/reflection-common Version 1.0.1
phpdocumentor/reflection-docblock Version 4.2.0
phpdocumentor/type-resolver Version 0.4.0
ulrichsg/getopt-php Version 3.1