Download the PHP package puz/router without Composer

On this page you can find all versions of the php package puz/router. 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 router

Puz Router

The most fluffiest PHP router you have ever used

Installation

To use it with composer, simply type composer require puz/router or add the following to your composer.json file.

If you want to use the latest unreleased version, you need to require the dev version, like this:

How-To

Create a router

Easy as:

The router is the object which contains different validation rules on how to validate the url. By default there are two validation rules added. \Puz\Router\Validations\MethodValidator and \Puz\Router\Validations\UrlValidator. These will validate routes against the request method and the given url.
You can modify this list like this:

Create a route

This is done through the Router object. Per now i have added six different request methods. GET, HEAD, POST, PUT, PATCH, DELETE. To create a route with one of these methods:

If you chain two request method methods, the last one will overwrite the previous. To allow multiple request methods you have to use the method method.

To provide the url you can (if you did not specify it in the method methods) use the url method.

To provide the callback you can (if you did not specify it in the method methods or the url method) use the callback method.

For now the router only accepts callable callbacks. (And pure strings that is just for echoing, ex: ->callback("ping") results in ping being echoed if it's not a valid function).

Run the router

To run the router you have to end your application with $router->run(...). This router will not auto-detect your request method nor requested uri, so you have to fill in the blanks. Heres an easy example of how to do that.

This also opens up for a easy way to debug or do it just the way you want it!

If you are using this router in a subfolder on your domain, you might have a bad time with the router uri if you're using this exact run example. You will need to filter away the subfolder from the request uri before giving it to the router. As for now i use this:

Examples

I will update the examples some other time, but not too far in the future. I hope this readme will provide enough information on how you can use the router.

Planned changes

[ ] Adding response converters. If your callback returns data, these converters will convert your response to ex. json output and such.

Got some ideas? Please give me a pling in the issue section!


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.4
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 puz/router contains the following files

Loading the files please wait ....