Laravel 5.6 updates
Travis config update Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
50
vendor/symfony/http-kernel/Bundle/Bundle.php
vendored
50
vendor/symfony/http-kernel/Bundle/Bundle.php
vendored
@@ -16,7 +16,6 @@ use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
/**
|
||||
* An implementation of BundleInterface that adds a few conventions
|
||||
@@ -127,15 +126,6 @@ abstract class Bundle implements BundleInterface
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bundle parent name.
|
||||
*
|
||||
* @return string|null The Bundle parent name it overrides or null if no parent
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bundle name (the class short name).
|
||||
*
|
||||
@@ -150,48 +140,8 @@ abstract class Bundle implements BundleInterface
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and registers Commands.
|
||||
*
|
||||
* Override this method if your bundle commands do not follow the conventions:
|
||||
*
|
||||
* * Commands are in the 'Command' sub-directory
|
||||
* * Commands extend Symfony\Component\Console\Command\Command
|
||||
*/
|
||||
public function registerCommands(Application $application)
|
||||
{
|
||||
if (!is_dir($dir = $this->getPath().'/Command')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Finder\Finder')) {
|
||||
throw new \RuntimeException('You need the symfony/finder component to register bundle commands.');
|
||||
}
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->files()->name('*Command.php')->in($dir);
|
||||
|
||||
$prefix = $this->getNamespace().'\\Command';
|
||||
foreach ($finder as $file) {
|
||||
$ns = $prefix;
|
||||
if ($relativePath = $file->getRelativePath()) {
|
||||
$ns .= '\\'.str_replace('/', '\\', $relativePath);
|
||||
}
|
||||
$class = $ns.'\\'.$file->getBasename('.php');
|
||||
if ($this->container) {
|
||||
$commandIds = $this->container->hasParameter('console.command.ids') ? $this->container->getParameter('console.command.ids') : array();
|
||||
$alias = 'console.command.'.strtolower(str_replace('\\', '_', $class));
|
||||
if (isset($commandIds[$alias]) || $this->container->has($alias)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$r = new \ReflectionClass($class);
|
||||
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
|
||||
@trigger_error(sprintf('Auto-registration of the command "%s" is deprecated since Symfony 3.4 and won\'t be supported in 4.0. Use PSR-4 based service discovery instead.', $class), E_USER_DEPRECATED);
|
||||
|
||||
$application->add($r->newInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -46,19 +46,6 @@ interface BundleInterface extends ContainerAwareInterface
|
||||
*/
|
||||
public function getContainerExtension();
|
||||
|
||||
/**
|
||||
* Returns the bundle name that this bundle overrides.
|
||||
*
|
||||
* Despite its name, this method does not imply any parent/child relationship
|
||||
* between the bundles, just a way to extend and override an existing
|
||||
* bundle.
|
||||
*
|
||||
* @return string The Bundle name it overrides or null if no parent
|
||||
*
|
||||
* @deprecated This method is deprecated as of 3.4 and will be removed in 4.0.
|
||||
*/
|
||||
public function getParent();
|
||||
|
||||
/**
|
||||
* Returns the bundle name (the class short name).
|
||||
*
|
||||
|
33
vendor/symfony/http-kernel/CHANGELOG.md
vendored
33
vendor/symfony/http-kernel/CHANGELOG.md
vendored
@@ -1,6 +1,39 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
||||
* added orphaned events support to `EventDataCollector`
|
||||
* `ExceptionListener` now logs exceptions at priority `0` (previously logged at `-128`)
|
||||
* Deprecated `service:action` syntax with a single colon to reference controllers. Use `service::method` instead.
|
||||
* Added the ability to profile individual argument value resolvers via the
|
||||
`Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver`
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* removed the `DataCollector::varToString()` method, use `DataCollector::cloneVar()`
|
||||
instead
|
||||
* using the `DataCollector::cloneVar()` method requires the VarDumper component
|
||||
* removed the `ValueExporter` class
|
||||
* removed `ControllerResolverInterface::getArguments()`
|
||||
* removed `TraceableControllerResolver::getArguments()`
|
||||
* removed `ControllerResolver::getArguments()` and the ability to resolve arguments
|
||||
* removed the `argument_resolver` service dependency from the `debug.controller_resolver`
|
||||
* removed `LazyLoadingFragmentHandler::addRendererService()`
|
||||
* removed `Psr6CacheClearer::addPool()`
|
||||
* removed `Extension::addClassesToCompile()` and `Extension::getClassesToCompile()`
|
||||
* removed `Kernel::loadClassCache()`, `Kernel::doLoadClassCache()`, `Kernel::setClassCache()`,
|
||||
and `Kernel::getEnvParameters()`
|
||||
* support for the `X-Status-Code` when handling exceptions in the `HttpKernel`
|
||||
has been dropped, use the `HttpKernel::allowCustomResponseCode()` method
|
||||
instead
|
||||
* removed convention-based commands registration
|
||||
* removed the `ChainCacheClearer::add()` method
|
||||
* removed the `CacheaWarmerAggregate::add()` and `setWarmers()` methods
|
||||
* made `CacheWarmerAggregate` and `ChainCacheClearer` classes final
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
|
@@ -16,18 +16,13 @@ namespace Symfony\Component\HttpKernel\CacheClearer;
|
||||
*
|
||||
* @author Dustin Dobervich <ddobervich@gmail.com>
|
||||
*
|
||||
* @final since version 3.4
|
||||
* @final
|
||||
*/
|
||||
class ChainCacheClearer implements CacheClearerInterface
|
||||
{
|
||||
protected $clearers;
|
||||
private $clearers;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of ChainCacheClearer.
|
||||
*
|
||||
* @param array $clearers The initial clearers
|
||||
*/
|
||||
public function __construct($clearers = array())
|
||||
public function __construct(iterable $clearers = array())
|
||||
{
|
||||
$this->clearers = $clearers;
|
||||
}
|
||||
@@ -41,16 +36,4 @@ class ChainCacheClearer implements CacheClearerInterface
|
||||
$clearer->clear($cacheDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a cache clearer to the aggregate.
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
|
||||
*/
|
||||
public function add(CacheClearerInterface $clearer)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->clearers[] = $clearer;
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\CacheClearer;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
@@ -25,18 +23,20 @@ class Psr6CacheClearer implements CacheClearerInterface
|
||||
$this->pools = $pools;
|
||||
}
|
||||
|
||||
public function addPool(CacheItemPoolInterface $pool)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->pools[] = $pool;
|
||||
}
|
||||
|
||||
public function hasPool($name)
|
||||
{
|
||||
return isset($this->pools[$name]);
|
||||
}
|
||||
|
||||
public function getPool($name)
|
||||
{
|
||||
if (!$this->hasPool($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('Cache pool not found: %s.', $name));
|
||||
}
|
||||
|
||||
return $this->pools[$name];
|
||||
}
|
||||
|
||||
public function clearPool($name)
|
||||
{
|
||||
if (!isset($this->pools[$name])) {
|
||||
|
@@ -16,20 +16,17 @@ namespace Symfony\Component\HttpKernel\CacheWarmer;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final since version 3.4
|
||||
* @final
|
||||
*/
|
||||
class CacheWarmerAggregate implements CacheWarmerInterface
|
||||
{
|
||||
protected $warmers = array();
|
||||
protected $optionalsEnabled = false;
|
||||
private $triggerDeprecation = false;
|
||||
private $warmers;
|
||||
private $optionalsEnabled = false;
|
||||
private $onlyOptionalsEnabled = false;
|
||||
|
||||
public function __construct($warmers = array())
|
||||
public function __construct(iterable $warmers = array())
|
||||
{
|
||||
foreach ($warmers as $warmer) {
|
||||
$this->add($warmer);
|
||||
}
|
||||
$this->triggerDeprecation = true;
|
||||
$this->warmers = $warmers;
|
||||
}
|
||||
|
||||
public function enableOptionalWarmers()
|
||||
@@ -37,6 +34,11 @@ class CacheWarmerAggregate implements CacheWarmerInterface
|
||||
$this->optionalsEnabled = true;
|
||||
}
|
||||
|
||||
public function enableOnlyOptionalWarmers()
|
||||
{
|
||||
$this->onlyOptionalsEnabled = $this->optionalsEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warms up the cache.
|
||||
*
|
||||
@@ -48,6 +50,9 @@ class CacheWarmerAggregate implements CacheWarmerInterface
|
||||
if (!$this->optionalsEnabled && $warmer->isOptional()) {
|
||||
continue;
|
||||
}
|
||||
if ($this->onlyOptionalsEnabled && !$warmer->isOptional()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$warmer->warmUp($cacheDir);
|
||||
}
|
||||
@@ -62,29 +67,4 @@ class CacheWarmerAggregate implements CacheWarmerInterface
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
|
||||
*/
|
||||
public function setWarmers(array $warmers)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->warmers = array();
|
||||
foreach ($warmers as $warmer) {
|
||||
$this->add($warmer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
|
||||
*/
|
||||
public function add(CacheWarmerInterface $warmer)
|
||||
{
|
||||
if ($this->triggerDeprecation) {
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->warmers[] = $warmer;
|
||||
}
|
||||
}
|
||||
|
6
vendor/symfony/http-kernel/Client.php
vendored
6
vendor/symfony/http-kernel/Client.php
vendored
@@ -25,8 +25,8 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @method Request|null getRequest() A Request instance
|
||||
* @method Response|null getResponse() A Response instance
|
||||
* @method Request getRequest() A Request instance
|
||||
* @method Response getResponse() A Response instance
|
||||
*/
|
||||
class Client extends BaseClient
|
||||
{
|
||||
@@ -168,7 +168,6 @@ EOF;
|
||||
'',
|
||||
$value->getClientOriginalName(),
|
||||
$value->getClientMimeType(),
|
||||
0,
|
||||
UPLOAD_ERR_INI_SIZE,
|
||||
true
|
||||
);
|
||||
@@ -177,7 +176,6 @@ EOF;
|
||||
$value->getPathname(),
|
||||
$value->getClientOriginalName(),
|
||||
$value->getClientMimeType(),
|
||||
$value->getClientSize(),
|
||||
$value->getError(),
|
||||
true
|
||||
);
|
||||
|
@@ -1,99 +0,0 @@
|
||||
<?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\Config;
|
||||
|
||||
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
|
||||
|
||||
/**
|
||||
* EnvParametersResource represents resources stored in prefixed environment variables.
|
||||
*
|
||||
* @author Chris Wilkinson <chriswilkinson84@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0
|
||||
*/
|
||||
class EnvParametersResource implements SelfCheckingResourceInterface, \Serializable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $prefix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $variables;
|
||||
|
||||
/**
|
||||
* @param string $prefix
|
||||
*/
|
||||
public function __construct($prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
$this->variables = $this->findVariables();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return serialize($this->getResource());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array An array with two keys: 'prefix' for the prefix used and 'variables' containing all the variables watched by this resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return array('prefix' => $this->prefix, 'variables' => $this->variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFresh($timestamp)
|
||||
{
|
||||
return $this->findVariables() === $this->variables;
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array('prefix' => $this->prefix, 'variables' => $this->variables));
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
$unserialized = unserialize($serialized, array('allowed_classes' => false));
|
||||
} else {
|
||||
$unserialized = unserialize($serialized);
|
||||
}
|
||||
|
||||
$this->prefix = $unserialized['prefix'];
|
||||
$this->variables = $unserialized['variables'];
|
||||
}
|
||||
|
||||
private function findVariables()
|
||||
{
|
||||
$variables = array();
|
||||
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
if (0 === strpos($key, $this->prefix)) {
|
||||
$variables[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($variables);
|
||||
|
||||
return $variables;
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ class FileLocator extends BaseFileLocator
|
||||
* @param null|string $path The path the global resource directory
|
||||
* @param array $paths An array of paths where to look for resources
|
||||
*/
|
||||
public function __construct(KernelInterface $kernel, $path = null, array $paths = array())
|
||||
public function __construct(KernelInterface $kernel, string $path = null, array $paths = array())
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
if (null !== $path) {
|
||||
|
@@ -34,7 +34,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
|
||||
*/
|
||||
private $argumentValueResolvers;
|
||||
|
||||
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = array())
|
||||
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, iterable $argumentValueResolvers = array())
|
||||
{
|
||||
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
|
||||
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();
|
||||
@@ -81,7 +81,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
public static function getDefaultArgumentValueResolvers()
|
||||
public static function getDefaultArgumentValueResolvers(): iterable
|
||||
{
|
||||
return array(
|
||||
new RequestAttributeValueResolver(),
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
@@ -63,6 +64,21 @@ final class ServiceValueResolver implements ArgumentValueResolverInterface
|
||||
$controller = ltrim($controller, '\\');
|
||||
}
|
||||
|
||||
yield $this->container->get($controller)->get($argument->getName());
|
||||
try {
|
||||
yield $this->container->get($controller)->get($argument->getName());
|
||||
} catch (RuntimeException $e) {
|
||||
$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);
|
||||
$message = preg_replace('/service "\.service_locator\.[^"]++"/', $what, $e->getMessage());
|
||||
|
||||
if ($e->getMessage() === $message) {
|
||||
$message = sprintf('Cannot resolve %s: %s', $what, $message);
|
||||
}
|
||||
|
||||
$r = new \ReflectionProperty($e, 'message');
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($e, $message);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,10 @@ final class SessionValueResolver implements ArgumentValueResolverInterface
|
||||
*/
|
||||
public function supports(Request $request, ArgumentMetadata $argument)
|
||||
{
|
||||
if (!$request->hasSession()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $argument->getType();
|
||||
if (SessionInterface::class !== $type && !is_subclass_of($type, SessionInterface::class)) {
|
||||
return false;
|
||||
|
62
vendor/symfony/http-kernel/Controller/ArgumentResolver/TraceableValueResolver.php
vendored
Normal file
62
vendor/symfony/http-kernel/Controller/ArgumentResolver/TraceableValueResolver.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Controller\ArgumentResolver;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
* Provides timing information via the stopwatch.
|
||||
*
|
||||
* @author Iltar van der Berg <kjarli@gmail.com>
|
||||
*/
|
||||
final class TraceableValueResolver implements ArgumentValueResolverInterface
|
||||
{
|
||||
private $inner;
|
||||
private $stopwatch;
|
||||
|
||||
public function __construct(ArgumentValueResolverInterface $inner, Stopwatch $stopwatch)
|
||||
{
|
||||
$this->inner = $inner;
|
||||
$this->stopwatch = $stopwatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports(Request $request, ArgumentMetadata $argument): bool
|
||||
{
|
||||
$method = \get_class($this->inner).'::'.__FUNCTION__;
|
||||
$this->stopwatch->start($method);
|
||||
|
||||
$return = $this->inner->supports($request, $argument);
|
||||
|
||||
$this->stopwatch->stop($method);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function resolve(Request $request, ArgumentMetadata $argument): iterable
|
||||
{
|
||||
$method = \get_class($this->inner).'::'.__FUNCTION__;
|
||||
$this->stopwatch->start($method);
|
||||
|
||||
yield from $this->inner->resolve($request, $argument);
|
||||
|
||||
$this->stopwatch->stop($method);
|
||||
}
|
||||
}
|
@@ -14,7 +14,6 @@ namespace Symfony\Component\HttpKernel\Controller;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* A controller resolver searching for a controller in a psr-11 container when using the "service:method" notation.
|
||||
@@ -33,58 +32,14 @@ class ContainerControllerResolver extends ControllerResolver
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getController(Request $request)
|
||||
{
|
||||
$controller = parent::getController($request);
|
||||
|
||||
if (\is_array($controller) && isset($controller[0]) && \is_string($controller[0]) && $this->container->has($controller[0])) {
|
||||
$controller[0] = $this->instantiateController($controller[0]);
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a callable for the given controller.
|
||||
*
|
||||
* @param string $controller A Controller string
|
||||
*
|
||||
* @return mixed A PHP callable
|
||||
*
|
||||
* @throws \LogicException When the name could not be parsed
|
||||
* @throws \InvalidArgumentException When the controller class does not exist
|
||||
*/
|
||||
protected function createController($controller)
|
||||
{
|
||||
if (false !== strpos($controller, '::')) {
|
||||
return parent::createController($controller);
|
||||
if (1 === substr_count($controller, ':')) {
|
||||
$controller = str_replace(':', '::', $controller);
|
||||
@trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1. Use %s instead.', $controller), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$method = null;
|
||||
if (1 == substr_count($controller, ':')) {
|
||||
// controller in the "service:method" notation
|
||||
list($controller, $method) = explode(':', $controller, 2);
|
||||
}
|
||||
|
||||
if (!$this->container->has($controller)) {
|
||||
$this->throwExceptionIfControllerWasRemoved($controller);
|
||||
|
||||
throw new \LogicException(sprintf('Controller not found: service "%s" does not exist.', $controller));
|
||||
}
|
||||
|
||||
$service = $this->container->get($controller);
|
||||
if (null !== $method) {
|
||||
return array($service, $method);
|
||||
}
|
||||
|
||||
if (!method_exists($service, '__invoke')) {
|
||||
throw new \LogicException(sprintf('Controller "%s" cannot be called without a method name. Did you forget an "__invoke" method?', $controller));
|
||||
}
|
||||
|
||||
return $service;
|
||||
return parent::createController($controller);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,24 +53,22 @@ class ContainerControllerResolver extends ControllerResolver
|
||||
|
||||
try {
|
||||
return parent::instantiateController($class);
|
||||
} catch (\ArgumentCountError $e) {
|
||||
} catch (\ErrorException $e) {
|
||||
} catch (\TypeError $e) {
|
||||
} catch (\Error $e) {
|
||||
}
|
||||
|
||||
$this->throwExceptionIfControllerWasRemoved($class, $e);
|
||||
|
||||
throw $e;
|
||||
if ($e instanceof \ArgumentCountError) {
|
||||
throw new \InvalidArgumentException(sprintf('Controller "%s" has required constructor arguments and does not exist in the container. Did you forget to define such a service?', $class), 0, $e);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Controller "%s" does neither exist as service nor as class', $class), 0, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $controller
|
||||
* @param \Exception|\Throwable|null $previous
|
||||
*/
|
||||
private function throwExceptionIfControllerWasRemoved($controller, $previous = null)
|
||||
private function throwExceptionIfControllerWasRemoved(string $controller, \Throwable $previous)
|
||||
{
|
||||
if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controller])) {
|
||||
throw new \LogicException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $controller), 0, $previous);
|
||||
throw new \InvalidArgumentException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $controller), 0, $previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ class ControllerReference
|
||||
* @param array $attributes An array of parameters to add to the Request attributes
|
||||
* @param array $query An array of parameters to add to the Request query string
|
||||
*/
|
||||
public function __construct($controller, array $attributes = array(), array $query = array())
|
||||
public function __construct(string $controller, array $attributes = array(), array $query = array())
|
||||
{
|
||||
$this->controller = $controller;
|
||||
$this->attributes = $attributes;
|
||||
|
@@ -16,44 +16,22 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* This implementation uses the '_controller' request attribute to determine
|
||||
* the controller to execute and uses the request attributes to determine
|
||||
* the controller method arguments.
|
||||
* the controller to execute.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
class ControllerResolver implements ArgumentResolverInterface, ControllerResolverInterface
|
||||
class ControllerResolver implements ControllerResolverInterface
|
||||
{
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* If the ...$arg functionality is available.
|
||||
*
|
||||
* Requires at least PHP 5.6.0 or HHVM 3.9.1
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsVariadic;
|
||||
|
||||
/**
|
||||
* If scalar types exists.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsScalarTypes;
|
||||
|
||||
public function __construct(LoggerInterface $logger = null)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
|
||||
$this->supportsScalarTypes = method_exists('ReflectionParameter', 'getType');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* This method looks for a '_controller' request attribute that represents
|
||||
* the controller name (a string like ClassName::MethodName).
|
||||
*/
|
||||
public function getController(Request $request)
|
||||
{
|
||||
@@ -66,23 +44,42 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
|
||||
}
|
||||
|
||||
if (\is_array($controller)) {
|
||||
if (isset($controller[0]) && \is_string($controller[0]) && isset($controller[1])) {
|
||||
try {
|
||||
$controller[0] = $this->instantiateController($controller[0]);
|
||||
} catch (\Error | \LogicException $e) {
|
||||
try {
|
||||
// We cannot just check is_callable but have to use reflection because a non-static method
|
||||
// can still be called statically in PHP but we don't want that. This is deprecated in PHP 7, so we
|
||||
// could simplify this with PHP 8.
|
||||
if ((new \ReflectionMethod($controller[0], $controller[1]))->isStatic()) {
|
||||
return $controller;
|
||||
}
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
if (!\is_callable($controller)) {
|
||||
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($controller)));
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
if (\is_object($controller)) {
|
||||
if (method_exists($controller, '__invoke')) {
|
||||
return $controller;
|
||||
if (!\is_callable($controller)) {
|
||||
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($controller)));
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', \get_class($controller), $request->getPathInfo()));
|
||||
return $controller;
|
||||
}
|
||||
|
||||
if (false === strpos($controller, ':')) {
|
||||
if (method_exists($controller, '__invoke')) {
|
||||
return $this->instantiateController($controller);
|
||||
} elseif (\function_exists($controller)) {
|
||||
return $controller;
|
||||
}
|
||||
if (\function_exists($controller)) {
|
||||
return $controller;
|
||||
}
|
||||
|
||||
$callable = $this->createController($controller);
|
||||
@@ -94,93 +91,34 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
|
||||
return $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface and inject it in the HttpKernel instead.
|
||||
*/
|
||||
public function getArguments(Request $request, $controller)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated as of 3.1 and will be removed in 4.0. Implement the %s and inject it in the HttpKernel instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
|
||||
|
||||
if (\is_array($controller)) {
|
||||
$r = new \ReflectionMethod($controller[0], $controller[1]);
|
||||
} elseif (\is_object($controller) && !$controller instanceof \Closure) {
|
||||
$r = new \ReflectionObject($controller);
|
||||
$r = $r->getMethod('__invoke');
|
||||
} else {
|
||||
$r = new \ReflectionFunction($controller);
|
||||
}
|
||||
|
||||
return $this->doGetArguments($request, $controller, $r->getParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param callable $controller
|
||||
* @param \ReflectionParameter[] $parameters
|
||||
*
|
||||
* @return array The arguments to use when calling the action
|
||||
*
|
||||
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Implement the ArgumentResolverInterface and inject it in the HttpKernel instead.
|
||||
*/
|
||||
protected function doGetArguments(Request $request, $controller, array $parameters)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated as of 3.1 and will be removed in 4.0. Implement the %s and inject it in the HttpKernel instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
|
||||
|
||||
$attributes = $request->attributes->all();
|
||||
$arguments = array();
|
||||
foreach ($parameters as $param) {
|
||||
if (array_key_exists($param->name, $attributes)) {
|
||||
if ($this->supportsVariadic && $param->isVariadic() && \is_array($attributes[$param->name])) {
|
||||
$arguments = array_merge($arguments, array_values($attributes[$param->name]));
|
||||
} else {
|
||||
$arguments[] = $attributes[$param->name];
|
||||
}
|
||||
} elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
|
||||
$arguments[] = $request;
|
||||
} elseif ($param->isDefaultValueAvailable()) {
|
||||
$arguments[] = $param->getDefaultValue();
|
||||
} elseif ($this->supportsScalarTypes && $param->hasType() && $param->allowsNull()) {
|
||||
$arguments[] = null;
|
||||
} else {
|
||||
if (\is_array($controller)) {
|
||||
$repr = sprintf('%s::%s()', \get_class($controller[0]), $controller[1]);
|
||||
} elseif (\is_object($controller)) {
|
||||
$repr = \get_class($controller);
|
||||
} else {
|
||||
$repr = $controller;
|
||||
}
|
||||
|
||||
throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param->name));
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a callable for the given controller.
|
||||
*
|
||||
* @param string $controller A Controller string
|
||||
*
|
||||
* @return callable A PHP callable
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function createController($controller)
|
||||
{
|
||||
if (false === strpos($controller, '::')) {
|
||||
throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".', $controller));
|
||||
return $this->instantiateController($controller);
|
||||
}
|
||||
|
||||
list($class, $method) = explode('::', $controller, 2);
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||
}
|
||||
try {
|
||||
return array($this->instantiateController($class), $method);
|
||||
} catch (\Error | \LogicException $e) {
|
||||
try {
|
||||
if ((new \ReflectionMethod($class, $method))->isStatic()) {
|
||||
return $class.'::'.$method;
|
||||
}
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return array($this->instantiateController($class), $method);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,24 +137,25 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
|
||||
{
|
||||
if (\is_string($callable)) {
|
||||
if (false !== strpos($callable, '::')) {
|
||||
$callable = explode('::', $callable);
|
||||
}
|
||||
|
||||
if (class_exists($callable) && !method_exists($callable, '__invoke')) {
|
||||
return sprintf('Class "%s" does not have a method "__invoke".', $callable);
|
||||
}
|
||||
|
||||
if (!\function_exists($callable)) {
|
||||
$callable = explode('::', $callable, 2);
|
||||
} else {
|
||||
return sprintf('Function "%s" does not exist.', $callable);
|
||||
}
|
||||
}
|
||||
|
||||
if (!\is_array($callable)) {
|
||||
return sprintf('Invalid type for controller given, expected string or array, got "%s".', \gettype($callable));
|
||||
if (\is_object($callable)) {
|
||||
$availableMethods = $this->getClassMethodsWithoutMagicMethods($callable);
|
||||
$alternativeMsg = $availableMethods ? sprintf(' or use one of the available methods: "%s"', implode('", "', $availableMethods)) : '';
|
||||
|
||||
return sprintf('Controller class "%s" cannot be called without a method name. You need to implement "__invoke"%s.', \get_class($callable), $alternativeMsg);
|
||||
}
|
||||
|
||||
if (2 !== \count($callable)) {
|
||||
return 'Invalid format for controller, expected array(controller, method) or controller::method.';
|
||||
if (!\is_array($callable)) {
|
||||
return sprintf('Invalid type for controller given, expected string, array or object, got "%s".', \gettype($callable));
|
||||
}
|
||||
|
||||
if (!isset($callable[0]) || !isset($callable[1]) || 2 !== \count($callable)) {
|
||||
return 'Invalid array callable, expected array(controller, method).';
|
||||
}
|
||||
|
||||
list($controller, $method) = $callable;
|
||||
@@ -231,7 +170,7 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
|
||||
return sprintf('Method "%s" on class "%s" should be public and non-abstract.', $method, $className);
|
||||
}
|
||||
|
||||
$collection = get_class_methods($controller);
|
||||
$collection = $this->getClassMethodsWithoutMagicMethods($controller);
|
||||
|
||||
$alternatives = array();
|
||||
|
||||
@@ -255,4 +194,13 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
private function getClassMethodsWithoutMagicMethods($classOrObject)
|
||||
{
|
||||
$methods = get_class_methods($classOrObject);
|
||||
|
||||
return array_filter($methods, function (string $method) {
|
||||
return 0 !== strncmp($method, '__', 2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -17,8 +17,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
* A ControllerResolverInterface implementation knows how to determine the
|
||||
* controller to execute based on a Request object.
|
||||
*
|
||||
* It can also determine the arguments to pass to the Controller.
|
||||
*
|
||||
* A Controller can be any valid PHP callable.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
@@ -37,21 +35,7 @@ interface ControllerResolverInterface
|
||||
* @return callable|false A PHP callable representing the Controller,
|
||||
* or false if this resolver is not able to determine the controller
|
||||
*
|
||||
* @throws \LogicException If the controller can't be found
|
||||
* @throws \LogicException If a controller was found based on the request but it is not callable
|
||||
*/
|
||||
public function getController(Request $request);
|
||||
|
||||
/**
|
||||
* Returns the arguments to pass to the controller.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
* @param callable $controller A PHP callable
|
||||
*
|
||||
* @return array An array of arguments to pass to the controller
|
||||
*
|
||||
* @throws \RuntimeException When value for argument given is not provided
|
||||
*
|
||||
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0. Please use the {@see ArgumentResolverInterface} instead.
|
||||
*/
|
||||
public function getArguments(Request $request, $controller);
|
||||
}
|
||||
|
@@ -17,26 +17,15 @@ use Symfony\Component\Stopwatch\Stopwatch;
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TraceableControllerResolver implements ControllerResolverInterface, ArgumentResolverInterface
|
||||
class TraceableControllerResolver implements ControllerResolverInterface
|
||||
{
|
||||
private $resolver;
|
||||
private $stopwatch;
|
||||
private $argumentResolver;
|
||||
|
||||
public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch, ArgumentResolverInterface $argumentResolver = null)
|
||||
public function __construct(ControllerResolverInterface $resolver, Stopwatch $stopwatch)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->argumentResolver = $argumentResolver;
|
||||
|
||||
// BC
|
||||
if (null === $this->argumentResolver) {
|
||||
$this->argumentResolver = $resolver;
|
||||
}
|
||||
|
||||
if (!$this->argumentResolver instanceof TraceableArgumentResolver) {
|
||||
$this->argumentResolver = new TraceableArgumentResolver($this->argumentResolver, $this->stopwatch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,18 +41,4 @@ class TraceableControllerResolver implements ControllerResolverInterface, Argume
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated This method is deprecated as of 3.1 and will be removed in 4.0.
|
||||
*/
|
||||
public function getArguments(Request $request, $controller)
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated as of 3.1 and will be removed in 4.0. Please use the %s instead.', __METHOD__, TraceableArgumentResolver::class), E_USER_DEPRECATED);
|
||||
|
||||
$ret = $this->argumentResolver->getArguments($request, $controller);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
@@ -25,15 +25,7 @@ class ArgumentMetadata
|
||||
private $defaultValue;
|
||||
private $isNullable;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param bool $isVariadic
|
||||
* @param bool $hasDefaultValue
|
||||
* @param mixed $defaultValue
|
||||
* @param bool $isNullable
|
||||
*/
|
||||
public function __construct($name, $type, $isVariadic, $hasDefaultValue, $defaultValue, $isNullable = false)
|
||||
public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
|
@@ -18,30 +18,6 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
*/
|
||||
final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* If the ...$arg functionality is available.
|
||||
*
|
||||
* Requires at least PHP 5.6.0 or HHVM 3.9.1
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsVariadic;
|
||||
|
||||
/**
|
||||
* If the reflection supports the getType() method to resolve types.
|
||||
*
|
||||
* Requires at least PHP 7.0.0 or HHVM 3.11.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsParameterType;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
|
||||
$this->supportsParameterType = method_exists('ReflectionParameter', 'getType');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -58,48 +34,12 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
}
|
||||
|
||||
foreach ($reflection->getParameters() as $param) {
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull());
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull());
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an argument is variadic.
|
||||
*
|
||||
* @param \ReflectionParameter $parameter
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isVariadic(\ReflectionParameter $parameter)
|
||||
{
|
||||
return $this->supportsVariadic && $parameter->isVariadic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an argument has a default value.
|
||||
*
|
||||
* @param \ReflectionParameter $parameter
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasDefaultValue(\ReflectionParameter $parameter)
|
||||
{
|
||||
return $parameter->isDefaultValueAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a default value if available.
|
||||
*
|
||||
* @param \ReflectionParameter $parameter
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
private function getDefaultValue(\ReflectionParameter $parameter)
|
||||
{
|
||||
return $this->hasDefaultValue($parameter) ? $parameter->getDefaultValue() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associated type to the given parameter if available.
|
||||
*
|
||||
@@ -109,20 +49,10 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
*/
|
||||
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
|
||||
{
|
||||
if ($this->supportsParameterType) {
|
||||
if (!$type = $parameter->getType()) {
|
||||
return;
|
||||
}
|
||||
$name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
|
||||
if ('array' === $name && !$type->isBuiltin()) {
|
||||
// Special case for HHVM with variadics
|
||||
return;
|
||||
}
|
||||
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $name)) {
|
||||
$name = $name[1];
|
||||
} else {
|
||||
if (!$type = $parameter->getType()) {
|
||||
return;
|
||||
}
|
||||
$name = $type->getName();
|
||||
$lcName = strtolower($name);
|
||||
|
||||
if ('self' !== $lcName && 'parent' !== $lcName) {
|
||||
|
@@ -34,7 +34,7 @@ class ConfigDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
* @param string $name The name of the application using the web profiler
|
||||
* @param string $version The version of the application using the web profiler
|
||||
*/
|
||||
public function __construct($name = null, $version = null)
|
||||
public function __construct(string $name = null, string $version = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->version = $version;
|
||||
|
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DataCollector;
|
||||
|
||||
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
|
||||
use Symfony\Component\VarDumper\Caster\CutStub;
|
||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
@@ -30,11 +29,6 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable
|
||||
{
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* @var ValueExporter
|
||||
*/
|
||||
private $valueExporter;
|
||||
|
||||
/**
|
||||
* @var ClonerInterface
|
||||
*/
|
||||
@@ -66,46 +60,17 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable
|
||||
return $var;
|
||||
}
|
||||
if (null === $this->cloner) {
|
||||
if (class_exists(CutStub::class)) {
|
||||
$this->cloner = new VarCloner();
|
||||
$this->cloner->setMaxItems(-1);
|
||||
$this->cloner->addCasters($this->getCasters());
|
||||
} else {
|
||||
@trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since Symfony 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), E_USER_DEPRECATED);
|
||||
$this->cloner = false;
|
||||
if (!class_exists(CutStub::class)) {
|
||||
throw new \LogicException(sprintf('The VarDumper component is needed for the %s() method. Install symfony/var-dumper version 3.4 or above.', __METHOD__));
|
||||
}
|
||||
}
|
||||
if (false === $this->cloner) {
|
||||
if (null === $this->valueExporter) {
|
||||
$this->valueExporter = new ValueExporter();
|
||||
}
|
||||
|
||||
return $this->valueExporter->exportValue($var);
|
||||
$this->cloner = new VarCloner();
|
||||
$this->cloner->setMaxItems(-1);
|
||||
$this->cloner->addCasters($this->getCasters());
|
||||
}
|
||||
|
||||
return $this->cloner->cloneVar($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a PHP variable to a string.
|
||||
*
|
||||
* @param mixed $var A PHP variable
|
||||
*
|
||||
* @return string The string representation of the variable
|
||||
*
|
||||
* @deprecated since version 3.2, to be removed in 4.0. Use cloneVar() instead.
|
||||
*/
|
||||
protected function varToString($var)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use cloneVar() instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
if (null === $this->valueExporter) {
|
||||
$this->valueExporter = new ValueExporter();
|
||||
}
|
||||
|
||||
return $this->valueExporter->exportValue($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return callable[] The casters to add to the cloner
|
||||
*/
|
||||
|
@@ -18,8 +18,6 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
* DataCollectorInterface.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @method reset() Resets this data collector to its initial state.
|
||||
*/
|
||||
interface DataCollectorInterface
|
||||
{
|
||||
@@ -34,4 +32,9 @@ interface DataCollectorInterface
|
||||
* @return string The collector name
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Resets this data collector to its initial state.
|
||||
*/
|
||||
public function reset();
|
||||
}
|
||||
|
@@ -18,9 +18,10 @@ use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider;
|
||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
use Twig\Template;
|
||||
use Symfony\Component\VarDumper\Server\Connection;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
@@ -37,16 +38,18 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
private $charset;
|
||||
private $requestStack;
|
||||
private $dumper;
|
||||
private $dumperIsInjected;
|
||||
private $sourceContextProvider;
|
||||
|
||||
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, $charset = null, RequestStack $requestStack = null, DataDumperInterface $dumper = null)
|
||||
/**
|
||||
* @param DataDumperInterface|Connection|null $dumper
|
||||
*/
|
||||
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, $dumper = null)
|
||||
{
|
||||
$this->stopwatch = $stopwatch;
|
||||
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
|
||||
$this->requestStack = $requestStack;
|
||||
$this->dumper = $dumper;
|
||||
$this->dumperIsInjected = null !== $dumper;
|
||||
|
||||
// All clones share these properties by reference:
|
||||
$this->rootRefs = array(
|
||||
@@ -55,6 +58,8 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
&$this->isCollected,
|
||||
&$this->clonesCount,
|
||||
);
|
||||
|
||||
$this->sourceContextProvider = $dumper instanceof Connection && isset($dumper->getContextProviders()['source']) ? $dumper->getContextProviders()['source'] : new SourceContextProvider($this->charset);
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
@@ -67,65 +72,17 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
if ($this->stopwatch) {
|
||||
$this->stopwatch->start('dump');
|
||||
}
|
||||
if ($this->isCollected && !$this->dumper) {
|
||||
$this->isCollected = false;
|
||||
}
|
||||
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 7);
|
||||
list('name' => $name, 'file' => $file, 'line' => $line, 'file_excerpt' => $fileExcerpt) = $this->sourceContextProvider->getContext();
|
||||
|
||||
$file = $trace[0]['file'];
|
||||
$line = $trace[0]['line'];
|
||||
$name = false;
|
||||
$fileExcerpt = false;
|
||||
|
||||
for ($i = 1; $i < 7; ++$i) {
|
||||
if (isset($trace[$i]['class'], $trace[$i]['function'])
|
||||
&& 'dump' === $trace[$i]['function']
|
||||
&& 'Symfony\Component\VarDumper\VarDumper' === $trace[$i]['class']
|
||||
) {
|
||||
$file = $trace[$i]['file'];
|
||||
$line = $trace[$i]['line'];
|
||||
|
||||
while (++$i < 7) {
|
||||
if (isset($trace[$i]['function'], $trace[$i]['file']) && empty($trace[$i]['class']) && 0 !== strpos($trace[$i]['function'], 'call_user_func')) {
|
||||
$file = $trace[$i]['file'];
|
||||
$line = $trace[$i]['line'];
|
||||
|
||||
break;
|
||||
} elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof Template) {
|
||||
$template = $trace[$i]['object'];
|
||||
$name = $template->getTemplateName();
|
||||
$src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
|
||||
$info = $template->getDebugInfo();
|
||||
if (isset($info[$trace[$i - 1]['line']])) {
|
||||
$line = $info[$trace[$i - 1]['line']];
|
||||
$file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null;
|
||||
|
||||
if ($src) {
|
||||
$src = explode("\n", $src);
|
||||
$fileExcerpt = array();
|
||||
|
||||
for ($i = max($line - 3, 1), $max = min($line + 3, \count($src)); $i <= $max; ++$i) {
|
||||
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
|
||||
}
|
||||
|
||||
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
if ($this->dumper instanceof Connection) {
|
||||
if (!$this->dumper->write($data)) {
|
||||
$this->isCollected = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $name) {
|
||||
$name = str_replace('\\', '/', $file);
|
||||
$name = substr($name, strrpos($name, '/') + 1);
|
||||
}
|
||||
|
||||
if ($this->dumper) {
|
||||
$this->doDump($data, $name, $file, $line);
|
||||
} elseif ($this->dumper) {
|
||||
$this->doDump($this->dumper, $data, $name, $file, $line);
|
||||
} else {
|
||||
$this->isCollected = false;
|
||||
}
|
||||
|
||||
$this->data[] = compact('data', 'name', 'file', 'line', 'fileExcerpt');
|
||||
@@ -152,14 +109,14 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
|| false === strripos($response->getContent(), '</body>')
|
||||
) {
|
||||
if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
|
||||
$this->dumper = new HtmlDumper('php://output', $this->charset);
|
||||
$this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
$dumper = new HtmlDumper('php://output', $this->charset);
|
||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
} else {
|
||||
$this->dumper = new CliDumper('php://output', $this->charset);
|
||||
$dumper = new CliDumper('php://output', $this->charset);
|
||||
}
|
||||
|
||||
foreach ($this->data as $dump) {
|
||||
$this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
|
||||
$this->doDump($dumper, $dump['data'], $dump['name'], $dump['file'], $dump['line']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,9 +145,6 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
$this->data = array();
|
||||
$this->dataCount = 0;
|
||||
$this->isCollected = true;
|
||||
if (!$this->dumperIsInjected) {
|
||||
$this->dumper = null;
|
||||
}
|
||||
|
||||
return $ser;
|
||||
}
|
||||
@@ -251,15 +205,15 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
}
|
||||
|
||||
if (!\in_array(\PHP_SAPI, array('cli', 'phpdbg'), true) && stripos($h[$i], 'html')) {
|
||||
$this->dumper = new HtmlDumper('php://output', $this->charset);
|
||||
$this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
$dumper = new HtmlDumper('php://output', $this->charset);
|
||||
$dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
|
||||
} else {
|
||||
$this->dumper = new CliDumper('php://output', $this->charset);
|
||||
$dumper = new CliDumper('php://output', $this->charset);
|
||||
}
|
||||
|
||||
foreach ($this->data as $i => $dump) {
|
||||
$this->data[$i] = null;
|
||||
$this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
|
||||
$this->doDump($dumper, $dump['data'], $dump['name'], $dump['file'], $dump['line']);
|
||||
}
|
||||
|
||||
$this->data = array();
|
||||
@@ -267,9 +221,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function doDump($data, $name, $file, $line)
|
||||
private function doDump(DataDumperInterface $dumper, $data, $name, $file, $line)
|
||||
{
|
||||
if ($this->dumper instanceof CliDumper) {
|
||||
if ($dumper instanceof CliDumper) {
|
||||
$contextDumper = function ($name, $file, $line, $fmt) {
|
||||
if ($this instanceof HtmlDumper) {
|
||||
if ($file) {
|
||||
@@ -290,26 +244,12 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
}
|
||||
$this->dumpLine(0);
|
||||
};
|
||||
$contextDumper = $contextDumper->bindTo($this->dumper, $this->dumper);
|
||||
$contextDumper = $contextDumper->bindTo($dumper, $dumper);
|
||||
$contextDumper($name, $file, $line, $this->fileLinkFormat);
|
||||
} else {
|
||||
$cloner = new VarCloner();
|
||||
$this->dumper->dump($cloner->cloneVar($name.' on line '.$line.':'));
|
||||
$dumper->dump($cloner->cloneVar($name.' on line '.$line.':'));
|
||||
}
|
||||
$this->dumper->dump($data);
|
||||
}
|
||||
|
||||
private function htmlEncode($s)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
$dumper = new HtmlDumper(function ($line) use (&$html) { $html .= $line; }, $this->charset);
|
||||
$dumper->setDumpHeader('');
|
||||
$dumper->setDumpBoundaries('', '');
|
||||
|
||||
$cloner = new VarCloner();
|
||||
$dumper->dump($cloner->cloneVar($s));
|
||||
|
||||
return substr(strip_tags($html), 1, -1);
|
||||
$dumper->dump($data);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DataCollector;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -27,9 +28,6 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
if ($dispatcher instanceof TraceableEventDispatcherInterface && !method_exists($dispatcher, 'reset')) {
|
||||
@trigger_error(sprintf('Implementing "%s" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', TraceableEventDispatcherInterface::class, \get_class($dispatcher)), E_USER_DEPRECATED);
|
||||
}
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
@@ -41,6 +39,7 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
$this->data = array(
|
||||
'called_listeners' => array(),
|
||||
'not_called_listeners' => array(),
|
||||
'orphaned_events' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,10 +48,6 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
$this->data = array();
|
||||
|
||||
if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
|
||||
if (!method_exists($this->dispatcher, 'reset')) {
|
||||
return; // @deprecated
|
||||
}
|
||||
|
||||
$this->dispatcher->reset();
|
||||
}
|
||||
}
|
||||
@@ -63,6 +58,11 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
$this->setCalledListeners($this->dispatcher->getCalledListeners());
|
||||
$this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
|
||||
}
|
||||
|
||||
if ($this->dispatcher instanceof TraceableEventDispatcher) {
|
||||
$this->setOrphanedEvents($this->dispatcher->getOrphanedEvents());
|
||||
}
|
||||
|
||||
$this->data = $this->cloneVar($this->data);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
*
|
||||
* @param array $listeners An array of called listeners
|
||||
*
|
||||
* @see TraceableEventDispatcherInterface
|
||||
* @see TraceableEventDispatcher
|
||||
*/
|
||||
public function setCalledListeners(array $listeners)
|
||||
{
|
||||
@@ -83,7 +83,7 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
*
|
||||
* @return array An array of called listeners
|
||||
*
|
||||
* @see TraceableEventDispatcherInterface
|
||||
* @see TraceableEventDispatcher
|
||||
*/
|
||||
public function getCalledListeners()
|
||||
{
|
||||
@@ -93,9 +93,9 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
/**
|
||||
* Sets the not called listeners.
|
||||
*
|
||||
* @param array $listeners An array of not called listeners
|
||||
* @param array $listeners
|
||||
*
|
||||
* @see TraceableEventDispatcherInterface
|
||||
* @see TraceableEventDispatcher
|
||||
*/
|
||||
public function setNotCalledListeners(array $listeners)
|
||||
{
|
||||
@@ -105,15 +105,39 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
|
||||
/**
|
||||
* Gets the not called listeners.
|
||||
*
|
||||
* @return array An array of not called listeners
|
||||
* @return array
|
||||
*
|
||||
* @see TraceableEventDispatcherInterface
|
||||
* @see TraceableEventDispatcher
|
||||
*/
|
||||
public function getNotCalledListeners()
|
||||
{
|
||||
return $this->data['not_called_listeners'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the orphaned events.
|
||||
*
|
||||
* @param array $events An array of orphaned events
|
||||
*
|
||||
* @see TraceableEventDispatcher
|
||||
*/
|
||||
public function setOrphanedEvents(array $events)
|
||||
{
|
||||
$this->data['orphaned_events'] = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the orphaned events.
|
||||
*
|
||||
* @return array An array of orphaned events
|
||||
*
|
||||
* @see TraceableEventDispatcher
|
||||
*/
|
||||
public function getOrphanedEvents()
|
||||
{
|
||||
return $this->data['orphaned_events'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\DataCollector;
|
||||
|
||||
use Symfony\Component\Debug\Exception\SilencedErrorContext;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
|
||||
@@ -25,18 +26,17 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
{
|
||||
private $logger;
|
||||
private $containerPathPrefix;
|
||||
private $currentRequest;
|
||||
private $requestStack;
|
||||
|
||||
public function __construct($logger = null, $containerPathPrefix = null)
|
||||
public function __construct($logger = null, string $containerPathPrefix = null, RequestStack $requestStack = null)
|
||||
{
|
||||
if (null !== $logger && $logger instanceof DebugLoggerInterface) {
|
||||
if (!method_exists($logger, 'clear')) {
|
||||
@trigger_error(sprintf('Implementing "%s" without the "clear()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', DebugLoggerInterface::class, \get_class($logger)), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
$this->containerPathPrefix = $containerPathPrefix;
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
*/
|
||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
{
|
||||
// everything is done as late as possible
|
||||
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
if ($this->logger && method_exists($this->logger, 'clear')) {
|
||||
if ($this->logger instanceof DebugLoggerInterface) {
|
||||
$this->logger->clear();
|
||||
}
|
||||
$this->data = array();
|
||||
@@ -67,9 +67,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
$containerDeprecationLogs = $this->getContainerDeprecationLogs();
|
||||
$this->data = $this->computeErrorsCount($containerDeprecationLogs);
|
||||
$this->data['compiler_logs'] = $this->getContainerCompilerLogs();
|
||||
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs(), $containerDeprecationLogs));
|
||||
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs));
|
||||
$this->data = $this->cloneVar($this->data);
|
||||
}
|
||||
$this->currentRequest = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,14 +234,14 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
{
|
||||
$silencedLogs = array();
|
||||
$count = array(
|
||||
'error_count' => $this->logger->countErrors(),
|
||||
'error_count' => $this->logger->countErrors($this->currentRequest),
|
||||
'deprecation_count' => 0,
|
||||
'warning_count' => 0,
|
||||
'scream_count' => 0,
|
||||
'priorities' => array(),
|
||||
);
|
||||
|
||||
foreach ($this->logger->getLogs() as $log) {
|
||||
foreach ($this->logger->getLogs($this->currentRequest) as $log) {
|
||||
if (isset($count['priorities'][$log['priority']])) {
|
||||
++$count['priorities'][$log['priority']]['count'];
|
||||
} else {
|
||||
|
@@ -79,6 +79,13 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
$responseCookies[$cookie->getName()] = $cookie;
|
||||
}
|
||||
|
||||
$dotenvVars = array();
|
||||
foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {
|
||||
if ('' !== $name && false !== $value = getenv($name)) {
|
||||
$dotenvVars[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->data = array(
|
||||
'method' => $request->getMethod(),
|
||||
'format' => $request->getRequestFormat(),
|
||||
@@ -101,6 +108,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
'path_info' => $request->getPathInfo(),
|
||||
'controller' => 'n/a',
|
||||
'locale' => $request->getLocale(),
|
||||
'dotenv_vars' => $dotenvVars,
|
||||
);
|
||||
|
||||
if (isset($this->data['request_headers']['php-auth-pw'])) {
|
||||
@@ -150,6 +158,10 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
}
|
||||
|
||||
$this->data['identifier'] = $this->data['route'] ?: (\is_array($this->data['controller']) ? $this->data['controller']['class'].'::'.$this->data['controller']['method'].'()' : $this->data['controller']);
|
||||
|
||||
if ($response->headers->has('x-previous-debug-token')) {
|
||||
$this->data['forward_token'] = $response->headers->get('x-previous-debug-token');
|
||||
}
|
||||
}
|
||||
|
||||
public function lateCollect()
|
||||
@@ -258,6 +270,11 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
return $this->data['locale'];
|
||||
}
|
||||
|
||||
public function getDotenvVars()
|
||||
{
|
||||
return new ParameterBag($this->data['dotenv_vars']->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the route name.
|
||||
*
|
||||
@@ -309,6 +326,11 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
return isset($this->data['redirect']) ? $this->data['redirect'] : false;
|
||||
}
|
||||
|
||||
public function getForwardToken()
|
||||
{
|
||||
return isset($this->data['forward_token']) ? $this->data['forward_token'] : null;
|
||||
}
|
||||
|
||||
public function onKernelController(FilterControllerEvent $event)
|
||||
{
|
||||
$this->controllers[$event->getRequest()] = $event->getController();
|
||||
|
@@ -1,99 +0,0 @@
|
||||
<?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\DataCollector\Util;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ValueExporter class is deprecated since Symfony 3.2 and will be removed in 4.0. Use the VarDumper component instead.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated since version 3.2, to be removed in 4.0. Use the VarDumper component instead.
|
||||
*/
|
||||
class ValueExporter
|
||||
{
|
||||
/**
|
||||
* Converts a PHP value to a string.
|
||||
*
|
||||
* @param mixed $value The PHP value
|
||||
* @param int $depth Only for internal usage
|
||||
* @param bool $deep Only for internal usage
|
||||
*
|
||||
* @return string The string representation of the given value
|
||||
*/
|
||||
public function exportValue($value, $depth = 1, $deep = false)
|
||||
{
|
||||
if ($value instanceof \__PHP_Incomplete_Class) {
|
||||
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
|
||||
}
|
||||
|
||||
if (\is_object($value)) {
|
||||
if ($value instanceof \DateTimeInterface) {
|
||||
return sprintf('Object(%s) - %s', \get_class($value), $value->format(\DateTime::ATOM));
|
||||
}
|
||||
|
||||
return sprintf('Object(%s)', \get_class($value));
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
if (empty($value)) {
|
||||
return '[]';
|
||||
}
|
||||
|
||||
$indent = str_repeat(' ', $depth);
|
||||
|
||||
$a = array();
|
||||
foreach ($value as $k => $v) {
|
||||
if (\is_array($v)) {
|
||||
$deep = true;
|
||||
}
|
||||
$a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
|
||||
}
|
||||
|
||||
if ($deep) {
|
||||
return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
|
||||
}
|
||||
|
||||
$s = sprintf('[%s]', implode(', ', $a));
|
||||
|
||||
if (80 > \strlen($s)) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $a));
|
||||
}
|
||||
|
||||
if (\is_resource($value)) {
|
||||
return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
if (false === $value) {
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if (true === $value) {
|
||||
return 'true';
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
}
|
||||
|
||||
private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
|
||||
{
|
||||
$array = new \ArrayObject($value);
|
||||
|
||||
return $array['__PHP_Incomplete_Class_Name'];
|
||||
}
|
||||
}
|
@@ -31,7 +31,7 @@ class FileLinkFormatter implements \Serializable
|
||||
/**
|
||||
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
|
||||
*/
|
||||
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, $baseDir = null, $urlFormat = null)
|
||||
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
|
||||
{
|
||||
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
||||
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
|
||||
@@ -68,11 +68,7 @@ class FileLinkFormatter implements \Serializable
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
$this->fileLinkFormat = unserialize($serialized, array('allowed_classes' => false));
|
||||
} else {
|
||||
$this->fileLinkFormat = unserialize($serialized);
|
||||
}
|
||||
$this->fileLinkFormat = unserialize($serialized, array('allowed_classes' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -36,23 +36,15 @@ class AddAnnotatedClassesToCachePass implements CompilerPassInterface
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$classes = array();
|
||||
$annotatedClasses = array();
|
||||
$annotatedClasses = $this->kernel->getAnnotatedClassesToCompile();
|
||||
foreach ($container->getExtensions() as $extension) {
|
||||
if ($extension instanceof Extension) {
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
$classes = array_merge($classes, $extension->getClassesToCompile());
|
||||
}
|
||||
$annotatedClasses = array_merge($annotatedClasses, $extension->getAnnotatedClassesToCompile());
|
||||
}
|
||||
}
|
||||
|
||||
$existingClasses = $this->getClassesInComposerClassMaps();
|
||||
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
$classes = $container->getParameterBag()->resolveValue($classes);
|
||||
$this->kernel->setClassCache($this->expandClasses($classes, $existingClasses));
|
||||
}
|
||||
$annotatedClasses = $container->getParameterBag()->resolveValue($annotatedClasses);
|
||||
$this->kernel->setAnnotatedClassCache($this->expandClasses($annotatedClasses, $existingClasses));
|
||||
}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
<?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\DependencyInjection;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\AddClassesToCachePass class is deprecated since Symfony 3.3 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* Sets the classes to compile in the cache for the container.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
class AddClassesToCachePass extends AddAnnotatedClassesToCachePass
|
||||
{
|
||||
}
|
@@ -15,6 +15,9 @@ use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
/**
|
||||
* Gathers and configures the argument value resolvers.
|
||||
@@ -27,11 +30,13 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface
|
||||
|
||||
private $argumentResolverService;
|
||||
private $argumentValueResolverTag;
|
||||
private $traceableResolverStopwatch;
|
||||
|
||||
public function __construct($argumentResolverService = 'argument_resolver', $argumentValueResolverTag = 'controller.argument_value_resolver')
|
||||
public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver', string $traceableResolverStopwatch = 'debug.stopwatch')
|
||||
{
|
||||
$this->argumentResolverService = $argumentResolverService;
|
||||
$this->argumentValueResolverTag = $argumentValueResolverTag;
|
||||
$this->traceableResolverStopwatch = $traceableResolverStopwatch;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
@@ -40,9 +45,20 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$resolvers = $this->findAndSortTaggedServices($this->argumentValueResolverTag, $container);
|
||||
|
||||
if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class) && $container->has($this->traceableResolverStopwatch)) {
|
||||
foreach ($resolvers as $resolverReference) {
|
||||
$id = (string) $resolverReference;
|
||||
$container->register("debug.$id", TraceableValueResolver::class)
|
||||
->setDecoratedService($id)
|
||||
->setArguments(array(new Reference("debug.$id.inner"), new Reference($this->traceableResolverStopwatch)));
|
||||
}
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition($this->argumentResolverService)
|
||||
->replaceArgument(1, new IteratorArgument($this->findAndSortTaggedServices($this->argumentValueResolverTag, $container)))
|
||||
->replaceArgument(1, new IteratorArgument($resolvers))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@@ -20,25 +20,8 @@ use Symfony\Component\DependencyInjection\Extension\Extension as BaseExtension;
|
||||
*/
|
||||
abstract class Extension extends BaseExtension
|
||||
{
|
||||
private $classes = array();
|
||||
private $annotatedClasses = array();
|
||||
|
||||
/**
|
||||
* Gets the classes to cache.
|
||||
*
|
||||
* @return array An array of classes
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function getClassesToCompile()
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return $this->classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the annotated classes to cache.
|
||||
*
|
||||
@@ -49,22 +32,6 @@ abstract class Extension extends BaseExtension
|
||||
return $this->annotatedClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds classes to the class cache.
|
||||
*
|
||||
* @param array $classes An array of class patterns
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function addClassesToCompile(array $classes)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->classes = array_merge($this->classes, $classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds annotated classes to the class cache.
|
||||
*
|
||||
|
@@ -28,11 +28,7 @@ class FragmentRendererPass implements CompilerPassInterface
|
||||
private $handlerService;
|
||||
private $rendererTag;
|
||||
|
||||
/**
|
||||
* @param string $handlerService Service name of the fragment handler in the container
|
||||
* @param string $rendererTag Tag name used for fragments
|
||||
*/
|
||||
public function __construct($handlerService = 'fragment.handler', $rendererTag = 'kernel.fragment_renderer')
|
||||
public function __construct(string $handlerService = 'fragment.handler', string $rendererTag = 'kernel.fragment_renderer')
|
||||
{
|
||||
$this->handlerService = $handlerService;
|
||||
$this->rendererTag = $rendererTag;
|
||||
|
@@ -23,52 +23,20 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
||||
class LazyLoadingFragmentHandler extends FragmentHandler
|
||||
{
|
||||
private $container;
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
private $rendererIds = array();
|
||||
private $initialized = array();
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container A container
|
||||
* @param RequestStack $requestStack The Request stack that controls the lifecycle of requests
|
||||
* @param bool $debug Whether the debug mode is enabled or not
|
||||
*/
|
||||
public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false)
|
||||
public function __construct(ContainerInterface $container, RequestStack $requestStack, bool $debug = false)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
parent::__construct($requestStack, array(), $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a service as a fragment renderer.
|
||||
*
|
||||
* @param string $name The service name
|
||||
* @param string $renderer The render service id
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
public function addRendererService($name, $renderer)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->rendererIds[$name] = $renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($uri, $renderer = 'inline', array $options = array())
|
||||
{
|
||||
// BC 3.x, to be removed in 4.0
|
||||
if (isset($this->rendererIds[$renderer])) {
|
||||
$this->addRenderer($this->container->get($this->rendererIds[$renderer]));
|
||||
unset($this->rendererIds[$renderer]);
|
||||
|
||||
return parent::render($uri, $renderer, $options);
|
||||
}
|
||||
|
||||
if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
|
||||
$this->addRenderer($this->container->get($renderer));
|
||||
$this->initialized[$renderer] = true;
|
||||
|
@@ -33,11 +33,13 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
{
|
||||
private $resolverServiceId;
|
||||
private $controllerTag;
|
||||
private $controllerLocator;
|
||||
|
||||
public function __construct($resolverServiceId = 'argument_resolver.service', $controllerTag = 'controller.service_arguments')
|
||||
public function __construct(string $resolverServiceId = 'argument_resolver.service', string $controllerTag = 'controller.service_arguments', string $controllerLocator = 'argument_resolver.controller_locator')
|
||||
{
|
||||
$this->resolverServiceId = $resolverServiceId;
|
||||
$this->controllerTag = $controllerTag;
|
||||
$this->controllerLocator = $controllerLocator;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
@@ -126,7 +128,7 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
if (isset($arguments[$r->name][$p->name])) {
|
||||
$target = $arguments[$r->name][$p->name];
|
||||
if ('?' !== $target[0]) {
|
||||
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
|
||||
} elseif ('' === $target = (string) substr($target, 1)) {
|
||||
throw new InvalidArgumentException(sprintf('A "%s" tag must have non-empty "id" attributes for service "%s".', $this->controllerTag, $id));
|
||||
} elseif ($p->allowsNull() && !$p->isOptional()) {
|
||||
@@ -136,17 +138,22 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
$binding = $bindings[$bindingName];
|
||||
|
||||
list($bindingValue, $bindingId) = $binding->getValues();
|
||||
$binding->setValues(array($bindingValue, $bindingId, true));
|
||||
|
||||
if (!$bindingValue instanceof Reference) {
|
||||
continue;
|
||||
$args[$p->name] = new Reference('.value.'.$container->hash($bindingValue));
|
||||
$container->register((string) $args[$p->name], 'mixed')
|
||||
->setFactory('current')
|
||||
->addArgument(array($bindingValue));
|
||||
} else {
|
||||
$args[$p->name] = $bindingValue;
|
||||
}
|
||||
|
||||
$binding->setValues(array($bindingValue, $bindingId, true));
|
||||
$args[$p->name] = $bindingValue;
|
||||
|
||||
continue;
|
||||
} elseif (!$type || !$autowire) {
|
||||
continue;
|
||||
} elseif (!$p->allowsNull()) {
|
||||
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
|
||||
}
|
||||
|
||||
if (Request::class === $type) {
|
||||
@@ -164,16 +171,18 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
|
||||
$args[$p->name] = $type ? new TypedReference($target, $type, $r->class, $invalidBehavior) : new Reference($target, $invalidBehavior);
|
||||
$args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior) : new Reference($target, $invalidBehavior);
|
||||
}
|
||||
// register the maps as a per-method service-locators
|
||||
if ($args) {
|
||||
$controllers[$id.':'.$r->name] = ServiceLocatorTagPass::register($container, $args);
|
||||
$controllers[$id.'::'.$r->name] = ServiceLocatorTagPass::register($container, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container->getDefinition($this->resolverServiceId)
|
||||
->replaceArgument(0, ServiceLocatorTagPass::register($container, $controllers));
|
||||
->replaceArgument(0, $controllerLocatorRef = ServiceLocatorTagPass::register($container, $controllers));
|
||||
|
||||
$container->setAlias($this->controllerLocator, (string) $controllerLocatorRef);
|
||||
}
|
||||
}
|
||||
|
@@ -21,21 +21,16 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
*/
|
||||
class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
{
|
||||
private $resolverServiceId;
|
||||
private $controllerLocator;
|
||||
|
||||
public function __construct($resolverServiceId = 'argument_resolver.service')
|
||||
public function __construct(string $controllerLocator = 'argument_resolver.controller_locator')
|
||||
{
|
||||
$this->resolverServiceId = $resolverServiceId;
|
||||
$this->controllerLocator = $controllerLocator;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (false === $container->hasDefinition($this->resolverServiceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$serviceResolver = $container->getDefinition($this->resolverServiceId);
|
||||
$controllerLocator = $container->getDefinition((string) $serviceResolver->getArgument(0));
|
||||
$controllerLocator = $container->findDefinition($this->controllerLocator);
|
||||
$controllers = $controllerLocator->getArgument(0);
|
||||
|
||||
foreach ($controllers as $controller => $argumentRef) {
|
||||
@@ -47,8 +42,7 @@ class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
} else {
|
||||
// any methods listed for call-at-instantiation cannot be actions
|
||||
$reason = false;
|
||||
$action = substr(strrchr($controller, ':'), 1);
|
||||
$id = substr($controller, 0, -1 - \strlen($action));
|
||||
list($id, $action) = explode('::', $controller);
|
||||
$controllerDef = $container->getDefinition($id);
|
||||
foreach ($controllerDef->getMethodCalls() as list($method)) {
|
||||
if (0 === strcasecmp($action, $method)) {
|
||||
@@ -57,9 +51,9 @@ class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
if (!$reason) {
|
||||
if ($controllerDef->getClass() === $id) {
|
||||
$controllers[$id.'::'.$action] = $argumentRef;
|
||||
}
|
||||
// Deprecated since Symfony 4.1. See Symfony\Component\HttpKernel\Controller\ContainerControllerResolver
|
||||
$controllers[$id.':'.$action] = $argumentRef;
|
||||
|
||||
if ('__invoke' === $action) {
|
||||
$controllers[$id] = $argumentRef;
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ class ResettableServicePass implements CompilerPassInterface
|
||||
{
|
||||
private $tagName;
|
||||
|
||||
public function __construct($tagName = 'kernel.reset')
|
||||
public function __construct(string $tagName = 'kernel.reset')
|
||||
{
|
||||
$this->tagName = $tagName;
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ class FilterControllerArgumentsEvent extends FilterControllerEvent
|
||||
{
|
||||
private $arguments;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, callable $controller, array $arguments, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, callable $controller, array $arguments, Request $request, ?int $requestType)
|
||||
{
|
||||
parent::__construct($kernel, $controller, $request, $requestType);
|
||||
|
||||
|
@@ -29,7 +29,7 @@ class FilterControllerEvent extends KernelEvent
|
||||
{
|
||||
private $controller;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, callable $controller, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, callable $controller, Request $request, ?int $requestType)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
|
@@ -28,7 +28,7 @@ class FilterResponseEvent extends KernelEvent
|
||||
{
|
||||
private $response;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, Response $response)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, Response $response)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
|
@@ -32,7 +32,7 @@ class GetResponseForControllerResultEvent extends GetResponseEvent
|
||||
*/
|
||||
private $controllerResult;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, $controllerResult)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, $controllerResult)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
|
@@ -41,7 +41,7 @@ class GetResponseForExceptionEvent extends GetResponseEvent
|
||||
*/
|
||||
private $allowCustomResponseCode = false;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Exception $e)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
|
@@ -32,7 +32,7 @@ class KernelEvent extends Event
|
||||
* @param int $requestType The request type the kernel is currently processing; one of
|
||||
* HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST
|
||||
*/
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, $requestType)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, ?int $requestType)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->request = $request;
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\EventListener;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
@@ -20,28 +21,48 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* Sets the session in the request.
|
||||
* Sets the session onto the request on the "kernel.request" event and saves
|
||||
* it on the "kernel.response" event.
|
||||
*
|
||||
* In addition, if the session has been started it overrides the Cache-Control
|
||||
* header in such a way that all caching is disabled in that case.
|
||||
* If you have a scenario where caching responses with session information in
|
||||
* them makes sense, you can disable this behaviour by setting the header
|
||||
* AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER on the response.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
abstract class AbstractSessionListener implements EventSubscriberInterface
|
||||
{
|
||||
const NO_AUTO_CACHE_CONTROL_HEADER = 'Symfony-Session-NoAutoCacheControl';
|
||||
|
||||
protected $container;
|
||||
private $sessionUsageStack = array();
|
||||
|
||||
public function __construct(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
{
|
||||
if (!$event->isMasterRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$session = null;
|
||||
$request = $event->getRequest();
|
||||
$session = $this->getSession();
|
||||
$this->sessionUsageStack[] = $session instanceof Session ? $session->getUsageIndex() : null;
|
||||
if (null === $session || $request->hasSession()) {
|
||||
return;
|
||||
if ($request->hasSession()) {
|
||||
// no-op
|
||||
} elseif (method_exists($request, 'setSessionFactory')) {
|
||||
$request->setSessionFactory(function () { return $this->getSession(); });
|
||||
} elseif ($session = $this->getSession()) {
|
||||
$request->setSession($session);
|
||||
}
|
||||
|
||||
$request->setSession($session);
|
||||
$session = $session ?? ($this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : null);
|
||||
$this->sessionUsageStack[] = $session instanceof Session ? $session->getUsageIndex() : 0;
|
||||
}
|
||||
|
||||
public function onKernelResponse(FilterResponseEvent $event)
|
||||
@@ -50,15 +71,51 @@ abstract class AbstractSessionListener implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$session = $event->getRequest()->getSession()) {
|
||||
if (!$session = $this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : $event->getRequest()->getSession()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$response = $event->getResponse();
|
||||
|
||||
if ($session instanceof Session ? $session->getUsageIndex() !== end($this->sessionUsageStack) : $session->isStarted()) {
|
||||
$event->getResponse()
|
||||
->setPrivate()
|
||||
->setMaxAge(0)
|
||||
->headers->addCacheControlDirective('must-revalidate');
|
||||
if (!$response->headers->has(self::NO_AUTO_CACHE_CONTROL_HEADER)) {
|
||||
$response
|
||||
->setPrivate()
|
||||
->setMaxAge(0)
|
||||
->headers->addCacheControlDirective('must-revalidate');
|
||||
}
|
||||
}
|
||||
|
||||
// Always remove the internal header if present
|
||||
$response->headers->remove(self::NO_AUTO_CACHE_CONTROL_HEADER);
|
||||
|
||||
if ($session->isStarted()) {
|
||||
/*
|
||||
* Saves the session, in case it is still open, before sending the response/headers.
|
||||
*
|
||||
* This ensures several things in case the developer did not save the session explicitly:
|
||||
*
|
||||
* * If a session save handler without locking is used, it ensures the data is available
|
||||
* on the next request, e.g. after a redirect. PHPs auto-save at script end via
|
||||
* session_register_shutdown is executed after fastcgi_finish_request. So in this case
|
||||
* the data could be missing the next request because it might not be saved the moment
|
||||
* the new request is processed.
|
||||
* * A locking save handler (e.g. the native 'files') circumvents concurrency problems like
|
||||
* the one above. But by saving the session before long-running things in the terminate event,
|
||||
* we ensure the session is not blocked longer than needed.
|
||||
* * When regenerating the session ID no locking is involved in PHPs session design. See
|
||||
* https://bugs.php.net/bug.php?id=61470 for a discussion. So in this case, the session must
|
||||
* be saved anyway before sending the headers with the new session ID. Otherwise session
|
||||
* data could get lost again for concurrent requests with the new ID. One result could be
|
||||
* that you get logged out after just logging in.
|
||||
*
|
||||
* This listener should be executed as one of the last listeners, so that previous listeners
|
||||
* can still operate on the open session. This prevents the overhead of restarting it.
|
||||
* Listeners after closing the session can still work with the session as usual because
|
||||
* Symfonys session implementation starts the session on demand. So writing to it after
|
||||
* it is saved will just restart it.
|
||||
*/
|
||||
$session->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +133,7 @@ abstract class AbstractSessionListener implements EventSubscriberInterface
|
||||
{
|
||||
return array(
|
||||
KernelEvents::REQUEST => array('onKernelRequest', 128),
|
||||
// low priority to come after regular response listeners, same as SaveSessionListener
|
||||
// low priority to come after regular response listeners, but higher than StreamedResponseListener
|
||||
KernelEvents::RESPONSE => array('onKernelResponse', -1000),
|
||||
KernelEvents::FINISH_REQUEST => array('onFinishRequest'),
|
||||
);
|
||||
|
@@ -61,10 +61,12 @@ abstract class AbstractTestSessionListener implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$session = $event->getRequest()->getSession()) {
|
||||
$request = $event->getRequest();
|
||||
if (!$request->hasSession()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
if ($wasStarted = $session->isStarted()) {
|
||||
$session->save();
|
||||
}
|
||||
|
@@ -48,15 +48,15 @@ class DebugHandlersListener implements EventSubscriberInterface
|
||||
* @param string|array $fileLinkFormat The format for links to source files
|
||||
* @param bool $scope Enables/disables scoping mode
|
||||
*/
|
||||
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = E_ALL, $throwAt = E_ALL, $scream = true, $fileLinkFormat = null, $scope = true)
|
||||
public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = E_ALL, ?int $throwAt = E_ALL, bool $scream = true, $fileLinkFormat = null, bool $scope = true)
|
||||
{
|
||||
$this->exceptionHandler = $exceptionHandler;
|
||||
$this->logger = $logger;
|
||||
$this->levels = null === $levels ? E_ALL : $levels;
|
||||
$this->throwAt = is_numeric($throwAt) ? (int) $throwAt : (null === $throwAt ? null : ($throwAt ? E_ALL : null));
|
||||
$this->scream = (bool) $scream;
|
||||
$this->throwAt = \is_int($throwAt) ? $throwAt : (null === $throwAt ? null : ($throwAt ? E_ALL : null));
|
||||
$this->scream = $scream;
|
||||
$this->fileLinkFormat = $fileLinkFormat;
|
||||
$this->scope = (bool) $scope;
|
||||
$this->scope = $scope;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -15,6 +15,7 @@ use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||
use Symfony\Component\VarDumper\Server\Connection;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
|
||||
/**
|
||||
@@ -26,20 +27,27 @@ class DumpListener implements EventSubscriberInterface
|
||||
{
|
||||
private $cloner;
|
||||
private $dumper;
|
||||
private $connection;
|
||||
|
||||
public function __construct(ClonerInterface $cloner, DataDumperInterface $dumper)
|
||||
public function __construct(ClonerInterface $cloner, DataDumperInterface $dumper, Connection $connection = null)
|
||||
{
|
||||
$this->cloner = $cloner;
|
||||
$this->dumper = $dumper;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$cloner = $this->cloner;
|
||||
$dumper = $this->dumper;
|
||||
$connection = $this->connection;
|
||||
|
||||
VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
VarDumper::setHandler(static function ($var) use ($cloner, $dumper, $connection) {
|
||||
$data = $cloner->cloneVar($var);
|
||||
|
||||
if (!$connection || !$connection->write($data)) {
|
||||
$dumper->dump($data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -41,16 +41,19 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
public function logKernelException(GetResponseForExceptionEvent $event)
|
||||
{
|
||||
$exception = $event->getException();
|
||||
|
||||
$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
|
||||
}
|
||||
|
||||
public function onKernelException(GetResponseForExceptionEvent $event)
|
||||
{
|
||||
$exception = $event->getException();
|
||||
$request = $event->getRequest();
|
||||
$request = $this->duplicateRequest($exception, $event->getRequest());
|
||||
$eventDispatcher = \func_num_args() > 2 ? func_get_arg(2) : null;
|
||||
|
||||
$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
|
||||
|
||||
$request = $this->duplicateRequest($exception, $request);
|
||||
|
||||
try {
|
||||
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
|
||||
} catch (\Exception $e) {
|
||||
@@ -85,7 +88,10 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::EXCEPTION => array('onKernelException', -128),
|
||||
KernelEvents::EXCEPTION => array(
|
||||
array('logKernelException', 0),
|
||||
array('onKernelException', -128),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -38,7 +38,7 @@ class FragmentListener implements EventSubscriberInterface
|
||||
* @param UriSigner $signer A UriSigner instance
|
||||
* @param string $fragmentPath The path that triggers this listener
|
||||
*/
|
||||
public function __construct(UriSigner $signer, $fragmentPath = '/_fragment')
|
||||
public function __construct(UriSigner $signer, string $fragmentPath = '/_fragment')
|
||||
{
|
||||
$this->signer = $signer;
|
||||
$this->fragmentPath = $fragmentPath;
|
||||
|
@@ -35,7 +35,7 @@ class LocaleListener implements EventSubscriberInterface
|
||||
* @param string $defaultLocale The default locale
|
||||
* @param RequestContextAwareInterface|null $router The router
|
||||
*/
|
||||
public function __construct(RequestStack $requestStack, $defaultLocale = 'en', RequestContextAwareInterface $router = null)
|
||||
public function __construct(RequestStack $requestStack, string $defaultLocale = 'en', RequestContextAwareInterface $router = null)
|
||||
{
|
||||
$this->defaultLocale = $defaultLocale;
|
||||
$this->requestStack = $requestStack;
|
||||
|
@@ -43,12 +43,12 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
* @param bool $onlyException True if the profiler only collects data when an exception occurs, false otherwise
|
||||
* @param bool $onlyMasterRequests True if the profiler only collects data when the request is a master request, false otherwise
|
||||
*/
|
||||
public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
|
||||
public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, bool $onlyException = false, bool $onlyMasterRequests = false)
|
||||
{
|
||||
$this->profiler = $profiler;
|
||||
$this->matcher = $matcher;
|
||||
$this->onlyException = (bool) $onlyException;
|
||||
$this->onlyMasterRequests = (bool) $onlyMasterRequests;
|
||||
$this->onlyException = $onlyException;
|
||||
$this->onlyMasterRequests = $onlyMasterRequests;
|
||||
$this->profiles = new \SplObjectStorage();
|
||||
$this->parents = new \SplObjectStorage();
|
||||
$this->requestStack = $requestStack;
|
||||
@@ -121,7 +121,7 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
{
|
||||
return array(
|
||||
KernelEvents::RESPONSE => array('onKernelResponse', -100),
|
||||
KernelEvents::EXCEPTION => 'onKernelException',
|
||||
KernelEvents::EXCEPTION => array('onKernelException', 0),
|
||||
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
|
||||
);
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ class ResponseListener implements EventSubscriberInterface
|
||||
{
|
||||
private $charset;
|
||||
|
||||
public function __construct($charset)
|
||||
public function __construct(string $charset)
|
||||
{
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ class RouterListener implements EventSubscriberInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($matcher, RequestStack $requestStack, RequestContext $context = null, LoggerInterface $logger = null, $projectDir = null, $debug = true)
|
||||
public function __construct($matcher, RequestStack $requestStack, RequestContext $context = null, LoggerInterface $logger = null, string $projectDir = null, bool $debug = true)
|
||||
{
|
||||
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
|
||||
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
|
||||
|
@@ -11,36 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\EventListener;
|
||||
|
||||
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.1, use AbstractSessionListener instead.', SaveSessionListener::class), E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
/**
|
||||
* Saves the session, in case it is still open, before sending the response/headers.
|
||||
*
|
||||
* This ensures several things in case the developer did not save the session explicitly:
|
||||
*
|
||||
* * If a session save handler without locking is used, it ensures the data is available
|
||||
* on the next request, e.g. after a redirect. PHPs auto-save at script end via
|
||||
* session_register_shutdown is executed after fastcgi_finish_request. So in this case
|
||||
* the data could be missing the next request because it might not be saved the moment
|
||||
* the new request is processed.
|
||||
* * A locking save handler (e.g. the native 'files') circumvents concurrency problems like
|
||||
* the one above. But by saving the session before long-running things in the terminate event,
|
||||
* we ensure the session is not blocked longer than needed.
|
||||
* * When regenerating the session ID no locking is involved in PHPs session design. See
|
||||
* https://bugs.php.net/bug.php?id=61470 for a discussion. So in this case, the session must
|
||||
* be saved anyway before sending the headers with the new session ID. Otherwise session
|
||||
* data could get lost again for concurrent requests with the new ID. One result could be
|
||||
* that you get logged out after just logging in.
|
||||
*
|
||||
* This listener should be executed as one of the last listeners, so that previous listeners
|
||||
* can still operate on the open session. This prevents the overhead of restarting it.
|
||||
* Listeners after closing the session can still work with the session as usual because
|
||||
* Symfonys session implementation starts the session on demand. So writing to it after
|
||||
* it is saved will just restart it.
|
||||
*
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*
|
||||
* @deprecated since Symfony 4.1, use AbstractSessionListener instead
|
||||
*/
|
||||
class SaveSessionListener implements EventSubscriberInterface
|
||||
{
|
||||
|
@@ -18,12 +18,10 @@ use Psr\Container\ContainerInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final since version 3.3
|
||||
* @final
|
||||
*/
|
||||
class SessionListener extends AbstractSessionListener
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
@@ -18,7 +18,7 @@ use Psr\Container\ContainerInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final since version 3.3
|
||||
* @final
|
||||
*/
|
||||
class TestSessionListener extends AbstractTestSessionListener
|
||||
{
|
||||
|
@@ -21,9 +21,10 @@ class AccessDeniedHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(403, $message, $previous, array(), $code);
|
||||
parent::__construct(403, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class BadRequestHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(400, $message, $previous, array(), $code);
|
||||
parent::__construct(400, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class ConflictHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(409, $message, $previous, array(), $code);
|
||||
parent::__construct(409, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class GoneHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(410, $message, $previous, array(), $code);
|
||||
parent::__construct(410, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface
|
||||
private $statusCode;
|
||||
private $headers;
|
||||
|
||||
public function __construct($statusCode, $message = null, \Exception $previous = null, array $headers = array(), $code = 0)
|
||||
public function __construct(int $statusCode, string $message = null, \Exception $previous = null, array $headers = array(), ?int $code = 0)
|
||||
{
|
||||
$this->statusCode = $statusCode;
|
||||
$this->headers = $headers;
|
||||
|
@@ -20,9 +20,10 @@ class LengthRequiredHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(411, $message, $previous, array(), $code);
|
||||
parent::__construct(411, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -21,10 +21,11 @@ class MethodNotAllowedHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct(array $allow, $message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(array $allow, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = array())
|
||||
{
|
||||
$headers = array('Allow' => strtoupper(implode(', ', $allow)));
|
||||
$headers['Allow'] = strtoupper(implode(', ', $allow));
|
||||
|
||||
parent::__construct(405, $message, $previous, $headers, $code);
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class NotAcceptableHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(406, $message, $previous, array(), $code);
|
||||
parent::__construct(406, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class NotFoundHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(404, $message, $previous, array(), $code);
|
||||
parent::__construct(404, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class PreconditionFailedHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(412, $message, $previous, array(), $code);
|
||||
parent::__construct(412, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -22,9 +22,10 @@ class PreconditionRequiredHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(428, $message, $previous, array(), $code);
|
||||
parent::__construct(428, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -21,12 +21,12 @@ class ServiceUnavailableHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($retryAfter = null, $message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct($retryAfter = null, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = array())
|
||||
{
|
||||
$headers = array();
|
||||
if ($retryAfter) {
|
||||
$headers = array('Retry-After' => $retryAfter);
|
||||
$headers['Retry-After'] = $retryAfter;
|
||||
}
|
||||
|
||||
parent::__construct(503, $message, $previous, $headers, $code);
|
||||
|
@@ -23,12 +23,12 @@ class TooManyRequestsHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($retryAfter = null, $message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct($retryAfter = null, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = array())
|
||||
{
|
||||
$headers = array();
|
||||
if ($retryAfter) {
|
||||
$headers = array('Retry-After' => $retryAfter);
|
||||
$headers['Retry-After'] = $retryAfter;
|
||||
}
|
||||
|
||||
parent::__construct(429, $message, $previous, $headers, $code);
|
||||
|
@@ -21,10 +21,11 @@ class UnauthorizedHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($challenge, $message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $challenge, string $message = null, \Exception $previous = null, ?int $code = 0, array $headers = array())
|
||||
{
|
||||
$headers = array('WWW-Authenticate' => $challenge);
|
||||
$headers['WWW-Authenticate'] = $challenge;
|
||||
|
||||
parent::__construct(401, $message, $previous, $headers, $code);
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class UnprocessableEntityHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(422, $message, $previous, array(), $code);
|
||||
parent::__construct(422, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,10 @@ class UnsupportedMediaTypeHttpException extends HttpException
|
||||
* @param string $message The internal exception message
|
||||
* @param \Exception $previous The previous exception
|
||||
* @param int $code The internal exception code
|
||||
* @param array $headers
|
||||
*/
|
||||
public function __construct($message = null, \Exception $previous = null, $code = 0)
|
||||
public function __construct(string $message = null, \Exception $previous = null, int $code = 0, array $headers = array())
|
||||
{
|
||||
parent::__construct(415, $message, $previous, array(), $code);
|
||||
parent::__construct(415, $message, $previous, $headers, $code);
|
||||
}
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
{
|
||||
if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
|
||||
if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
|
||||
@trigger_error('Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated since Symfony 3.1, and will be removed in 4.0. Use a different rendering strategy or pass scalar values.', E_USER_DEPRECATED);
|
||||
throw new \InvalidArgumentException('Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is not supported. Use a different rendering strategy or pass scalar values.');
|
||||
}
|
||||
|
||||
return $this->inlineStrategy->render($uri, $request, $options);
|
||||
@@ -83,7 +83,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
return new Response($tag);
|
||||
}
|
||||
|
||||
private function generateSignedFragmentUri($uri, Request $request)
|
||||
private function generateSignedFragmentUri($uri, Request $request): string
|
||||
{
|
||||
if (null === $this->signer) {
|
||||
throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
|
||||
@@ -95,7 +95,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
return substr($fragmentUri, \strlen($request->getSchemeAndHttpHost()));
|
||||
}
|
||||
|
||||
private function containsNonScalars(array $values)
|
||||
private function containsNonScalars(array $values): bool
|
||||
{
|
||||
foreach ($values as $value) {
|
||||
if (\is_array($value)) {
|
||||
|
@@ -37,7 +37,7 @@ class FragmentHandler
|
||||
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
|
||||
* @param bool $debug Whether the debug mode is enabled or not
|
||||
*/
|
||||
public function __construct(RequestStack $requestStack, array $renderers = array(), $debug = false)
|
||||
public function __construct(RequestStack $requestStack, array $renderers = array(), bool $debug = false)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
foreach ($renderers as $renderer) {
|
||||
|
@@ -38,7 +38,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
* @param string $globalDefaultTemplate The global default content (it can be a template name or the content)
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct($templating = null, UriSigner $signer = null, $globalDefaultTemplate = null, $charset = 'utf-8')
|
||||
public function __construct($templating = null, UriSigner $signer = null, string $globalDefaultTemplate = null, string $charset = 'utf-8')
|
||||
{
|
||||
$this->setTemplating($templating);
|
||||
$this->globalDefaultTemplate = $globalDefaultTemplate;
|
||||
@@ -121,12 +121,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
||||
return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function templateExists($template)
|
||||
private function templateExists(string $template): bool
|
||||
{
|
||||
if ($this->templating instanceof EngineInterface) {
|
||||
try {
|
||||
|
@@ -118,9 +118,12 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
|
||||
$subRequest->headers->set('Surrogate-Capability', $request->headers->get('Surrogate-Capability'));
|
||||
}
|
||||
|
||||
if ($session = $request->getSession()) {
|
||||
$subRequest->setSession($session);
|
||||
static $setSession;
|
||||
|
||||
if (null === $setSession) {
|
||||
$setSession = \Closure::bind(function ($subRequest, $request) { $subRequest->session = $request->session; }, null, Request::class);
|
||||
}
|
||||
$setSession($subRequest, $request);
|
||||
|
||||
return $subRequest;
|
||||
}
|
||||
|
@@ -634,23 +634,16 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
|
||||
/**
|
||||
* Records that an event took place.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
* @param string $event The event name
|
||||
*/
|
||||
private function record(Request $request, $event)
|
||||
private function record(Request $request, string $event)
|
||||
{
|
||||
$this->traces[$this->getTraceKey($request)][] = $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the key we use in the "trace" array for a given request.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTraceKey(Request $request)
|
||||
private function getTraceKey(Request $request): string
|
||||
{
|
||||
$path = $request->getPathInfo();
|
||||
if ($qs = $request->getQueryString()) {
|
||||
@@ -663,12 +656,8 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
/**
|
||||
* Checks whether the given (cached) response may be served as "stale" when a revalidation
|
||||
* is currently in progress.
|
||||
*
|
||||
* @param Response $entry
|
||||
*
|
||||
* @return bool true when the stale response may be served, false otherwise
|
||||
*/
|
||||
private function mayServeStaleWhileRevalidate(Response $entry)
|
||||
private function mayServeStaleWhileRevalidate(Response $entry): bool
|
||||
{
|
||||
$timeout = $entry->headers->getCacheControlDirective('stale-while-revalidate');
|
||||
|
||||
@@ -681,12 +670,8 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
|
||||
/**
|
||||
* Waits for the store to release a locked entry.
|
||||
*
|
||||
* @param Request $request The request to wait for
|
||||
*
|
||||
* @return bool true if the lock was released before the internal timeout was hit; false if the wait timeout was exceeded
|
||||
*/
|
||||
private function waitForLock(Request $request)
|
||||
private function waitForLock(Request $request): bool
|
||||
{
|
||||
$wait = 0;
|
||||
while ($this->store->isLocked($request) && $wait < 100) {
|
||||
|
@@ -29,11 +29,9 @@ class Store implements StoreInterface
|
||||
private $locks;
|
||||
|
||||
/**
|
||||
* @param string $root The path to the cache directory
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct($root)
|
||||
public function __construct(string $root)
|
||||
{
|
||||
$this->root = $root;
|
||||
if (!file_exists($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) {
|
||||
|
@@ -23,41 +23,24 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
*/
|
||||
class SubRequestHandler
|
||||
{
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
public static function handle(HttpKernelInterface $kernel, Request $request, $type, $catch)
|
||||
public static function handle(HttpKernelInterface $kernel, Request $request, $type, $catch): Response
|
||||
{
|
||||
// save global state related to trusted headers and proxies
|
||||
$trustedProxies = Request::getTrustedProxies();
|
||||
$trustedHeaderSet = Request::getTrustedHeaderSet();
|
||||
if (\method_exists(Request::class, 'getTrustedHeaderName')) {
|
||||
Request::setTrustedProxies($trustedProxies, -1);
|
||||
$trustedHeaders = array(
|
||||
Request::HEADER_FORWARDED => Request::getTrustedHeaderName(Request::HEADER_FORWARDED, false),
|
||||
Request::HEADER_X_FORWARDED_FOR => Request::getTrustedHeaderName(Request::HEADER_X_FORWARDED_FOR, false),
|
||||
Request::HEADER_X_FORWARDED_HOST => Request::getTrustedHeaderName(Request::HEADER_X_FORWARDED_HOST, false),
|
||||
Request::HEADER_X_FORWARDED_PROTO => Request::getTrustedHeaderName(Request::HEADER_X_FORWARDED_PROTO, false),
|
||||
Request::HEADER_X_FORWARDED_PORT => Request::getTrustedHeaderName(Request::HEADER_X_FORWARDED_PORT, false),
|
||||
);
|
||||
Request::setTrustedProxies($trustedProxies, $trustedHeaderSet);
|
||||
} else {
|
||||
$trustedHeaders = array(
|
||||
Request::HEADER_FORWARDED => 'FORWARDED',
|
||||
Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
|
||||
Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
|
||||
Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
|
||||
Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
|
||||
);
|
||||
}
|
||||
|
||||
// remove untrusted values
|
||||
$remoteAddr = $request->server->get('REMOTE_ADDR');
|
||||
if (!IpUtils::checkIp($remoteAddr, $trustedProxies)) {
|
||||
foreach ($trustedHeaders as $key => $name) {
|
||||
if ($trustedHeaderSet & $key) {
|
||||
$request->headers->remove($name);
|
||||
}
|
||||
$trustedHeaders = array(
|
||||
'FORWARDED' => $trustedHeaderSet & Request::HEADER_FORWARDED,
|
||||
'X_FORWARDED_FOR' => $trustedHeaderSet & Request::HEADER_X_FORWARDED_FOR,
|
||||
'X_FORWARDED_HOST' => $trustedHeaderSet & Request::HEADER_X_FORWARDED_HOST,
|
||||
'X_FORWARDED_PROTO' => $trustedHeaderSet & Request::HEADER_X_FORWARDED_PROTO,
|
||||
'X_FORWARDED_PORT' => $trustedHeaderSet & Request::HEADER_X_FORWARDED_PORT,
|
||||
);
|
||||
foreach (array_filter($trustedHeaders) as $name => $key) {
|
||||
$request->headers->remove($name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +59,13 @@ class SubRequestHandler
|
||||
// set trusted values, reusing as much as possible the global trusted settings
|
||||
if (Request::HEADER_FORWARDED & $trustedHeaderSet) {
|
||||
$trustedValues[0] .= sprintf(';host="%s";proto=%s', $request->getHttpHost(), $request->getScheme());
|
||||
$request->headers->set($trustedHeaders[Request::HEADER_FORWARDED], implode(', ', $trustedValues));
|
||||
$request->headers->set('Forwarded', implode(', ', $trustedValues));
|
||||
}
|
||||
if (Request::HEADER_X_FORWARDED_FOR & $trustedHeaderSet) {
|
||||
$request->headers->set($trustedHeaders[Request::HEADER_X_FORWARDED_FOR], implode(', ', $trustedIps));
|
||||
$request->headers->set('X-Forwarded-For', implode(', ', $trustedIps));
|
||||
} elseif (!(Request::HEADER_FORWARDED & $trustedHeaderSet)) {
|
||||
Request::setTrustedProxies($trustedProxies, $trustedHeaderSet | Request::HEADER_X_FORWARDED_FOR);
|
||||
$request->headers->set($trustedHeaders[Request::HEADER_X_FORWARDED_FOR], implode(', ', $trustedIps));
|
||||
$request->headers->set('X-Forwarded-For', implode(', ', $trustedIps));
|
||||
}
|
||||
|
||||
// fix the client IP address by setting it to 127.0.0.1,
|
||||
|
33
vendor/symfony/http-kernel/HttpKernel.php
vendored
33
vendor/symfony/http-kernel/HttpKernel.php
vendored
@@ -51,9 +51,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
$this->argumentResolver = $argumentResolver;
|
||||
|
||||
if (null === $this->argumentResolver) {
|
||||
@trigger_error(sprintf('As of 3.1 an %s is used to resolve arguments. In 4.0 the $argumentResolver becomes the %s if no other is provided instead of using the $resolver argument.', ArgumentResolverInterface::class, ArgumentResolver::class), E_USER_DEPRECATED);
|
||||
// fallback in case of deprecations
|
||||
$this->argumentResolver = $resolver;
|
||||
$this->argumentResolver = new ArgumentResolver();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +116,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
* @throws \LogicException If one of the listener does not behave as expected
|
||||
* @throws NotFoundHttpException When controller cannot be found
|
||||
*/
|
||||
private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
|
||||
private function handleRaw(Request $request, int $type = self::MASTER_REQUEST)
|
||||
{
|
||||
$this->requestStack->push($request);
|
||||
|
||||
@@ -157,9 +155,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
|
||||
if ($event->hasResponse()) {
|
||||
$response = $event->getResponse();
|
||||
}
|
||||
|
||||
if (!$response instanceof Response) {
|
||||
} else {
|
||||
$msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));
|
||||
|
||||
// the user may have forgotten to return something
|
||||
@@ -184,7 +180,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
*
|
||||
* @throws \RuntimeException if the passed object is not a Response instance
|
||||
*/
|
||||
private function filterResponse(Response $response, Request $request, $type)
|
||||
private function filterResponse(Response $response, Request $request, int $type)
|
||||
{
|
||||
$event = new FilterResponseEvent($this, $request, $type, $response);
|
||||
|
||||
@@ -201,11 +197,8 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
* Note that the order of the operations is important here, otherwise
|
||||
* operations such as {@link RequestStack::getParentRequest()} can lead to
|
||||
* weird results.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $type
|
||||
*/
|
||||
private function finishRequest(Request $request, $type)
|
||||
private function finishRequest(Request $request, int $type)
|
||||
{
|
||||
$this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
|
||||
$this->requestStack->pop();
|
||||
@@ -216,13 +209,11 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
*
|
||||
* @param \Exception $e An \Exception instance
|
||||
* @param Request $request A Request instance
|
||||
* @param int $type The type of the request
|
||||
*
|
||||
* @return Response A Response instance
|
||||
* @param int $type The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function handleException(\Exception $e, $request, $type)
|
||||
private function handleException(\Exception $e, Request $request, int $type): Response
|
||||
{
|
||||
$event = new GetResponseForExceptionEvent($this, $request, $type, $e);
|
||||
$this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
|
||||
@@ -239,13 +230,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
$response = $event->getResponse();
|
||||
|
||||
// the developer asked for a specific status code
|
||||
if ($response->headers->has('X-Status-Code')) {
|
||||
@trigger_error(sprintf('Using the X-Status-Code header is deprecated since Symfony 3.3 and will be removed in 4.0. Use %s::allowCustomResponseCode() instead.', GetResponseForExceptionEvent::class), E_USER_DEPRECATED);
|
||||
|
||||
$response->setStatusCode($response->headers->get('X-Status-Code'));
|
||||
|
||||
$response->headers->remove('X-Status-Code');
|
||||
} elseif (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
|
||||
if (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
|
||||
// ensure that we actually have an error response
|
||||
if ($e instanceof HttpExceptionInterface) {
|
||||
// keep the HTTP status code and headers
|
||||
@@ -263,7 +248,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function varToString($var)
|
||||
private function varToString($var): string
|
||||
{
|
||||
if (\is_object($var)) {
|
||||
return sprintf('Object(%s)', \get_class($var));
|
||||
|
256
vendor/symfony/http-kernel/Kernel.php
vendored
256
vendor/symfony/http-kernel/Kernel.php
vendored
@@ -13,7 +13,6 @@ namespace Symfony\Component\HttpKernel;
|
||||
|
||||
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
|
||||
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
|
||||
use Symfony\Component\ClassLoader\ClassCollectionLoader;
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
@@ -33,7 +32,6 @@ use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
|
||||
use Symfony\Component\HttpKernel\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||
@@ -52,7 +50,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
*/
|
||||
protected $bundles = array();
|
||||
|
||||
protected $bundleMap;
|
||||
protected $container;
|
||||
protected $rootDir;
|
||||
protected $environment;
|
||||
@@ -60,31 +57,26 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
protected $booted = false;
|
||||
protected $name;
|
||||
protected $startTime;
|
||||
protected $loadClassCache;
|
||||
|
||||
private $projectDir;
|
||||
private $warmupDir;
|
||||
private $requestStackSize = 0;
|
||||
private $resetServices = false;
|
||||
|
||||
const VERSION = '3.4.14';
|
||||
const VERSION_ID = 30414;
|
||||
const MAJOR_VERSION = 3;
|
||||
const MINOR_VERSION = 4;
|
||||
const RELEASE_VERSION = 14;
|
||||
const VERSION = '4.1.3';
|
||||
const VERSION_ID = 40103;
|
||||
const MAJOR_VERSION = 4;
|
||||
const MINOR_VERSION = 1;
|
||||
const RELEASE_VERSION = 3;
|
||||
const EXTRA_VERSION = '';
|
||||
|
||||
const END_OF_MAINTENANCE = '11/2020';
|
||||
const END_OF_LIFE = '11/2021';
|
||||
const END_OF_MAINTENANCE = '01/2019';
|
||||
const END_OF_LIFE = '07/2019';
|
||||
|
||||
/**
|
||||
* @param string $environment The environment
|
||||
* @param bool $debug Whether to enable debugging or not
|
||||
*/
|
||||
public function __construct($environment, $debug)
|
||||
public function __construct(string $environment, bool $debug)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
$this->debug = (bool) $debug;
|
||||
$this->debug = $debug;
|
||||
$this->rootDir = $this->getRootDir();
|
||||
$this->name = $this->getName();
|
||||
}
|
||||
@@ -124,10 +116,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
$_SERVER['SHELL_VERBOSITY'] = 3;
|
||||
}
|
||||
|
||||
if ($this->loadClassCache) {
|
||||
$this->doLoadClassCache($this->loadClassCache[0], $this->loadClassCache[1]);
|
||||
}
|
||||
|
||||
// init bundles
|
||||
$this->initializeBundles();
|
||||
|
||||
@@ -224,26 +212,13 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBundle($name, $first = true/*, $noDeprecation = false */)
|
||||
public function getBundle($name)
|
||||
{
|
||||
$noDeprecation = false;
|
||||
if (\func_num_args() >= 3) {
|
||||
$noDeprecation = func_get_arg(2);
|
||||
}
|
||||
|
||||
if (!$first && !$noDeprecation) {
|
||||
@trigger_error(sprintf('Passing "false" as the second argument to "%s()" is deprecated as of 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (!isset($this->bundleMap[$name])) {
|
||||
if (!isset($this->bundles[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your %s.php file?', $name, \get_class($this)));
|
||||
}
|
||||
|
||||
if (true === $first) {
|
||||
return $this->bundleMap[$name][0];
|
||||
}
|
||||
|
||||
return $this->bundleMap[$name];
|
||||
return $this->bundles[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,32 +245,27 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
|
||||
$overridePath = substr($path, 9);
|
||||
$resourceBundle = null;
|
||||
$bundles = $this->getBundle($bundleName, false, true);
|
||||
$bundle = $this->getBundle($bundleName);
|
||||
$files = array();
|
||||
|
||||
foreach ($bundles as $bundle) {
|
||||
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
|
||||
if (null !== $resourceBundle) {
|
||||
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
|
||||
$file,
|
||||
$resourceBundle,
|
||||
$dir.'/'.$bundles[0]->getName().$overridePath
|
||||
));
|
||||
}
|
||||
|
||||
if ($first) {
|
||||
return $file;
|
||||
}
|
||||
$files[] = $file;
|
||||
if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) {
|
||||
if (null !== $resourceBundle) {
|
||||
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.',
|
||||
$file,
|
||||
$resourceBundle,
|
||||
$dir.'/'.$bundle->getName().$overridePath
|
||||
));
|
||||
}
|
||||
|
||||
if (file_exists($file = $bundle->getPath().'/'.$path)) {
|
||||
if ($first && !$isResource) {
|
||||
return $file;
|
||||
}
|
||||
$files[] = $file;
|
||||
$resourceBundle = $bundle->getName();
|
||||
$files[] = $file;
|
||||
}
|
||||
|
||||
if (file_exists($file = $bundle->getPath().'/'.$path)) {
|
||||
if ($first && !$isResource) {
|
||||
return $file;
|
||||
}
|
||||
$files[] = $file;
|
||||
$resourceBundle = $bundle->getName();
|
||||
}
|
||||
|
||||
if (\count($files) > 0) {
|
||||
@@ -379,43 +349,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the PHP class cache.
|
||||
*
|
||||
* This methods only registers the fact that you want to load the cache classes.
|
||||
* The cache will actually only be loaded when the Kernel is booted.
|
||||
*
|
||||
* That optimization is mainly useful when using the HttpCache class in which
|
||||
* case the class cache is not loaded if the Response is in the cache.
|
||||
*
|
||||
* @param string $name The cache name prefix
|
||||
* @param string $extension File extension of the resulting file
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. The class cache is not needed anymore when using PHP 7.0.
|
||||
*/
|
||||
public function loadClassCache($name = 'classes', $extension = '.php')
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->loadClassCache = array($name, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setClassCache(array $classes)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
file_put_contents(($this->warmupDir ?: $this->getCacheDir()).'/classes.map', sprintf('<?php return %s;', var_export($classes, true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@@ -457,83 +390,28 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
* Gets the patterns defining the classes to parse and cache for annotations.
|
||||
*/
|
||||
protected function doLoadClassCache($name, $extension)
|
||||
public function getAnnotatedClassesToCompile(): array
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
@trigger_error(__METHOD__.'() is deprecated since Symfony 3.3, to be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
$cacheDir = $this->warmupDir ?: $this->getCacheDir();
|
||||
|
||||
if (!$this->booted && is_file($cacheDir.'/classes.map')) {
|
||||
ClassCollectionLoader::load(include($cacheDir.'/classes.map'), $cacheDir, $name, $this->debug, false, $extension);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the data structures related to the bundle management.
|
||||
*
|
||||
* - the bundles property maps a bundle name to the bundle instance,
|
||||
* - the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first).
|
||||
* Initializes bundles.
|
||||
*
|
||||
* @throws \LogicException if two bundles share a common name
|
||||
* @throws \LogicException if a bundle tries to extend a non-registered bundle
|
||||
* @throws \LogicException if a bundle tries to extend itself
|
||||
* @throws \LogicException if two bundles extend the same ancestor
|
||||
*/
|
||||
protected function initializeBundles()
|
||||
{
|
||||
// init bundles
|
||||
$this->bundles = array();
|
||||
$topMostBundles = array();
|
||||
$directChildren = array();
|
||||
|
||||
foreach ($this->registerBundles() as $bundle) {
|
||||
$name = $bundle->getName();
|
||||
if (isset($this->bundles[$name])) {
|
||||
throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
|
||||
}
|
||||
$this->bundles[$name] = $bundle;
|
||||
|
||||
if ($parentName = $bundle->getParent()) {
|
||||
@trigger_error('Bundle inheritance is deprecated as of 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
|
||||
if (isset($directChildren[$parentName])) {
|
||||
throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
|
||||
}
|
||||
if ($parentName == $name) {
|
||||
throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
|
||||
}
|
||||
$directChildren[$parentName] = $name;
|
||||
} else {
|
||||
$topMostBundles[$name] = $bundle;
|
||||
}
|
||||
}
|
||||
|
||||
// look for orphans
|
||||
if (!empty($directChildren) && \count($diff = array_diff_key($directChildren, $this->bundles))) {
|
||||
$diff = array_keys($diff);
|
||||
|
||||
throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
|
||||
}
|
||||
|
||||
// inheritance
|
||||
$this->bundleMap = array();
|
||||
foreach ($topMostBundles as $name => $bundle) {
|
||||
$bundleMap = array($bundle);
|
||||
$hierarchy = array($name);
|
||||
|
||||
while (isset($directChildren[$name])) {
|
||||
$name = $directChildren[$name];
|
||||
array_unshift($bundleMap, $this->bundles[$name]);
|
||||
$hierarchy[] = $name;
|
||||
}
|
||||
|
||||
foreach ($hierarchy as $hierarchyBundle) {
|
||||
$this->bundleMap[$hierarchyBundle] = $bundleMap;
|
||||
array_pop($bundleMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,56 +576,26 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
foreach ($this->bundles as $name => $bundle) {
|
||||
$bundles[$name] = \get_class($bundle);
|
||||
$bundlesMetadata[$name] = array(
|
||||
'parent' => $bundle->getParent(),
|
||||
'path' => $bundle->getPath(),
|
||||
'namespace' => $bundle->getNamespace(),
|
||||
);
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
array(
|
||||
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
|
||||
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
|
||||
'kernel.environment' => $this->environment,
|
||||
'kernel.debug' => $this->debug,
|
||||
'kernel.name' => $this->name,
|
||||
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
|
||||
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
|
||||
'kernel.bundles' => $bundles,
|
||||
'kernel.bundles_metadata' => $bundlesMetadata,
|
||||
'kernel.charset' => $this->getCharset(),
|
||||
'kernel.container_class' => $this->getContainerClass(),
|
||||
),
|
||||
$this->getEnvParameters(false)
|
||||
return array(
|
||||
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir,
|
||||
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
|
||||
'kernel.environment' => $this->environment,
|
||||
'kernel.debug' => $this->debug,
|
||||
'kernel.name' => $this->name,
|
||||
'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir,
|
||||
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
|
||||
'kernel.bundles' => $bundles,
|
||||
'kernel.bundles_metadata' => $bundlesMetadata,
|
||||
'kernel.charset' => $this->getCharset(),
|
||||
'kernel.container_class' => $this->getContainerClass(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the environment parameters.
|
||||
*
|
||||
* Only the parameters starting with "SYMFONY__" are considered.
|
||||
*
|
||||
* @return array An array of parameters
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0
|
||||
*/
|
||||
protected function getEnvParameters()
|
||||
{
|
||||
if (0 === \func_num_args() || func_get_arg(0)) {
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated as of 3.3 and will be removed in 4.0. Use the %%env()%% syntax to get the value of any environment variable from configuration files instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$parameters = array();
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
if (0 === strpos($key, 'SYMFONY__')) {
|
||||
@trigger_error(sprintf('The support of special environment variables that start with SYMFONY__ (such as "%s") is deprecated as of 3.3 and will be removed in 4.0. Use the %%env()%% syntax instead to get the value of environment variables in configuration files.', $key), E_USER_DEPRECATED);
|
||||
$parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the service container.
|
||||
*
|
||||
@@ -776,7 +624,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
}
|
||||
|
||||
$container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));
|
||||
$container->addResource(new EnvParametersResource('SYMFONY__'));
|
||||
|
||||
return $container;
|
||||
}
|
||||
@@ -854,7 +701,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
'file' => $cache->getPath(),
|
||||
'as_files' => true,
|
||||
'debug' => $this->debug,
|
||||
'inline_class_loader_parameter' => \PHP_VERSION_ID >= 70000 && !$this->loadClassCache && !class_exists(ClassCollectionLoader::class, false) ? 'container.dumper.inline_class_loader' : null,
|
||||
'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
|
||||
));
|
||||
|
||||
@@ -946,11 +792,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
|
||||
$output .= $rawChunk;
|
||||
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
|
||||
unset($tokens, $rawChunk);
|
||||
gc_mem_caches();
|
||||
}
|
||||
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
|
||||
unset($tokens, $rawChunk);
|
||||
gc_mem_caches();
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -962,11 +806,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
||||
|
||||
public function unserialize($data)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 70000) {
|
||||
list($environment, $debug) = unserialize($data, array('allowed_classes' => false));
|
||||
} else {
|
||||
list($environment, $debug) = unserialize($data);
|
||||
}
|
||||
list($environment, $debug) = unserialize($data, array('allowed_classes' => false));
|
||||
|
||||
$this->__construct($environment, $debug);
|
||||
}
|
||||
|
16
vendor/symfony/http-kernel/KernelInterface.php
vendored
16
vendor/symfony/http-kernel/KernelInterface.php
vendored
@@ -18,7 +18,7 @@ use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
/**
|
||||
* The Kernel is the heart of the Symfony system.
|
||||
*
|
||||
* It manages an environment made of bundles.
|
||||
* It manages an environment made of application kernel and bundles.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
@@ -56,22 +56,18 @@ interface KernelInterface extends HttpKernelInterface, \Serializable
|
||||
public function getBundles();
|
||||
|
||||
/**
|
||||
* Returns a bundle and optionally its descendants by its name.
|
||||
* Returns a bundle.
|
||||
*
|
||||
* The second argument is deprecated as of 3.4 and will be removed in 4.0. This method
|
||||
* will always return an instance of BundleInterface in 4.0.
|
||||
* @param string $name Bundle name
|
||||
*
|
||||
* @param string $name Bundle name
|
||||
* @param bool $first Whether to return the first bundle only or together with its descendants
|
||||
*
|
||||
* @return BundleInterface|BundleInterface[] A BundleInterface instance or an array of BundleInterface instances if $first is false
|
||||
* @return BundleInterface A BundleInterface instance
|
||||
*
|
||||
* @throws \InvalidArgumentException when the bundle is not enabled
|
||||
*/
|
||||
public function getBundle($name, $first = true);
|
||||
public function getBundle($name);
|
||||
|
||||
/**
|
||||
* Returns the file path for a given resource.
|
||||
* Returns the file path for a given bundle resource.
|
||||
*
|
||||
* A Resource can be a file or a directory.
|
||||
*
|
||||
|
@@ -11,12 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Log;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* DebugLoggerInterface.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @method clear() Removes all log records.
|
||||
*/
|
||||
interface DebugLoggerInterface
|
||||
{
|
||||
@@ -27,14 +27,23 @@ interface DebugLoggerInterface
|
||||
* timestamp, message, priority, and priorityName.
|
||||
* It can also have an optional context key containing an array.
|
||||
*
|
||||
* @param Request|null $request The request to get logs for
|
||||
*
|
||||
* @return array An array of logs
|
||||
*/
|
||||
public function getLogs();
|
||||
public function getLogs(/* Request $request = null */);
|
||||
|
||||
/**
|
||||
* Returns the number of errors.
|
||||
*
|
||||
* @param Request|null $request The request to count logs for
|
||||
*
|
||||
* @return int The number of errors
|
||||
*/
|
||||
public function countErrors();
|
||||
public function countErrors(/* Request $request = null */);
|
||||
|
||||
/**
|
||||
* Removes all log records.
|
||||
*/
|
||||
public function clear();
|
||||
}
|
||||
|
11
vendor/symfony/http-kernel/Log/Logger.php
vendored
11
vendor/symfony/http-kernel/Log/Logger.php
vendored
@@ -37,7 +37,7 @@ class Logger extends AbstractLogger
|
||||
private $formatter;
|
||||
private $handle;
|
||||
|
||||
public function __construct($minLevel = null, $output = 'php://stderr', callable $formatter = null)
|
||||
public function __construct(string $minLevel = null, $output = 'php://stderr', callable $formatter = null)
|
||||
{
|
||||
if (null === $minLevel) {
|
||||
$minLevel = LogLevel::WARNING;
|
||||
@@ -80,14 +80,7 @@ class Logger extends AbstractLogger
|
||||
fwrite($this->handle, $formatter($level, $message, $context));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function format($level, $message, array $context)
|
||||
private function format(string $level, string $message, array $context): string
|
||||
{
|
||||
if (false !== strpos($message, '{')) {
|
||||
$replacements = array();
|
||||
|
@@ -30,11 +30,9 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
*
|
||||
* Example : "file:/path/to/the/storage/folder"
|
||||
*
|
||||
* @param string $dsn The DSN
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct($dsn)
|
||||
public function __construct(string $dsn)
|
||||
{
|
||||
if (0 !== strpos($dsn, 'file:')) {
|
||||
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn "%s". The expected format is "file:/path/to/the/storage/folder".', $dsn));
|
||||
@@ -146,7 +144,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
|
||||
// when there are errors in sub-requests, the parent and/or children tokens
|
||||
// may equal the profile token, resulting in infinite loops
|
||||
$parentToken = $profile->getParentToken() !== $profileToken ? $profile->getParentToken() : null;
|
||||
$childrenToken = array_filter(array_map(function ($p) use ($profileToken) {
|
||||
$childrenToken = array_filter(array_map(function (Profile $p) use ($profileToken) {
|
||||
return $profileToken !== $p->getToken() ? $p->getToken() : null;
|
||||
}, $profile->getChildren()));
|
||||
|
||||
|
20
vendor/symfony/http-kernel/Profiler/Profile.php
vendored
20
vendor/symfony/http-kernel/Profiler/Profile.php
vendored
@@ -43,10 +43,7 @@ class Profile
|
||||
*/
|
||||
private $children = array();
|
||||
|
||||
/**
|
||||
* @param string $token The token
|
||||
*/
|
||||
public function __construct($token)
|
||||
public function __construct(string $token)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
@@ -74,7 +71,7 @@ class Profile
|
||||
/**
|
||||
* Sets the parent token.
|
||||
*/
|
||||
public function setParent(Profile $parent)
|
||||
public function setParent(self $parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
@@ -213,12 +210,23 @@ class Profile
|
||||
/**
|
||||
* Adds the child token.
|
||||
*/
|
||||
public function addChild(Profile $child)
|
||||
public function addChild(self $child)
|
||||
{
|
||||
$this->children[] = $child;
|
||||
$child->setParent($this);
|
||||
}
|
||||
|
||||
public function getChildByToken(string $token): ?self
|
||||
{
|
||||
foreach ($this->children as $child) {
|
||||
if ($token === $child->getToken()) {
|
||||
return $child;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Collector by name.
|
||||
*
|
||||
|
19
vendor/symfony/http-kernel/Profiler/Profiler.php
vendored
19
vendor/symfony/http-kernel/Profiler/Profiler.php
vendored
@@ -36,14 +36,11 @@ class Profiler
|
||||
private $initiallyEnabled = true;
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
* @param bool $enable The initial enabled state
|
||||
*/
|
||||
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, $enable = true)
|
||||
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, bool $enable = true)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
$this->logger = $logger;
|
||||
$this->initiallyEnabled = $this->enabled = (bool) $enable;
|
||||
$this->initiallyEnabled = $this->enabled = $enable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,6 +156,10 @@ class Profiler
|
||||
$profile->setIp('Unknown');
|
||||
}
|
||||
|
||||
if ($prevToken = $response->headers->get('X-Debug-Token')) {
|
||||
$response->headers->set('X-Previous-Debug-Token', $prevToken);
|
||||
}
|
||||
|
||||
$response->headers->set('X-Debug-Token', $profile->getToken());
|
||||
|
||||
foreach ($this->collectors as $collector) {
|
||||
@@ -174,10 +175,6 @@ class Profiler
|
||||
public function reset()
|
||||
{
|
||||
foreach ($this->collectors as $collector) {
|
||||
if (!method_exists($collector, 'reset')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$collector->reset();
|
||||
}
|
||||
$this->enabled = $this->initiallyEnabled;
|
||||
@@ -211,10 +208,6 @@ class Profiler
|
||||
*/
|
||||
public function add(DataCollectorInterface $collector)
|
||||
{
|
||||
if (!method_exists($collector, 'reset')) {
|
||||
@trigger_error(sprintf('Implementing "%s" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', DataCollectorInterface::class, \get_class($collector)), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->collectors[$collector->getName()] = $collector;
|
||||
}
|
||||
|
||||
|
@@ -12,11 +12,8 @@
|
||||
namespace Symfony\Component\HttpKernel\Tests\Bundle;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
|
||||
|
||||
class BundleTest extends TestCase
|
||||
@@ -31,24 +28,6 @@ class BundleTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Auto-registration of the command "Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand" is deprecated since Symfony 3.4 and won't be supported in 4.0. Use PSR-4 based service discovery instead.
|
||||
*/
|
||||
public function testRegisterCommands()
|
||||
{
|
||||
$cmd = new FooCommand();
|
||||
$app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
|
||||
$app->expects($this->once())->method('add')->with($this->equalTo($cmd));
|
||||
|
||||
$bundle = new ExtensionPresentBundle();
|
||||
$bundle->registerCommands($app);
|
||||
|
||||
$bundle2 = new ExtensionAbsentBundle();
|
||||
|
||||
$this->assertNull($bundle2->registerCommands($app));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
|
||||
@@ -59,20 +38,6 @@ class BundleTest extends TestCase
|
||||
$bundle->getContainerExtension();
|
||||
}
|
||||
|
||||
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
|
||||
|
||||
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
|
||||
// add() is never called when the found command classes are already registered as services
|
||||
$application->expects($this->never())->method('add');
|
||||
|
||||
$bundle = new ExtensionPresentBundle();
|
||||
$bundle->setContainer($container);
|
||||
$bundle->registerCommands($application);
|
||||
}
|
||||
|
||||
public function testBundleNameIsGuessedFromClass()
|
||||
{
|
||||
$bundle = new GuessedNameBundle();
|
||||
|
@@ -39,21 +39,6 @@ class ChainCacheClearerTest extends TestCase
|
||||
$chainClearer->clear(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectClearerUsingAdd()
|
||||
{
|
||||
$clearer = $this->getMockClearer();
|
||||
$clearer
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$chainClearer = new ChainCacheClearer();
|
||||
$chainClearer->add($clearer);
|
||||
$chainClearer->clear(self::$cacheDir);
|
||||
}
|
||||
|
||||
protected function getMockClearer()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface')->getMock();
|
||||
|
@@ -45,25 +45,4 @@ class Psr6CacheClearerTest extends TestCase
|
||||
{
|
||||
(new Psr6CacheClearer())->clearPool('unknown');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer::addPool() method is deprecated since Symfony 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead.
|
||||
*/
|
||||
public function testClearPoolsInjectedByAdder()
|
||||
{
|
||||
$pool1 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool1
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$pool2 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
|
||||
$pool2
|
||||
->expects($this->once())
|
||||
->method('clear');
|
||||
|
||||
$clearer = new Psr6CacheClearer(array('pool1' => $pool1));
|
||||
$clearer->addPool($pool2);
|
||||
$clearer->clear('');
|
||||
}
|
||||
}
|
||||
|
@@ -38,34 +38,6 @@ class CacheWarmerAggregateTest extends TestCase
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectWarmersUsingAdd()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('warmUp');
|
||||
$aggregate = new CacheWarmerAggregate();
|
||||
$aggregate->add($warmer);
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectWarmersUsingSetWarmers()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
$warmer
|
||||
->expects($this->once())
|
||||
->method('warmUp');
|
||||
$aggregate = new CacheWarmerAggregate();
|
||||
$aggregate->setWarmers(array($warmer));
|
||||
$aggregate->warmUp(self::$cacheDir);
|
||||
}
|
||||
|
||||
public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled()
|
||||
{
|
||||
$warmer = $this->getCacheWarmerMock();
|
||||
|
21
vendor/symfony/http-kernel/Tests/ClientTest.php
vendored
21
vendor/symfony/http-kernel/Tests/ClientTest.php
vendored
@@ -100,8 +100,8 @@ class ClientTest extends TestCase
|
||||
$client = new Client($kernel);
|
||||
|
||||
$files = array(
|
||||
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => 1, 'error' => UPLOAD_ERR_OK),
|
||||
new UploadedFile($source, 'original', 'mime/original', 1, UPLOAD_ERR_OK, true),
|
||||
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK),
|
||||
new UploadedFile($source, 'original', 'mime/original', UPLOAD_ERR_OK, true),
|
||||
);
|
||||
|
||||
$file = null;
|
||||
@@ -116,8 +116,7 @@ class ClientTest extends TestCase
|
||||
|
||||
$this->assertEquals('original', $file->getClientOriginalName());
|
||||
$this->assertEquals('mime/original', $file->getClientMimeType());
|
||||
$this->assertSame(1, $file->getClientSize());
|
||||
$this->assertTrue($file->isValid());
|
||||
$this->assertEquals(1, $file->getSize());
|
||||
}
|
||||
|
||||
$file->move(\dirname($target), basename($target));
|
||||
@@ -150,15 +149,19 @@ class ClientTest extends TestCase
|
||||
|
||||
$file = $this
|
||||
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
|
||||
->setConstructorArgs(array($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true))
|
||||
->setMethods(array('getSize'))
|
||||
->setConstructorArgs(array($source, 'original', 'mime/original', UPLOAD_ERR_OK, true))
|
||||
->setMethods(array('getSize', 'getClientSize'))
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$file->expects($this->once())
|
||||
/* should be modified when the getClientSize will be removed */
|
||||
$file->expects($this->any())
|
||||
->method('getSize')
|
||||
->will($this->returnValue(INF))
|
||||
;
|
||||
$file->expects($this->any())
|
||||
->method('getClientSize')
|
||||
->will($this->returnValue(INF))
|
||||
;
|
||||
|
||||
$client->request('POST', '/', array(), array($file));
|
||||
|
||||
@@ -172,7 +175,7 @@ class ClientTest extends TestCase
|
||||
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
|
||||
$this->assertEquals('mime/original', $file->getClientMimeType());
|
||||
$this->assertEquals('original', $file->getClientOriginalName());
|
||||
$this->assertEquals(0, $file->getClientSize());
|
||||
$this->assertEquals(0, $file->getSize());
|
||||
|
||||
unlink($source);
|
||||
}
|
||||
|
@@ -1,110 +0,0 @@
|
||||
<?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\Tests\Config;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpKernel\Config\EnvParametersResource;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class EnvParametersResourceTest extends TestCase
|
||||
{
|
||||
protected $prefix = '__DUMMY_';
|
||||
protected $initialEnv;
|
||||
protected $resource;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->initialEnv = array(
|
||||
$this->prefix.'1' => 'foo',
|
||||
$this->prefix.'2' => 'bar',
|
||||
);
|
||||
|
||||
foreach ($this->initialEnv as $key => $value) {
|
||||
$_SERVER[$key] = $value;
|
||||
}
|
||||
|
||||
$this->resource = new EnvParametersResource($this->prefix);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
foreach ($_SERVER as $key => $value) {
|
||||
if (0 === strpos($key, $this->prefix)) {
|
||||
unset($_SERVER[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetResource()
|
||||
{
|
||||
$this->assertSame(
|
||||
array('prefix' => $this->prefix, 'variables' => $this->initialEnv),
|
||||
$this->resource->getResource(),
|
||||
'->getResource() returns the resource'
|
||||
);
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertSame(
|
||||
serialize(array('prefix' => $this->prefix, 'variables' => $this->initialEnv)),
|
||||
(string) $this->resource
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshNotChanged()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns true if the variables have not changed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshValueChanged()
|
||||
{
|
||||
reset($this->initialEnv);
|
||||
$_SERVER[key($this->initialEnv)] = 'baz';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns false if a variable has been changed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshValueRemoved()
|
||||
{
|
||||
reset($this->initialEnv);
|
||||
unset($_SERVER[key($this->initialEnv)]);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns false if a variable has been removed'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsFreshValueAdded()
|
||||
{
|
||||
$_SERVER[$this->prefix.'3'] = 'foo';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->resource->isFresh(time()),
|
||||
'->isFresh() returns false if a variable has been added'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$this->assertEquals($this->resource, unserialize(serialize($this->resource)));
|
||||
}
|
||||
}
|
@@ -12,10 +12,12 @@
|
||||
namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
|
||||
|
||||
class ServiceValueResolverTest extends TestCase
|
||||
{
|
||||
@@ -85,6 +87,25 @@ class ServiceValueResolverTest extends TestCase
|
||||
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Cannot autowire argument $dummy of "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyController::index()": it references class "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyService" but no such service exists.
|
||||
*/
|
||||
public function testErrorIsTruncated()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
|
||||
|
||||
$container->register('argument_resolver.service', ServiceValueResolver::class)->addArgument(null)->setPublic(true);
|
||||
$container->register(DummyController::class)->addTag('controller.service_arguments')->setPublic(true);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$request = $this->requestWithAttributes(array('_controller' => array(DummyController::class, 'index')));
|
||||
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
|
||||
$container->get('argument_resolver.service')->resolve($request, $argument)->current();
|
||||
}
|
||||
|
||||
private function requestWithAttributes(array $attributes)
|
||||
{
|
||||
$request = Request::create('/');
|
||||
@@ -110,3 +131,10 @@ class ServiceValueResolverTest extends TestCase
|
||||
class DummyService
|
||||
{
|
||||
}
|
||||
|
||||
class DummyController
|
||||
{
|
||||
public function index(DummyService $dummy)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
76
vendor/symfony/http-kernel/Tests/Controller/ArgumentResolver/TraceableValueResolverTest.php
vendored
Normal file
76
vendor/symfony/http-kernel/Tests/Controller/ArgumentResolver/TraceableValueResolverTest.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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\Tests\Controller\ArgumentResolver;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
|
||||
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
|
||||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
class TraceableValueResolverTest extends TestCase
|
||||
{
|
||||
public function testTimingsInSupports()
|
||||
{
|
||||
$stopwatch = new Stopwatch();
|
||||
$resolver = new TraceableValueResolver(new ResolverStub(), $stopwatch);
|
||||
$argument = new ArgumentMetadata('dummy', 'string', false, false, null);
|
||||
$request = new Request();
|
||||
|
||||
$this->assertTrue($resolver->supports($request, $argument));
|
||||
|
||||
$event = $stopwatch->getEvent(ResolverStub::class.'::supports');
|
||||
$this->assertCount(1, $event->getPeriods());
|
||||
}
|
||||
|
||||
public function testTimingsInResolve()
|
||||
{
|
||||
$stopwatch = new Stopwatch();
|
||||
$resolver = new TraceableValueResolver(new ResolverStub(), $stopwatch);
|
||||
$argument = new ArgumentMetadata('dummy', 'string', false, false, null);
|
||||
$request = new Request();
|
||||
|
||||
$iterable = $resolver->resolve($request, $argument);
|
||||
|
||||
foreach ($iterable as $index => $resolved) {
|
||||
$event = $stopwatch->getEvent(ResolverStub::class.'::resolve');
|
||||
$this->assertTrue($event->isStarted());
|
||||
$this->assertEmpty($event->getPeriods());
|
||||
switch ($index) {
|
||||
case 0:
|
||||
$this->assertEquals('first', $resolved);
|
||||
break;
|
||||
case 1:
|
||||
$this->assertEquals('second', $resolved);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$event = $stopwatch->getEvent(ResolverStub::class.'::resolve');
|
||||
$this->assertCount(1, $event->getPeriods());
|
||||
}
|
||||
}
|
||||
|
||||
class ResolverStub implements ArgumentValueResolverInterface
|
||||
{
|
||||
public function supports(Request $request, ArgumentMetadata $argument)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resolve(Request $request, ArgumentMetadata $argument)
|
||||
{
|
||||
yield 'first';
|
||||
yield 'second';
|
||||
}
|
||||
}
|
@@ -152,9 +152,6 @@ class ArgumentResolverTest extends TestCase
|
||||
$this->assertEquals(array($request), self::$resolver->getArguments($request, $controller), '->getArguments() injects the request when extended');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testGetVariadicArguments()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
@@ -166,7 +163,6 @@ class ArgumentResolverTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetVariadicArgumentsWithoutArrayInRequest()
|
||||
@@ -180,7 +176,6 @@ class ArgumentResolverTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testGetArgumentWithoutArray()
|
||||
@@ -210,9 +205,6 @@ class ArgumentResolverTest extends TestCase
|
||||
self::$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testGetNullableArguments()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
@@ -224,9 +216,6 @@ class ArgumentResolverTest extends TestCase
|
||||
$this->assertEquals(array('foo', new \stdClass(), 'value', 'mandatory'), self::$resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testGetNullableArgumentsWithDefaults()
|
||||
{
|
||||
$request = Request::create('/');
|
||||
|
@@ -13,15 +13,20 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
|
||||
|
||||
class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
{
|
||||
public function testGetControllerService()
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Referencing controllers with a single colon is deprecated since Symfony 4.1. Use foo::action instead.
|
||||
*/
|
||||
public function testGetControllerServiceWithSingleColon()
|
||||
{
|
||||
$service = new ControllerTestService('foo');
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
@@ -30,22 +35,47 @@ class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->returnValue($this))
|
||||
->will($this->returnValue($service))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foo:controllerMethod1');
|
||||
$request->attributes->set('_controller', 'foo:action');
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertInstanceOf(\get_class($this), $controller[0]);
|
||||
$this->assertSame('controllerMethod1', $controller[1]);
|
||||
$this->assertSame($service, $controller[0]);
|
||||
$this->assertSame('action', $controller[1]);
|
||||
}
|
||||
|
||||
public function testGetControllerService()
|
||||
{
|
||||
$service = new ControllerTestService('foo');
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with('foo')
|
||||
->will($this->returnValue(true));
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->returnValue($service))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foo::action');
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertSame($service, $controller[0]);
|
||||
$this->assertSame('action', $controller[1]);
|
||||
}
|
||||
|
||||
public function testGetControllerInvokableService()
|
||||
{
|
||||
$invokableController = new InvokableController('bar');
|
||||
$service = new InvokableControllerService('bar');
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
@@ -56,7 +86,7 @@ class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('foo')
|
||||
->will($this->returnValue($invokableController))
|
||||
->will($this->returnValue($service))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
@@ -65,128 +95,72 @@ class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertEquals($invokableController, $controller);
|
||||
$this->assertSame($service, $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerInvokableServiceWithClassNameAsName()
|
||||
{
|
||||
$invokableController = new InvokableController('bar');
|
||||
$className = __NAMESPACE__.'\InvokableController';
|
||||
$service = new InvokableControllerService('bar');
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with($className)
|
||||
->with(InvokableControllerService::class)
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with($className)
|
||||
->will($this->returnValue($invokableController))
|
||||
->with(InvokableControllerService::class)
|
||||
->will($this->returnValue($service))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $className);
|
||||
$request->attributes->set('_controller', InvokableControllerService::class);
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertEquals($invokableController, $controller);
|
||||
}
|
||||
|
||||
public function testNonInstantiableController()
|
||||
{
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with(NonInstantiableController::class)
|
||||
->will($this->returnValue(false))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', array(NonInstantiableController::class, 'action'));
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertSame(array(NonInstantiableController::class, 'action'), $controller);
|
||||
$this->assertSame($service, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage Controller "Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
|
||||
* Tests where the fallback instantiation fails due to required constructor arguments.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
|
||||
*/
|
||||
public function testNonConstructController()
|
||||
public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsName()
|
||||
{
|
||||
$container = $this->getMockBuilder(Container::class)->getMock();
|
||||
$container->expects($this->at(0))
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with(ImpossibleConstructController::class)
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$container->expects($this->at(1))
|
||||
->method('has')
|
||||
->with(ImpossibleConstructController::class)
|
||||
->with(ControllerTestService::class)
|
||||
->will($this->returnValue(false))
|
||||
;
|
||||
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('getRemovedIds')
|
||||
->with()
|
||||
->will($this->returnValue(array(ImpossibleConstructController::class => true)))
|
||||
->will($this->returnValue(array(ControllerTestService::class => true)))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', array(ImpossibleConstructController::class, 'action'));
|
||||
$request->attributes->set('_controller', array(ControllerTestService::class, 'action'));
|
||||
|
||||
if (\PHP_VERSION_ID < 70100) {
|
||||
ErrorHandler::register();
|
||||
try {
|
||||
$resolver->getController($request);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
}
|
||||
} else {
|
||||
$resolver->getController($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNonInstantiableControllerWithCorrespondingService()
|
||||
{
|
||||
$service = new \stdClass();
|
||||
|
||||
$container = $this->createMockContainer();
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('has')
|
||||
->with(NonInstantiableController::class)
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
$container->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
->with(NonInstantiableController::class)
|
||||
->will($this->returnValue($service))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', array(NonInstantiableController::class, 'action'));
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertSame(array($service, 'action'), $controller);
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* Tests where the fallback instantiation fails due to non-existing class.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
|
||||
*/
|
||||
public function testExceptionWhenUsingRemovedControllerService()
|
||||
{
|
||||
$container = $this->getMockBuilder(Container::class)->getMock();
|
||||
$container->expects($this->at(0))
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with('app.my_controller')
|
||||
->will($this->returnValue(false))
|
||||
@@ -205,62 +179,28 @@ class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage Controller "app.my_controller" cannot be called without a method name. Did you forget an "__invoke" method?
|
||||
*/
|
||||
public function testExceptionWhenUsingControllerWithoutAnInvokeMethod()
|
||||
{
|
||||
$container = $this->getMockBuilder(Container::class)->getMock();
|
||||
$container->expects($this->once())
|
||||
->method('has')
|
||||
->with('app.my_controller')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
$container->expects($this->once())
|
||||
->method('get')
|
||||
->with('app.my_controller')
|
||||
->will($this->returnValue(new ImpossibleConstructController('toto', 'controller')))
|
||||
;
|
||||
|
||||
$resolver = $this->createControllerResolver(null, $container);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'app.my_controller');
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getUndefinedControllers
|
||||
*/
|
||||
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
|
||||
{
|
||||
// All this logic needs to be duplicated, since calling parent::testGetControllerOnNonUndefinedFunction will override the expected excetion and not use the regex
|
||||
$resolver = $this->createControllerResolver();
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($exceptionName);
|
||||
$this->expectExceptionMessageRegExp($exceptionMessage);
|
||||
} else {
|
||||
$this->setExpectedExceptionRegExp($exceptionName, $exceptionMessage);
|
||||
}
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $controller);
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
public function getUndefinedControllers()
|
||||
{
|
||||
return array(
|
||||
array('foo', \LogicException::class, '/Controller not found: service "foo" does not exist\./'),
|
||||
array('oof::bar', \InvalidArgumentException::class, '/Class "oof" does not exist\./'),
|
||||
array('stdClass', \LogicException::class, '/Controller not found: service "stdClass" does not exist\./'),
|
||||
array(
|
||||
'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::bar',
|
||||
\InvalidArgumentException::class,
|
||||
'/.?[cC]ontroller(.*?) for URI "\/" is not callable\.( Expected method(.*) Available methods)?/',
|
||||
),
|
||||
$tests = parent::getUndefinedControllers();
|
||||
$tests[0] = array('foo', \InvalidArgumentException::class, 'Controller "foo" does neither exist as service nor as class');
|
||||
$tests[1] = array('oof::bar', \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class');
|
||||
$tests[2] = array(array('oof', 'bar'), \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class');
|
||||
$tests[] = array(
|
||||
array(ControllerTestService::class, 'action'),
|
||||
\InvalidArgumentException::class,
|
||||
'Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
|
||||
);
|
||||
$tests[] = array(
|
||||
ControllerTestService::class.'::action',
|
||||
\InvalidArgumentException::class, 'Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
|
||||
);
|
||||
$tests[] = array(
|
||||
InvokableControllerService::class,
|
||||
\InvalidArgumentException::class,
|
||||
'Controller "Symfony\Component\HttpKernel\Tests\Controller\InvokableControllerService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
|
||||
);
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
protected function createControllerResolver(LoggerInterface $logger = null, ContainerInterface $container = null)
|
||||
@@ -278,7 +218,7 @@ class ContainerControllerResolverTest extends ControllerResolverTest
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableController
|
||||
class InvokableControllerService
|
||||
{
|
||||
public function __construct($bar) // mandatory argument to prevent automatic instantiation
|
||||
{
|
||||
@@ -289,16 +229,9 @@ class InvokableController
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NonInstantiableController
|
||||
class ControllerTestService
|
||||
{
|
||||
public static function action()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ImpossibleConstructController
|
||||
{
|
||||
public function __construct($toto, $controller)
|
||||
public function __construct($foo)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -15,8 +15,6 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
||||
|
||||
class ControllerResolverTest extends TestCase
|
||||
{
|
||||
@@ -43,51 +41,55 @@ class ControllerResolverTest extends TestCase
|
||||
public function testGetControllerWithObjectAndInvokeMethod()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
$object = new InvokableController();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $this);
|
||||
$request->attributes->set('_controller', $object);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame($this, $controller);
|
||||
$this->assertSame($object, $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithObjectAndMethod()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
$object = new ControllerTest();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', array($this, 'controllerMethod1'));
|
||||
$request->attributes->set('_controller', array($object, 'publicAction'));
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame(array($this, 'controllerMethod1'), $controller);
|
||||
$this->assertSame(array($object, 'publicAction'), $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithClassAndMethod()
|
||||
public function testGetControllerWithClassAndMethodAsArray()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', array('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', 'controllerMethod4'));
|
||||
$request->attributes->set('_controller', array(ControllerTest::class, 'publicAction'));
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame(array('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', 'controllerMethod4'), $controller);
|
||||
$this->assertInstanceOf(ControllerTest::class, $controller[0]);
|
||||
$this->assertSame('publicAction', $controller[1]);
|
||||
}
|
||||
|
||||
public function testGetControllerWithObjectAndMethodAsString()
|
||||
public function testGetControllerWithClassAndMethodAsString()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::controllerMethod1');
|
||||
$request->attributes->set('_controller', ControllerTest::class.'::publicAction');
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', $controller[0], '->getController() returns a PHP callable');
|
||||
$this->assertInstanceOf(ControllerTest::class, $controller[0]);
|
||||
$this->assertSame('publicAction', $controller[1]);
|
||||
}
|
||||
|
||||
public function testGetControllerWithClassAndInvokeMethod()
|
||||
public function testGetControllerWithInvokableClass()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest');
|
||||
$request->attributes->set('_controller', InvokableController::class);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertInstanceOf('Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest', $controller);
|
||||
$this->assertInstanceOf(InvokableController::class, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,10 +114,49 @@ class ControllerResolverTest extends TestCase
|
||||
$this->assertSame('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function', $controller);
|
||||
}
|
||||
|
||||
public function testGetControllerWithClosure()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$closure = function () {
|
||||
return 'test';
|
||||
};
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $closure);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertInstanceOf(\Closure::class, $controller);
|
||||
$this->assertSame('test', $controller());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getStaticControllers
|
||||
*/
|
||||
public function testGetControllerWithStaticController($staticController, $returnValue)
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', $staticController);
|
||||
$controller = $resolver->getController($request);
|
||||
$this->assertSame($staticController, $controller);
|
||||
$this->assertSame($returnValue, $controller());
|
||||
}
|
||||
|
||||
public function getStaticControllers()
|
||||
{
|
||||
return array(
|
||||
array(TestAbstractController::class.'::staticAction', 'foo'),
|
||||
array(array(TestAbstractController::class, 'staticAction'), 'foo'),
|
||||
array(PrivateConstructorController::class.'::staticAction', 'bar'),
|
||||
array(array(PrivateConstructorController::class, 'staticAction'), 'bar'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getUndefinedControllers
|
||||
*/
|
||||
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
|
||||
public function testGetControllerWithUndefinedController($controller, $exceptionName = null, $exceptionMessage = null)
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
if (method_exists($this, 'expectException')) {
|
||||
@@ -132,179 +173,30 @@ class ControllerResolverTest extends TestCase
|
||||
|
||||
public function getUndefinedControllers()
|
||||
{
|
||||
$controller = new ControllerTest();
|
||||
|
||||
return array(
|
||||
array(1, 'InvalidArgumentException', 'Unable to find controller "1".'),
|
||||
array('foo', 'InvalidArgumentException', 'Unable to find controller "foo".'),
|
||||
array('oof::bar', 'InvalidArgumentException', 'Class "oof" does not exist.'),
|
||||
array('stdClass', 'InvalidArgumentException', 'Unable to find controller "stdClass".'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::staticsAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::privateAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::protectedAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::undefinedAction', 'InvalidArgumentException', 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
|
||||
array('foo', \Error::class, 'Class \'foo\' not found'),
|
||||
array('oof::bar', \Error::class, 'Class \'oof\' not found'),
|
||||
array(array('oof', 'bar'), \Error::class, 'Class \'oof\' not found'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::staticsAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::privateAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::protectedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::undefinedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
|
||||
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'),
|
||||
array(array($controller, 'staticsAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
|
||||
array(array($controller, 'privateAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
|
||||
array(array($controller, 'protectedAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
|
||||
array(array($controller, 'undefinedAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
|
||||
array($controller, \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'),
|
||||
array(array('a' => 'foo', 'b' => 'bar'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Invalid array callable, expected array(controller, method).'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetArguments()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$controller = array(new self(), 'testGetArguments');
|
||||
$this->assertEquals(array(), $resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = array(new self(), 'controllerMethod1');
|
||||
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = array(new self(), 'controllerMethod2');
|
||||
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
|
||||
|
||||
$request->attributes->set('bar', 'bar');
|
||||
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = function ($foo) {};
|
||||
$this->assertEquals(array('foo'), $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = function ($foo, $bar = 'bar') {};
|
||||
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$controller = new self();
|
||||
$this->assertEquals(array('foo', null), $resolver->getArguments($request, $controller));
|
||||
$request->attributes->set('bar', 'bar');
|
||||
$this->assertEquals(array('foo', 'bar'), $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('foobar', 'foobar');
|
||||
$controller = 'Symfony\Component\HttpKernel\Tests\Controller\some_controller_function';
|
||||
$this->assertEquals(array('foo', 'foobar'), $resolver->getArguments($request, $controller));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('foobar', 'foobar');
|
||||
$controller = array(new self(), 'controllerMethod3');
|
||||
|
||||
try {
|
||||
$resolver->getArguments($request, $controller);
|
||||
$this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value');
|
||||
}
|
||||
|
||||
$request = Request::create('/');
|
||||
$controller = array(new self(), 'controllerMethod5');
|
||||
$this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetVariadicArguments()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', array('foo', 'bar'));
|
||||
$controller = array(new VariadicController(), 'action');
|
||||
$this->assertEquals(array('foo', 'foo', 'bar'), $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
public function testCreateControllerCanReturnAnyCallable()
|
||||
{
|
||||
$mock = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolver')->setMethods(array('createController'))->getMock();
|
||||
$mock->expects($this->once())->method('createController')->will($this->returnValue('Symfony\Component\HttpKernel\Tests\Controller\some_controller_function'));
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'foobar');
|
||||
$mock->getController($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @group legacy
|
||||
*/
|
||||
public function testIfExceptionIsThrownWhenMissingAnArgument()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
$request = Request::create('/');
|
||||
|
||||
$controller = array($this, 'controllerMethod1');
|
||||
|
||||
$resolver->getArguments($request, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetNullableArguments()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('foo', 'foo');
|
||||
$request->attributes->set('bar', new \stdClass());
|
||||
$request->attributes->set('mandatory', 'mandatory');
|
||||
$controller = array(new NullableController(), 'action');
|
||||
$this->assertEquals(array('foo', new \stdClass(), 'value', 'mandatory'), $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
* @group legacy
|
||||
*/
|
||||
public function testGetNullableArgumentsWithDefaults()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('mandatory', 'mandatory');
|
||||
$controller = array(new NullableController(), 'action');
|
||||
$this->assertEquals(array(null, null, 'value', 'mandatory'), $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
protected function createControllerResolver(LoggerInterface $logger = null)
|
||||
{
|
||||
return new ControllerResolver($logger);
|
||||
}
|
||||
|
||||
public function __invoke($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function controllerMethod1($foo)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerMethod2($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerMethod3($foo, $bar, $foobar)
|
||||
{
|
||||
}
|
||||
|
||||
protected static function controllerMethod4()
|
||||
{
|
||||
}
|
||||
|
||||
protected function controllerMethod5(Request $request)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
function some_controller_function($foo, $foobar)
|
||||
@@ -313,6 +205,15 @@ function some_controller_function($foo, $foobar)
|
||||
|
||||
class ControllerTest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function publicAction()
|
||||
{
|
||||
}
|
||||
@@ -329,3 +230,30 @@ class ControllerTest
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableController
|
||||
{
|
||||
public function __invoke($foo, $bar = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TestAbstractController
|
||||
{
|
||||
public static function staticAction()
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
}
|
||||
|
||||
class PrivateConstructorController
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function staticAction()
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
|
@@ -84,9 +84,6 @@ class ArgumentMetadataFactoryTest extends TestCase
|
||||
), $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testVariadicSignature()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata(array(new VariadicController(), 'action'));
|
||||
@@ -97,9 +94,6 @@ class ArgumentMetadataFactoryTest extends TestCase
|
||||
), $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
public function testBasicTypesSignature()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata(array(new BasicTypesController(), 'action'));
|
||||
@@ -111,9 +105,6 @@ class ArgumentMetadataFactoryTest extends TestCase
|
||||
), $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testNullableTypesSignature()
|
||||
{
|
||||
$arguments = $this->factory->createArgumentMetadata(array(new NullableController(), 'action'));
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user