Download the PHP package davidecesarano/embryo-routing without Composer

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

Embryo Routing

A lightweight, fast and PSR compatible PHP Router.

Features

Requirements

Installation

Using Composer:

Example

Before defining the application routes, it is necessary to create the following objects:

Later, you can define the routes with Router object:

Now, create PSR-15 middleware queue adding required routing middlewares:

Finally you can produce output of the Response with Emitter object.

Usage

Create routes

You can define application routes using methods on the Router object. Every method accepts two arguments:

Note that you can write pattern with or without "/" to first character like this: blog/{id}.

Methods

Embryo Routing supports GET, POST, PUT, PATCH, DELETE and OPTIONS request methods. Every request method corresponds to a method of the Router object: get(), post(), put(), patch(), delete() and options(). You can use all() and map() methods for supporting all methods or specific route methods.

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. Embryo uses MethodOverrideMiddleware for manage HTTP-Method-Override.

Callbacks

Each routing method accepts a callback routine as its final argument. This argument by default it accepts at least two arguments:

Writing content to the response

There are three ways you can write content to the HTTP response:

  1. You can simply echo() content from the route callback: this content will be appended to the current HTTP response object.
  2. You can return a Psr\Http\Message\ResponseInterface object.
  3. You can return a json content when returning an array.

Closure binding

If you use a Closure instance as the route callback, the closure’s state is bound to the Container instance. This means you will have access to the DI container instance inside of the Closure via the $this keyword:

Access to current route

If you get the route's object, you can it using the request attribute:

Placeholders

Route patterns may use named placeholders to dynamically match HTTP request URI segments.

Format

A route pattern placeholder starts with a {, followed by the placeholder name, ending with a }. Name and value placeholder may be each character from a-z, A-Z, 0-9, including the _ (underscore).

Optional

To make a placeholder optional, wrap it in square brackets:

You can use a multiple optional parameters:

For "simple slug" optional parameters, you can do this:

In this example, a URI of /blog/2018/my-post-title would result in the $year (2018) and $slug (my-post-title) arguments.

Set regex route

By default the placeholders can accept any character allowed for composing an uri with the exception of the / character. However, placeholders can also require the HTTP request URI to match a particular regular expression. For this, you can use where() method:

Set name route

You can be assigned a name at the route with name() method:

Create route groups

You can organize routes into logical groups with group() method. If you want add a route prefix you can use prefix() method:

In this example URI is, for example, /api/user/1.

Add middleware to route

You can also attach a PSR-15 middleware to any route or route group. The middleware() method accepts a string, an array or an instance of Psr\Http\Server\MiddlewareInterface.

Route middleware

You can use the middleware() method to assign one or more middleware at the route:

Group middleware

In addition to the routes, you can assign one or more middleware to a group and to individual routes within the group:

Resolve via Container

In callback, in addition to closure, you can use the class@method string or ['className', 'methodName'] array:

It translates into a class/method call like this:

In this example you will have access to the DI container instance inside of the class via the $this keyword. If you want have access to service in container use $this->get('myservice'). If you want have access to the request or response instance use $this->request and $this->response. In addition, methods parameters it's may also called using type-hinting, which means you can put the class you need in the method and the Service Container will resolve it automatically:

Set default namespace

You may to set default namespace for your controllers with setNamespace() method:

Working in subfolder

Embryo Routing can works in a subdirectory by setting the path with setBasePath() method:


All versions of embryo-routing with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
davidecesarano/embryo-http Version dev-master
davidecesarano/embryo-container Version dev-master
davidecesarano/embryo-middleware Version dev-master
davidecesarano/embryo-emitter 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 davidecesarano/embryo-routing contains the following files

Loading the files please wait ....