Download the PHP package sunnyflail/router without Composer

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

Router

A simple routing Utility

How to use

This library leaves it up to you how you want to handle the resulting callback, focusing only on routing

1. Adding new Routes

This library provides three ways to add new Routes to Router. Starting with the most recommended way at 1.2

1.1. Route creation schema

Schema is almost the same for each of these methods

  1. path - String with path that the router will match. It MUST end with a forwards backslash to work correctly. For segments with variable arguments contain the name of argument with curly brackets (eg. '/offer/{id}')

  2. callback - Array containing name of the class / object instance that the Route will be refering to (eg. [IndexController::class, "index"]). It may also be an anonymous function (eg. fn() => print("Hello from anonymous function!"))

  3. (optional) methods - Array containg uppercased names of http methods that this route will correspond to (eg. ["POST", "OPTION"]). Defaults to ["GET", "HEAD"]

  4. (optional) params - Associative array with argument names as keys and regexes that they match as values. If you used an argumented segment in path, you must provide a regex for it there (eg. ["id" => "\d+"])

  5. (optional) defaults - Associative array with argument names as keys and defaulting values as value. You may provide them for some of argumented segments (eg.["id" => 1])

1.2. Loading from an associative array

Create new instance of Router and then call that instance's Router::insertConfig method, passing an array with params as shown above eg.

1.3. Creating Route objects and inserting them

Create a Route object and call Router::addRoutes providing it as an argument. You may insert as many Routes as you want at one call, just separate them with a comma. eg.

1.4. Manually inserting Route data

You may also manually insert the data by calling Router::addRoute method. It's syntax is the same as when creating new Route object eg.

2. Routing

To begin routing invoke Router::match, providing uppercase HTTP request method as first argument, and request path as second. eg.

This method returns an instance of SunnyFlail\Router\MatchedData class containing matched Route and data scraped from argumented segments.

To get these data invoke MatchedData::getData method. It returns an associative array with parameter names as keys, and scraped values corresponding to the key. It may return an empty array if there were no argumented params

To get matched route, invoke MatchedData::getRoute

The Router::match method may throw a SunnyFlail\Router\NotFoundException if no routes were matched

3. Operating on inserted Routes

3.1. Getting a Route object from Router

To get a route call Router::getRoute, providing the name of searched route as an argument. eg.

3.2. Generating urls

To generate relative (to the domainname) url pointing to selected route call Route::generateUrl method. You may need to provide an associative array to fill the parameters eg.


All versions of router with dependencies

PHP Build Version
Package Version
No informations.
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 sunnyflail/router contains the following files

Loading the files please wait ....