Download the PHP package wepesi/routing without Composer

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

wepesi/routing

Build Status Source Version Downloads License Issues

A lightweight and simple object oriented PHP Router. Built by (Boss Ibrahim Mussa) and Contributors

Features

Prerequisites/Requirements

Installation

Installation is possible using Composer

Demo

A demo is included in the demo folder. Serve it using your favorite web server, or using PHP 7.4+'s built-in server by executing php -S localhost:8080 on the shell. A .htaccess for use with Apache is included.

Usage

Create an instance of \Wepesi\Routing\Router, define some routes onto it, and run it.

Routing

Wepesi/routing supports GET, POST, PUT, PATCH, DELETE HTTP request methods. Pass in a single request method.

When a route matches against the current URL (e.g. $_SERVER['REQUEST_URI']), the attached route handling function will be executed. The route handling function must be a callable. Only the first route matched will be handled. When no matching route is found, a 404 handler will be executed.

Routing Shorthands

Shorthands for single request methods are provided:

Note: Routes must be hooked before $router->run(); is being called.

Route Patterns

Route Patterns can be static or dynamic:

Static Route Patterns

A static route pattern is a regular string representing a URI. It will be compared directly against the path part of the current URL.

Examples:

Usage Examples:

Dynamic Placeholder-based Route Patterns

This type of Route Patterns are the same as Dynamic PCRE-based Route Patterns, but with one difference: they don't use regexes to do the pattern matching but they use the more easy placeholders instead. Placeholders are strings surrounded by collumn, e.g. :name.

Examples:

Placeholders are easier to use than PRCEs, but offer you less control as they internally get translated to a PRCE that matches any character (.*).

Note: the name of the placeholder should match with the name of the parameter that is passed into the route handling function.

Dynamic PCRE-based Route Patterns

This type of Route Patterns contain dynamic parts which can vary per request. The varying parts are named subpatterns and are defined using regular expressions.

Usage Examples:

Commonly used PCRE-based subpatterns within Dynamic Route Patterns are:

When multiple subpatterns are defined, the resulting route handling parameters are passed into the route handling 'with` function in the order they are defined in:

This will be like a kind of validation of your parameters.

Subrouting / Groupe Routing

Use $router->group($baseroute, $fn) to group a collection of routes in to a subroute pattern. The subroute pattern is prefixed into all following routes defined in the scope. e.g. Mounting a callback $fn onto /movies will prefix /movies onto all following routes.

Nesting of subroutes is possible, just define a second $router->group() in the callable that's already contained within a preceding $router->group().

Class#Method calls

We can route to the class action like so:

or

When a request matches the specified route URI, the get_users method on the UserController class will be executed. The defined route parameters will be passed to the class method.

The method can be static(not-recommend) or non-static (recommend). In case of a non-static method, a new instance of the class will be created.

Note: In case you are using static method, dont pass as string or in array.

Before Route Middleware

wepesi/routing supports Before Route Middlewares, which are executed before the route handling is processed.

Route middlewares are route specific, one or middleware can be set and will be executed before route function.

API Groupe Routing

You can define your API route inside the api method, and will auto complet api route fro you.

Overriding the request method

Use X-HTTP-Method-Override to override the HTTP Request Method. Only works when the original Request Method is POST. Allowed values for X-HTTP-Method-Override are PUT, DELETE, or PATCH.

Custom 404

The default 404 handler sets a 404 status code and exits. You can override this default 404 handler by using $router->set404(callable);

You can also define multiple custom routes e.x. you want to define an /api route, you can print a custom 404 page:

Also supported are Class@Method callables:

The 404 handler will be executed when no route pattern was matched to the current URL.

💡 You can also manually trigger the 404 handler by calling $router->trigger404()

Integration with other libraries

Integrate other libraries with wepesi/routing by making good use of the use keyword to pass dependencies into the handling functions.

Given this structure it is still possible to manipulate the output from within the After Router Middleware

A note on working with PUT

There's no such thing as $_PUT in PHP. One must fake it:

Subfolder support

License

wepesi/routing is released under the Apache-2.0 license. See the enclosed LICENSE for details.


All versions of routing with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
wepesi/optionsresolver Version dev-master
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 wepesi/routing contains the following files

Loading the files please wait ...