Download the PHP package decodelabs/greenleaf without Composer
On this page you can find all versions of the php package decodelabs/greenleaf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download decodelabs/greenleaf
More information about decodelabs/greenleaf
Files in decodelabs/greenleaf
Package greenleaf
Short Description Super-fast directory based HTTP router
License MIT
Informations about the package greenleaf
Greenleaf
Super-fast directory based HTTP router
Greenleaf provides a simple, fast and flexible way to route HTTP requests to controllers and actions based on the URL path.
Get news and updates on the DecodeLabs blog.
Installation
Install via Composer:
Usage
Greenleaf provides a PSR-15 middleware that can be used with any PSR-15 compatible framework. It will parse the request path and attempt to match it against a set of configured routes.
The heart of Greenleaf is a directory based class mapping that enables loading Generators
, Routes
and Actions
from a directory tree that closer matches the structure of most web apps from a logical perspective.
You will need to register at least one namespace with Greenleaf to allow it to load classes from your configured directory tree.
Dispatcher
Greenleaf provides its Dispatcher under the Harvest Middleware namespace to allow for easy integration and automated class resolution with Harvest.
You can however instantiate the Dispatcher directly and treat it as a standard PSR HTTP Handler.
Generators
Generators are used to load and configure routes. They are simple classes that implement the Generator
interface.
By default, Greenleaf will load a Scanner
Generator which in turn will scan the configured directory tree for other Generators and load the Actions they provide.
To define Routes in your directory tree, you can start with a Generic Routes Generator.
Router
When the Dispatcher runs, it loads an appropriate Router to take care of matching the Request to the configured Routes.
At this early stage, Greenleaf provides a reference Matching implementation that just brute forces its way through the list of Routes until it finds a match. This implementation is not optimised for speed and will be replaced shortly with a high performance compiled router system that will be able to handle thousands of routes with ease.
When a Router implementation finds a match, it transforms the Route pattern into a Greenleaf custom URI and a set of parameters that are then passed to the Action (if relevant).
Greenleaf URI
The URI format is mostly just a subset of HTTP URLs, with leaf
as the scheme, standard path, query and fragment components, and one notable addition: areas.
Denoted by a ~ as the first element of the path, an area allows the app to delineate segregated areas (such as the front end and admin) with ease.
The default area is "front" and is used when no area is specified.
For example:
Actions
Once loaded, an Action must only implement an execute($request, $uri, $params)
method, however Greenleaf provides a number of traits that can be used to add additional functionality.
The ByMethodTrait
for example will attempt to invoke a method on the Action based on the HTTP method of the request.
Note that most traits that work in this fashion will use Slingshot
to invoke the method with deep dependency injection support. In this example, the slug from the matched route request URL is passed as a string to the action handlers.
URLs
One of the main benefits of Greenleaf is that it allows you to generate URLs for your routes in a simple and flexible way by creating leaf URIs with many of the required URL constructs already in place.
The router will then be able to match these URIs to the correct route and pass the parameters to the URL generator.
Licensing
Greenleaf is licensed under the MIT License. See LICENSE for the full license text.
All versions of greenleaf with dependencies
decodelabs/archetype Version ^0.3
decodelabs/coercion Version ^0.2.7
decodelabs/dictum Version ^0.6
decodelabs/exceptional Version ^0.4.4
decodelabs/glitch-support Version ^0.4.5
decodelabs/harvest Version ^0.3
decodelabs/singularity Version ^0.2.5
decodelabs/slingshot Version ^0.1.1
decodelabs/veneer Version ^0.11.6
psr/container Version ^2.0
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0