Download the PHP package adinan-cenci/router without Composer

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

A small PHP router library

A simple PHP router to handle http requests.

This library is PSR-15 compliant and therefore works with PSR-7 messages and makes use of PSR-17 factories.




Instantiating




Adding routes

You may add routes by informing the http method, the regex pattern to be matched against the the path and the associated controller:

Http method

Regex patterns

A simple regex pattern. Capture groups will be passed to the controller as attributes.

Obs: The route accepts multiple patterns as an array.

Controllers

The controller will receive two paramaters: an instance of Psr\Http\Message\ServerRequestInterface and Psr\Http\Server\RequestHandlerInterface respectively.

The routes accept various arguments as controllers:

Obs: If the controller does not exist or cannot be called because of some reason or another, an exception will be thrown.

See the contents of the "examples" directory for more details.

::add() shorthands




Executing

Calling ::run() will execute the router and send a respose.




PSR compliance

This library is PSR-15 compliant, as such your controllers may tailor the response in details as specified in the PSR-7. The handler make PSR-17 factories available to use.

IMPORTANT

If your controller does not return an instance of ResponseInterface, the router will create one based out of whatever was outputed through echo and print.

Niceties

Besides being PSR-17 compliant, the response factory comes with some methods to make things easier:

Adding cookies to a response object is made easier with ::withAddedCookie():




Middlewares

Middlewares will be processed before the routes. Middlewares are very similar to routes but unlike routes more than one middleware may be executed.




Errors

Exceptions

By default catched exceptions will be rendered in a 500 response object, you may customize it by setting your own handler.

Not found

By default when no route is found, the router will render a 404 response object, you may customize it by setting your own handler.




::setDefaultNamespace($namespace)

Set the default namespace, so there will be no need to write the entire class name of the controller when defining routes.




Working inside sub-directories

The router will automatically work inside sub-directories.

Consider the example: Your URL: http://yourwebsite.com/foobar/about

Your document root is
/var/www/html/ and your router is inside of
/var/www/html/foobar/.

The router will match the routes against about and NOT foobar/about.

Still, if you really need to work with foobar/about , then you must pass /var/www/html/ as your base directory to the Router class' constructor.




Server configuration

In order for it to work, we need to rewrite the requests to the file containing our router. Below are some examples:

Apache

Here is the example of a .htaccess for Apache:




Nginx

Here is the example for nginx:




IIS

Here is the example of a web.config for Microsoft IIS:




Installing

Use composer




License

MIT


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
adinan-cenci/psr-17 Version ^1.0.0
psr/http-server-handler Version 1.0.x-dev
psr/http-server-middleware Version 1.0.x-dev
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 adinan-cenci/router contains the following files

Loading the files please wait ....