Download the PHP package solventt/slim-route-strategy without Composer

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

Table of contents

1) Requirements 2) Installing 3) Flexible controller signature 4) Features 5) Resolving DTO 6) Use cases 7) Writing custom rules

Package is an implementation of a route invocation strategy for the Slim microframework. It allows to flexibly set up resolving of your controller parameters. About the invocation strategy you can read in the Slim docs.

Requirements

Installing

Flexible controller signature

By default, Slim controllers have a strict signature: , ,

And so you can't omit any of these parameters even if one is not needed. It is called the strategy.

But with this package:

Features

The route strategy consist of the following rules:

1) IdIntegerTypeRule (optional) - casts string type of the 'id' route parameter (if exists) to integer type. It's especially conveniently while using declare(strict_types=1)

NOTE: the name of the controller parameter and the route placeholder MUST be .


2) FlexibleSignatureRule - tries to map an associative array of route parameters to the controller parameters names.

Assume there is the controller method:

And there are the route parameters:

Then controller method will receive next parameters values:

NOTE: the names of the controller request/response parameters MUST be and accordingly.


3) TypeHintContainerRule - injects type-hinted controller parameters using the DI container. But the union types will be ignored.


4) NullTypeRule - if a controller parameter does not have a default value, it checks presence of the 'null' parameter type and (if successful) take it for resolving:


5) MakeDtoRule - read the next section.

By default, only , and are active.

Also, you can add your own rules.

Resolving DTO

converts a data array of POST|PUT|PATCH requests into a Data Transfer Object (DTO)

By default, it will be created the built-in Dto class filled with the request data. But you can define your own DTO class and your own logic for processing the data and filling the object with it, using factories.

Example

Definition for the DI Container:

Factory logic:

And the controller method:

REMEMBER: 1) Name of the parameter must contain a 'dto' substring. For example: '$userUpdateDto', '$dto', 'myDto', 'loginDto' and so forth. 2) You need to specify a parameter name in the DI Container definition as an array key. The value of the array - a corresponding DTO factory class. 3) The DI container definition must be named as 'dtoFactories' (see the example above).

Use cases

For Slim version ^4.0, :

For Slim version ^3.0, :

About the strategy rules

If you don't provide any rules to the rout strategy constructor, only FlexibleSignatureRule, TypeHintContainerRule and NullTypeRule will be enabled by default.

For example, you want to add and , then you should define all necessary rules explicitly:

Or if you want to add only a rule:

REMEMBER:

The example above shows the correct order of the rules.

Writing custom rules

Your custom rule must implement .

Let's look at the simple example. Suppose you want the controller method to receive the User entity as an argument. So the route is:

The controller method is:

And you wrote your custom :


All versions of slim-route-strategy with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
psr/container Version ^1.0
slim/slim Version ^3.0 || ^4.0
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 solventt/slim-route-strategy contains the following files

Loading the files please wait ....