Download the PHP package zholus/symfony-middleware without Composer

On this page you can find all versions of the php package zholus/symfony-middleware. 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 symfony-middleware

MiddlewareBundle for Symfony

Build Status Coverage Status StyleCI

This bundle allows you to create simple middleware that executes right before controller does on each requests.

Its almost looks like middleware in laravel framework.

There are 4 possible ways to inject your middleware to your request.

Symfony versions

Installation

Composer for symfony version 6.x

composer require zholus/symfony-middleware

Composer for symfony version 5.x

composer require zholus/symfony-middleware:^2

Composer for symfony version 4.x

composer require zholus/symfony-middleware:^1

Add bundle in bundles.php

Zholus\SymfonyMiddleware\MiddlewareBundle::class => ['all' => true]

Register middleware

Global middleware

Global middleware executes on every http requests before every controller.

To register middleware as global you need implement interface \Zholus\SymfonyMiddleware\GlobalMiddlewareInterface.

That's all.

Controller middleware

This middleware will execute on every action in certain controller, to attach middleware to controller, you need setup some configuration in your services.yaml file:

App\Controller\WelcomeController:
    tags:
        - { name: 'middleware.controller', middleware: 'App\Middleware\AuthNeededMiddleware' }

That's all, just attach tag with options: name - middleware.controller and middleware - fully-qualified class name.

You can attach more that one middleware to controller

App\Controller\WelcomeController:
    tags:
        - { name: 'middleware.controller', middleware: 'App\Middleware\AuthNeededMiddleware' }
        - { name: 'middleware.controller', middleware: 'App\Middleware\AdminAccessMiddleware' }

Action middleware

This middleware is similar to controller, we need to add just one more option called action

App\Controller\WelcomeController:
    tags:
        - { name: 'middleware.controller', middleware: 'App\Middleware\AuthNeededMiddleware', action: 'index' }

That means that when action index will run, than our middleware will executed

Route middleware

In your routes configuration file add array option called middleware:

index:
    path: /
    controller: App\Controller\WelcomeController::index
    options:
        middleware: ['App\Middleware\AuthNeededMiddleware', 'App\Middleware\AdminAccessMiddleware']

Those middlewares will attach to route name in our example to index.

Priority of middleware executions

Order of execution of different types of middleware is next: global middleware execute first, next controller, next action and last route.

For global middlewares you can specify in services.yaml, lets see an example

App\Middleware\AuthNeededMiddleware:
    tags:
        - { name: 'middleware.global', priority: 2 }

App\Middleware\AdminAccessMiddleware:
    tags:
        - { name: 'middleware.global', priority: 1 }

Default priority without specifying in configuration is 0. The higher the number, the earlier a middleware is executed.

For other 3 types (controller, action, route) priority will the same is in the configuration, for example in route configuration:

index:
    path: /
    controller: App\Controller\WelcomeController::index
    options:
        middleware: ['App\Middleware\AuthNeededMiddleware', 'App\Middleware\AdminAccessMiddleware']

First will execute App\Middleware\AuthNeededMiddleware and next App\Middleware\AdminAccessMiddleware. And same in other 2 types.

Middleware example

In example below, our middleware check if given credentials is represent user with admin access, if not, we will return response with access denied message.

As we can see, if any of middlewares returning Response, it means that next middlewares will not be executed.

Returning of null means that next middleware will be executed.


All versions of symfony-middleware with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.2
symfony/framework-bundle Version ^6.0
symfony/event-dispatcher Version ^6.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 zholus/symfony-middleware contains the following files

Loading the files please wait ....