Download the PHP package mrcl/slim-routes without Composer

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

SlimRoutes

PHP8 attributes for easier and cleaner routing in Slim.

Table of contents

Installation

SlimRoutes requires >= PHP 8.1

Usage

Attributes

Controller

#[Controller] marks a controller class as routable.

Controller parameters

Parameter Description
pattern Prefixes all routes' pattern
middleware Adds middleware to all routes
version Specify the basic API version(s) for all routes
Can get overriden by route
groupId Group all routes by specific group configuration
Can get overriden by route

Route

#[Route] maps a route to an action.
By default, it uses the GET method.

Route parameters

Parameter Description
pattern Route pattern
method HTTP method(s)
middleware Route middleware
version Specify the route's API version(s)
groupId Use specific group configuration
priority Prioritize route
name Unique route name

Configuration

Minimal configuration

For a minimal configuration you only need to pass an instance of the Slim/App (or any other class which implements Slim\Interfaces\RouteCollectorInterface or Slim\Interfaces\RouteCollectorProxyInterface) and directories where your action/controller classes are located.

Note: #[Controller(version, groupId)] and #[Route(version. groupId, priority)] do not work without configuration.

Configuration options

Caching

Recommended for production usage.

Additional directory

Add another directory to search for routable classes.

File name pattern

You can minimize the amount of scanned classes by setting a file name/extension pattern (regex).
Recommended if you have a lot of other classes in your folders and/or you do not use caching (e.g. in development).

Example:
All wanted file names end with 'Controller' and file extensions are 'php' or 'PHP'

Options for *Action.php and *Controller.php files are ready to use.

Groups

For more details, see Advanced grouping with groups.

API version

For more details, see API versioning.

Route priority

If you want to prioritize your routes, you need to enable it first. Predefined constants are available in RoutePriority.

If you plan to use your own range of priorities, you can pass a defaultPriority. Priorities are simple integers, the lower the number the higher the priority (better position in the route stack).

Change mapping of ANY

The special HttpMethod::ANY maps "any" HTTP method to your route.

By default, it maps to GET, POST, PUT, PATCH, DELETE and OPTIONS (like in Slim).

You can configure it to your own needs:

Further information

Route patterns

Leading slash

You may have noticed that all route patterns in this documentation do not use a leading /. They are automatically added on route generation.
If you prefer to use leading slashes, just use them.

Pattern order

Depending on Slim configuration a base path or group can be the first pattern element.

[/Slim][/ApiVersion][[/Parent...Group]/Group][/Controller]/Route

Middleware

Unlike in Slim added middleware runs in the order you set it.

Request > FirstMiddleware > SecondMiddleware > ThirdMiddleware > FourthMiddleware
UserController:getAllUsers
FourthMiddleware > ThirdMiddleware > SecondMiddleware > FirstMiddleware > Response`

Middleware order

Added middleware on Slim level is always the first to be run.

[SlimMiddleware][ApiVersionMiddleware][[ParentGroup...Middleware]GroupMiddleware][ControllerMiddleware][RouteMiddleware]

HTTP methods

SlimRoutes comes with predefined constants of the most used HTTP methods.
Also see, Change mapping of ANY.

Grouping routes

Controller pattern

By using the #[Controller] attribute you have the option to pass a pattern which prefixes all routes within the class.

Advanced grouping with groups

If you want to simply group action classes or have a more complex route setup and do not want to reassign patterns and middleware all the time, you can configure groups to use in your routes.

You can use an extra class for defining GroupConfigurations.

Add groups to SlimRoutes

Pass the group's ID

API versioning

For enabling API versioning to all of your routes, you have to configure an VersionConfiguration.

Multiple API versions

Let's assume you have three API versions v1, v2, v3.

A possible configuration could look like the following:

Route order

The route stack would contain routes in the following order

You can still use the priority argument on routes to lower or heighten their position.

Versioning for specific routes

We have the following additional config

For a controller setup a possible config could be:

For action classes:

Unversioned routes

Exclude only some routes

If you want to exclude some routes from versioning you can do so by pass VersionConfiguration::NONE to the #[Route] or #[Controller] attribute.

Additionally, if all of your unversioned routes need some specific middleware you can add a VersionConfiguration.

Make all routes available without version

If you have the special case that all routes (without specific version assignment) need also to be accessed without versioning you can do so

Versioned route names

When you add an API version and use route names, route names will be prefixed with the added version(s).

Route names are v1-my-action and v2-my-action


All versions of slim-routes with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
slim/slim Version ^4.8
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 mrcl/slim-routes contains the following files

Loading the files please wait ....