Download the PHP package grithin/phproute without Composer

On this page you can find all versions of the php package grithin/phproute. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phproute

Grithin's PHP Route

In the beginning, Apache mapped file system path to url path on incoming requests. This wasn't ideal for scripts, since Apache could fail and return the script in plaintext. Matching the file system with the url path is still the avenue of least surprise.

This Route class provides the functionality of file path to url path mapping, without making the script files public, and with a few additions:

The benefit to doing it this way, instead of having a single route file that maps directly to flat controller classes, is:

There are some downsides to this method of routing:

Let's consider some UserController in some framework X that uses flat routing. A benefit to a UserController, that handles incoming paths like '/user/x', is the ability to share functionality and variables. Sometimes it is useful for a set of control functions to have access to the same control related utility functions, and sometimes its useful that a section controller sets some initialization or section sepcific variable data. However, all of this is reproducable with Route through section _control.php files and Route globals (see Route Globals)

Simple Example

File paths

Structure

There is a control folder (/control), and in that control folder are route files and control files.

The route files are loaded gradually, according to the url path. If the url were http://bobery.com/part1/part2/part3, the router would attempt to load:

Not all of those route files need to exist. And, at any point, a route file can change the routing tokens, resulting in a different series of route files being loaded.

The result of the route files is either a final path or a callback.

If the route files did nothing, the final path would remain as the url path.

Control files are loaded in the same way route files are, and are loaded based on the final path. If the final path were /part1/part2/part3, the router would attempt to load:

Not all of these control files need to exist. At any point in the path, you can use the name of the token instead of _control.php, and it will take precedent. So, this could be

Here, /control/part1.php replaces /control/part1/_control.php. The /control/_control.php is an optional global control file, which is loaded for all requests.

Route Globals

In the course of chained control logic, it is sometimes useful for the items in the chain to share-forward functionality or variables. To enable this, Route provides a global array, which it injects/unpacks into control files (like _control.php or page.php) files. By default, two globals are always available: Route, which refers to the Route instance, and control, which is an ArrayObject intended to be where you place control functionality and variables you want to share. However, you can add globals.

The Route Loop

A route file is only run once, but it's rules may apply multiple times, if the path changes. This operations in a similar fashion to the rule loop of mod_rewrite. It also, like mod_rewrite, allows the option for a rule to be final, and discontinue the loop.

Path: /test1/test2/test3 Route Loading:

Stopping the Loop

A rule can have a flag of last, and if that rule matches, the loop will stop after it.

You can also call$route->routing_end() within a route file or within a route rule callback.

Debugging

Just inspect the $route instance

Route Files

Route files have available $route, containing the Route instance.

Route files should return an array of the route rules.

Route Rule

$match_pattern

By default, interpret match_pattern as exact, case sensitive, match pattern. With http://bobery.com/part1/part2/part3, part1/part2/part3 would match, but part1/part2 and part1/part2/part3/ would not.

Flags can change interpretation of match_pattern.

Regex

Default Numeric Group Matches
Named Matches
Using Matches

Apart from a match callback (see $change > callable), the control files have access to the route instance. And, with a rule like ['test/from/(?<id>[0-9]+)','/test/to/[id]', 'regex,last'], we have:

$change

Can be a string or callable

string

Without the regex flag, will replace entire path.

With the regex flag, serves as specialized match replacement (like preg_replace replacement parameter). For convenience, match groups can be used

Example

callable

A callable function($route, $rule), that conforms to Route::is_callable, that should return a new path.

If regex flag is present, callable serves as preg_replace_callback callback, in which the 3rd parameter begins the normal preg_replace_callback callback parameters (function($route, $rule, $matches))

$flags

Comma separrated flags, or an array of flags

Useful Examples

Point folders to index control files

Re-assignment of id:

Control

Loaded control files have the $route instance injected into their context, along with anything else keyed by the $route->globals array.

If you want to end the routing prior to the tokens finishing, you must either exit or call $route->control_end(). If there are remaining tokens without corresponding control files, the router will consider this a page not found event.

Notes

Route expects at least one file excluding a primary _control.php file. If some route will end on the primary _control.php, you must either exit or catch and dispense the RouteException.


All versions of phproute with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
grithin/phpbase Version >=3.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package grithin/phproute contains the following files

Loading the files please wait ....