Download the PHP package juliangut/slim-routing without Composer

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

PHP version Latest Version License

Total Downloads Monthly Downloads

slim-routing

A replacement for Slim's router that adds Attribute and configuration based routing as well as expands the possibilities of your route callbacks by handling different response types

Thanks to this library, instead of configuring routes by hand one by one and including them into Slim's routing you can create mapping files that define and structure your routes and let them be included automatically instead

Additionally, if you're familiar with Symfony's definition of routes through Attributes you'll feel at home with slim-routing because route mappings can be defined the same way as well

Route gathering and compilation can be quite a heavy process depending on how many classes/files and routes are defined, specially in the case of attributes. For this reason it's strongly advised to always use route collector's cache and Slim's route expression caching on production applications and invalidate cache on deployment

Thanks to slim-routing route callbacks can now return \Jgut\Slim\Routing\Response\ResponseType objects that will be ultimately transformed into the mandatory Psr\Message\ResponseInterface in a way that lets you fully decouple view from the route

Installation

Composer

symfony/yaml to parse yaml routing files

spatie/array-to-xml to return XML responses

slim/twig-view to return Twig rendered responses

Usage

Require composer autoload file

Configuration

In the case of Attributes mapping all classes in source paths will be traversed in search of routing definitions

Response handling

Ever wondered why you should encode output or call template renderer in every single route? or even why respond with a ResponseInterface object in the end?

Route callbacks normally respond with a Psr\Message\ResponseInterface object, but thanks to slim-routing they can now respond with a string, null or even better with a more intent expressive ResponseType object that will be handled afterward

Of course normal ResponseInterface responses from route callback will be treated as usual

ResponseType aware invocation strategies

For the new response handling to work you need to register a new invocation strategy provided by this library, there are four strategies provided out of the box that plainly mimic the ones provided by Slim

Response type

Response types are Value Objects with the needed data to later produce a ResponseInterface object. This leaves the presentation logic out of routes allowing for cleaner routes and easy presentation logic reuse

If a route returns an instance of \Jgut\Slim\Routing\Response\ResponseType it will be passed to the corresponding handler according to configuration

There are three response types already provided:

You can easily create your own.

Response type handler

Mapped on invocation strategy, a response handler will be responsible for returning a Psr\Message\ResponseInterface from the received \Jgut\Slim\Routing\Response\ResponseType

Typically, they will agglutinate presentation logic: how to represent the data contained in the response type, such as transform it into JSON, XML, etc. or render it with a template engine such as Twig

Register response type handlers on invocation strategy creation or

Provided response types handlers:

You can create your own response type handlers to compose specifically formatted response (JSON:API, ...) or use another template engines (Plates, Blade, ...), or craft any other response

Parameter transformation

Route parameters can be transformed before arriving to route callable. The most common use of this feature would be to transform IDs into actual object/entity used in the callable

To achieve this you need to provide a \Jgut\Slim\Routing\Transformer\ParameterTransformer instance

For example, you would want to transform parameters into Doctrine entities

Mind that a single transformer can transform one or several parameters

Console commands

List routing

List defined routes supporting searching and sorting

Match routing

Match routes with Slim's route resolver, so results will be exactly the same as through HTTP requests

Route mapping

Routes can be defined in two basic ways: by writing them down in definition files of various formats or directly in classes with Attributes

Attributes

Group (Class level)

Defines a group in which routes may reside. It is not mandatory but useful when you want to do route grouping or apply middleware to several routes at the same time

Route (Method level)

Defines the final routes added to Slim

Middleware (Class and Method level)

Defines middleware to apply. Multiple Attributes can be added

Transformer (Class and Method level)

Defines route transformers. Multiple Attributes can be added

Definition files

PHP
XML
JSON

Mind comments are not valid standard JSON

YAML

Group

Defines a group in which routes may reside

Route

Defines a route added to Slim

Annotations

Annotations are deprecated and will be removed eventually. Use Attribute mapping when possible.

You need to require Doctrine's annotation package

Group (Class level)

Defines a group in which routes may reside. It is not mandatory but useful when you want to do route grouping or apply middleware to several routes at the same time

Route (Method level)

Defines the final routes added to Slim

Route composition

Using grouping with juliangut/slim-routing is a little different to how default Slim's router works

Groups are never really added to the router (in the sense you can add them in Slim with $app->group(...)), instead, routes are a composition of definitions that makes the final route

Name

Final route name is composed of the concatenation of group prefixes followed by route name according to configured route naming strategy

Pattern

Resulting route pattern is composed of the concatenation of group patterns if any and finally route pattern

Placeholders

Resulting placeholders list is composed of all group placeholders if any and route placeholders

It is important to pay attention not to duplicate placeholder names in the resulting pattern as this can't be handled by FastRoute. Check group tree patterns for placeholder names

Arguments

Resulting route arguments is composed of all group arguments if any and route arguments

Middlewares

Resulting middlewares added to a route will be the result of combining group middleware and route middleware and are applied to the route in the following order, so that final middleware execution order will be the same as expected in any Slim app:

Transformers and parameters

Resulting transformers and parameters list are a combination of all group transformers and parameters if any and route transformers and parameters

As with placeholders, it is important to pay attention not to duplicate parameter names as child groups and routes will replace previous parameters

Migration from 2.x

Annotations

Annotations have been deprecated and its use is highly discouraged in favor of Attributes

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before.

See file CONTRIBUTING.md

License

See file LICENSE included with the source code for a copy of the license terms.


All versions of slim-routing with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
juliangut/mapping Version ^1.4.2
slim/slim Version ^4.7
symfony/polyfill-php81 Version ^1.27
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 juliangut/slim-routing contains the following files

Loading the files please wait ....