Download the PHP package grogorick/php-routing without Composer

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

Minimal PHP Routing

Set callbacks for hierarchical routes in a simple associative array structure.

Setup

Example

Routes Array Syntax

route-literal => [subroutes array]
static route literal string => subroutes array

/regex/ => subroutes function
regex to match a URL parameter => subroutes function getting the parsed parameter, generating a subroutes array

(subroutes group) => subroutes function
subroutes group name in parentheses => subroutes function generating a subroutes array

METHOD => callable
request METHOD in full uppercase => action callable to be called for this route


Action callables will be called with the following arguments:

URL parameters — in their order withing the respective route
form data — via $_POST or file_get_contents('php://input')
search parameters — via $_GET

Reference

route($routes)
Main function to parse the current request URL and call the corresponding callback function.
$routes (associative array)
— route literal string => subroute array
— route parameter regex => closure with parsed parameter as argument, returning a subroute array
— request method (POST/GET/PUT/PATCH/DELETE) => callback function

respond($response, $code = 200)
Helper function to output the retrieved response as JSON-encoded string, and set an optional status code. Stops execution afterwards.
$response (any) — JSON-serializable response object
$code (int) — HTTP response status code

Check($check, $subroutes)
Wrapper for subroutes array with restricted access.
$check (callable) — callback function to check for access permission
$subroutes — see route($routes)

respond_error_if_no_other_route_matches($error)
Report error during Check(...) without directly stopping routing.
$error (string) — error message

Param($convert, $subroutes)
Wrapper for subroutes array to convert a parsed url parameter.
$convert (callable) — callback function to convert the latest parameter
$subroutes — see route($routes)

IntParam($subroutes)
Shorthand for Param('intval', $subroutes)
$subroutes — see route($routes)

Entity($subroutes)
Item($subroutes)
Wrapper for subroutes array to generate recommended response status codes for undefined request methods.
$subroutes — see route($routes)

set_response_headers($headers)
add_response_header($header)
Replace/add headers that are automatically applied when using respond(...).
$headers (array) — headers to replace all default/previously set headers
$header (string) — header to add

set_options($options)
Set options available in \Options.
$options (associative array) — options to set, using values from \Options as array keys

Server Configuration

Additional Request Methods

By default, most Apache configurations only allow GET and POST requests. Add the following to allow further methods (PUT, PATCH, DELETE, HEAD, OPTIONS).

For this to work, the httpd.conf should include

Response Headers

Response headers can be set either via PHP, which allows to set them dynamically, e.g., to support multiple specific origins:

or via .htaccess if static settings are sufficient:

URL Syntax

Short

https://your-api.domain /v1/accounts/42

Medium

https://your-api.domain /api.php/v1/accounts/42
(pre-configured on most systems)

or

Long

https://your-api.domain /api.php?request=/v1/accounts/42
(vanilla PHP)


All versions of php-routing 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 grogorick/php-routing contains the following files

Loading the files please wait ....