Download the PHP package fusonic/http-kernel-extensions without Composer

On this page you can find all versions of the php package fusonic/http-kernel-extensions. 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 http-kernel-extensions

http-kernel-extensions

License Latest Version Total Downloads php 8.1+

⚠️ Discontinuation notice ⚠️

[!WARNING] The fusonic/http-kernel-extensions package has been discontinued in favour of a dedicated Symfony bundle located at fusonic/http-kernel-bundle (see fusonic/php-http-kernel-bundle).

This package is only compatible up to and including Symfony 6.3 and will not receive any further feature updates. Please consider switching to the new bundle to benefit from future changes.

Please refer to UPGRADE-1.0.md for guidance on how to upgrade to the new bundle.

About

This library contains a variety of extensions to the Symfony HttpKernel component. See below for details on each extension this lib provides and how it works.

Currently primary development takes place at a private repository at Gitlab.com. The project on Github.com is updated regularly, but does not include any issues managed at Gitlab. However, we are happily accepting issues and pull requests on Github as well! Feel free to open an issue or merge request. If we see broader community engagement in the future, we may consider switching our primary development to Github.

Install

Use composer to install the lib from packagist.

Usage

The RequestDtoResolver

In Symfony there exists a thing called argument resolvers. They can be used to set the value of controller action arguments before the actions get called. There exists e.g. the RequestValueResolver which will inject the current request as an argument in the called action. Similar to this we created our own argument resolver, but it does a few more things than just injecting an object.

What does it do?

Our RequestDtoResolver can be used to map requests data directly to objects. Instead of manually getting all the information from your request and putting it in an object or - god forbid - passing around generic data arrays, this class will leverage the Symfony Serializer to map requests to objects and by that enable you to have custom objects to transport the request data (aka data transfer objects) from your controller to your business logic. In addition, it will also validate the resulting object with Symfony Validation if you set validation annotations.

How to use?

Supposing you are using a full Symfony setup you have to register the resolver as a service in your services.yaml as shown below to be called by Symfony.

Create your DTO like e.g. our UpdateFooDto here. All the validation stuff is optional but getters and setters are needed by the serializer.

Parameter attribute

Finally, add the DTO with the RequestDtoArgument to your controller action. Routing parameters are optional as well of course.

Class attribute

Alternatively you can also add the attribute to the DTO class itself instead of the parameter in the controller action if you prefer it this way.

Parsing and collecting data for models

By default, any json or form request body types will be parsed accordingly. To override this behaviour you could inject your own request body parsers (by implementing Fusonic\HttpKernelExtensions\Request\BodyParser\RequestBodyParserInterface) into an implementation of Fusonic\HttpKernelExtensions\Request\RequestDataCollectorInterface, which is injected into the Fusonic\HttpKernelExtensions\Controller\RequestDtoResolver. Inside the RequestDataCollectorInterface you can also modify the behaviour of how and which values are used from the Request object.

Error handling

The extension provides a default error handler (http-kernel-extensions/src/ErrorHandler/ConstraintViolationErrorHandler.php) which handles common de-normalization errors that should be considered type errors. It will create a Fusonic\HttpKernelExtensions\Exception\ConstraintViolationException ConstraintViolationException which can be used with the provided Fusonic\HttpKernelExtensions\Normalizer\ConstraintViolationExceptionNormalizer ConstraintViolationExceptionNormalizer. This normalizer is uses on Symfony's built-in Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer and enhances it with some extra information: an errorCode and messageTemplate. Both useful for parsing validation errors on the client side. If that does not match your needs you can simply provide your own error handler by implementing the Fusonic\HttpKernelExtensions\ErrorHandler\ErrorHandlerInterface and passing it to the RequestDtoResolver.

You have to register the normalizer as a service like this:

Using an exception listener/subscriber

In Symfony you can use an exception listener or subscriber to eventually convert the ConstraintViolationException into an actual response using the Fusonic\HttpKernelExtensions\Normalizer\ConstraintViolationExceptionNormalizer. For example:

Check the Events and Event Listeners for details.

ContextAwareProvider

There are cases where you want to add data to your DTOs but not through the consumer of the API but, for example, depending on the currently logged in user. You could do that manually after you received your DTO in the controller, get the user, set the user for the DTO and then move on with the processing. As you set it after the creation of the DTO you cannot work with the validation and have to make it nullable as well. And you might have to do some additional checks in your business logic afterwards to ensure everything you need is set.

Or you just create and register a provider, implement (and test) it once and be done with it. All providers will be called by the RequestDtoResolver, retrieve the needed data for the supported DTO, set it in your DTO and then the validation will take place. By the time you get it in your controller it's complete and validated. How do you do that?

  1. Create a provider and implement the two methods of the ContextAwareProvideInterface.

  2. Create the interface to mark the class you support and set the data.

  3. Implement the interface in the DTO.
  4. Finally, pass the providers into the resolver. If you are using Symfony you will be doing that in the services.yaml and it will look similar to this.

All versions of http-kernel-extensions with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
phpdocumentor/reflection-docblock Version ^5.3
symfony/http-kernel Version ^5.4|^6.0
symfony/property-access Version ^5.4|^6.0
symfony/property-info Version ^5.4|^6.0
symfony/serializer Version ^5.4.12|^6.0
symfony/validator Version ^5.4|^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 fusonic/http-kernel-extensions contains the following files

Loading the files please wait ....