f1monkey/request-handle-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Common request deserialization and exception handling

1.1.0 2020-06-30 23:57 UTC

This package is auto-updated.

Last update: 2021-08-29 02:17:07 UTC


README

Installation

$ composer require f1monkey/request-handle-bundle

Add to config/bundles.php:

<?php
return [
    // ...
    F1Monkey\RequestHandleBundle\RequestHandleBundle::class => ['all' => true],
];

Create config file (i.e. config/packages/request_handle.yaml)

Configuration

request_handle:
    value_resolver:
        # controller arguments implementing this interface will be deserialized using RequestDeserializationValueResolver
        request_class: App\Model\RequestInterface
    request_validator:
        # controller arguments implementing this interface will be validated using RequestValidationListener
        request_class: App\Model\RequestInterface
    exception_log:
        # logger service id for exception logging (default value = @logger)
        logger: 'logger'

ExceptionListener

Custom error response

If you need to customize error response, you should override exception response factory in your application's services.yaml

services:
    F1Monkey\RequestHandleBundle\Factory\ErrorResponseFactoryInterface:
        class: App\Factory\ErrorResponseFactory

Custom exception message

By default, error messages are overridden by default HTTP messages according to HTTP response code. To set a custom error message, you should implement UserFriendlyExceptionInterface in your Exception class.

X-Debug header

Because all exceptions are transformed to a "user-friendly" responses, debugging becomes harder: symfony error page will not appear at all. To show the error page, two conditions must be met:

  • kernel.debug parameter set to true (it is default setting for dev environment)
  • X-Debug header is present in the request

ExceptionLogListener

Customize logging

To customize logging you should override logger context provider service:

services:
    F1Monkey\RequestHandleBundle\Service\LogContextProviderInterface:
        class: App\Service\LogContextProvider