Augmentation vers version 3.3.0
This commit is contained in:
52
vendor/symfony/http-kernel/Event/FilterControllerArgumentsEvent.php
vendored
Normal file
52
vendor/symfony/http-kernel/Event/FilterControllerArgumentsEvent.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Event;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
* Allows filtering of controller arguments.
|
||||
*
|
||||
* You can call getController() to retrieve the controller and getArguments
|
||||
* to retrieve the current arguments. With setArguments() you can replace
|
||||
* arguments that are used to call the controller.
|
||||
*
|
||||
* Arguments set in the event must be compatible with the signature of the
|
||||
* controller.
|
||||
*
|
||||
* @author Christophe Coevoet <stof@notk.org>
|
||||
*/
|
||||
class FilterControllerArgumentsEvent extends FilterControllerEvent
|
||||
{
|
||||
private $arguments;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, callable $controller, array $arguments, Request $request, $requestType)
|
||||
{
|
||||
parent::__construct($kernel, $controller, $request, $requestType);
|
||||
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$this->arguments = $arguments;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class FilterControllerEvent extends KernelEvent
|
||||
{
|
||||
private $controller;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, $controller, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, callable $controller, Request $request, $requestType)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
@@ -46,54 +46,8 @@ class FilterControllerEvent extends KernelEvent
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new controller.
|
||||
*
|
||||
* @param callable $controller
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function setController($controller)
|
||||
public function setController(callable $controller)
|
||||
{
|
||||
// controller must be a callable
|
||||
if (!\is_callable($controller)) {
|
||||
throw new \LogicException(sprintf('The controller must be a callable (%s given).', $this->varToString($controller)));
|
||||
}
|
||||
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
private function varToString($var)
|
||||
{
|
||||
if (\is_object($var)) {
|
||||
return sprintf('Object(%s)', \get_class($var));
|
||||
}
|
||||
|
||||
if (\is_array($var)) {
|
||||
$a = array();
|
||||
foreach ($var as $k => $v) {
|
||||
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
|
||||
}
|
||||
|
||||
return sprintf('Array(%s)', implode(', ', $a));
|
||||
}
|
||||
|
||||
if (\is_resource($var)) {
|
||||
return sprintf('Resource(%s)', get_resource_type($var));
|
||||
}
|
||||
|
||||
if (null === $var) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
if (false === $var) {
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if (true === $var) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
return (string) $var;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,11 @@ class GetResponseForExceptionEvent extends GetResponseEvent
|
||||
*/
|
||||
private $exception;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $allowCustomResponseCode = false;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
@@ -64,4 +69,22 @@ class GetResponseForExceptionEvent extends GetResponseEvent
|
||||
{
|
||||
$this->exception = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the event as allowing a custom response code.
|
||||
*/
|
||||
public function allowCustomResponseCode()
|
||||
{
|
||||
$this->allowCustomResponseCode = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the event allows a custom response code.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAllowingCustomResponseCode()
|
||||
{
|
||||
return $this->allowCustomResponseCode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user