Merge branch '5.0'

* 5.0:
  [DependencyInjection] Fix binding tagged services to containers
  [ProxyManager] fix generating proxies for root-namespaced classes
  [DoctrineBridge] Cleanup 3.4 legacy
  [DI] skip looking for config class when the extension class is anonymous
  Fix typo
  Docs - Update debug section of UPGRADE guides for 4.4 and 5.0 versions.
  Fix invalid typehint for subject in is_granted Twig function
  [Dotenv] FIX missing getenv
  [HttpFoundation] fix pdo session handler for sqlsrv
  [HttpClient][Psr18Client] Remove Psr18ExceptionTrait
  [HttpKernel] ignore failuresgenerated by opcache.restrict_api
This commit is contained in:
Nicolas Grekas 2019-12-19 17:01:26 +01:00
commit 4e5b15353d
16 changed files with 58 additions and 30 deletions

View File

@ -19,6 +19,7 @@ Debug
-----
* Deprecated the component in favor of the `ErrorHandler` component
* Replace uses of `Symfony\Component\Debug\Debug` by `Symfony\Component\ErrorHandler\Debug`
Config
------

View File

@ -60,6 +60,7 @@ Debug
-----
* Removed the component in favor of the `ErrorHandler` component
* Replace uses of `Symfony\Component\Debug\Debug` by `Symfony\Component\ErrorHandler\Debug`
DependencyInjection
-------------------

View File

@ -54,17 +54,13 @@ abstract class ManagerRegistry extends AbstractManagerRegistry
}
$manager->setProxyInitializer(\Closure::bind(
function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) {
if (isset($this->normalizedIds[$normalizedId = strtolower($name)])) { // BC with DI v3.4
$name = $this->normalizedIds[$normalizedId];
}
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
}
if (isset($this->fileMap[$name])) {
$wrappedInstance = $this->load($this->fileMap[$name]);
} else {
$method = $this->methodMap[$name] ?? 'get'.strtr($name, $this->underscoreMap).'Service'; // BC with DI v3.4
$wrappedInstance = $this->{$method}(false);
$wrappedInstance = $this->{$this->methodMap[$name]}(false);
}
$manager->setProxyInitializer(null);

View File

@ -81,6 +81,7 @@ EOF;
public function getProxyCode(Definition $definition): string
{
$code = $this->classGenerator->generate($this->generateProxyClass($definition));
$code = preg_replace('/^(class [^ ]++ extends )([^\\\\])/', '$1\\\\$2', $code);
if (version_compare(self::getProxyManagerVersion(), '2.2', '<')) {
$code = preg_replace(

View File

@ -21,5 +21,5 @@ class LazyServiceProjectServiceContainer extends Container
}
}
class stdClass_%s extends %SstdClass implements \ProxyManager\%s
class stdClass_%s extends \stdClass implements \ProxyManager\%s
{%a}%A

View File

@ -31,7 +31,10 @@ final class SecurityExtension extends AbstractExtension
$this->securityChecker = $securityChecker;
}
public function isGranted($role, object $object = null, string $field = null): bool
/**
* @param mixed $object
*/
public function isGranted($role, $object = null, string $field = null): bool
{
if (null === $this->securityChecker) {
return false;

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
@ -126,8 +127,8 @@ class ResolveBindingsPass extends AbstractRecursivePass
continue;
}
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument) {
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, an instance of %s or an instance of %s or an instance of %s, %s given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue)));
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected null, %s, %s, %s or ServiceLocatorArgument, %s given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, \gettype($bindingValue)));
}
}

View File

@ -81,6 +81,11 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
public function getConfiguration(array $config, ContainerBuilder $container)
{
$class = \get_class($this);
if (false !== strpos($class, "\0")) {
return null; // ignore anonymous classes
}
$class = substr_replace($class, '\Configuration', strrpos($class, '\\'));
$class = $container->getReflectionClass($class);

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
use Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass;
@ -35,6 +36,7 @@ class ResolveBindingsPassTest extends TestCase
$bindings = [
CaseSensitiveClass::class => new BoundArgument(new Reference('foo')),
'Psr\Container\ContainerInterface $container' => new BoundArgument(new ServiceLocatorArgument([]), true, BoundArgument::INSTANCEOF_BINDING),
'iterable $objects' => new BoundArgument(new TaggedIteratorArgument('tag.name'), true, BoundArgument::INSTANCEOF_BINDING),
];
@ -49,7 +51,13 @@ class ResolveBindingsPassTest extends TestCase
$pass = new ResolveBindingsPass();
$pass->process($container);
$this->assertEquals([0 => new Reference('foo'), 1 => '123', 4 => new TaggedIteratorArgument('tag.name')], $definition->getArguments());
$expected = [
0 => new Reference('foo'),
1 => '123',
3 => new ServiceLocatorArgument([]),
4 => new TaggedIteratorArgument('tag.name'),
];
$this->assertEquals($expected, $definition->getArguments());
$this->assertEquals([['setSensitiveClass', [new Reference('foo')]]], $definition->getMethodCalls());
}

View File

@ -9,7 +9,7 @@ use Psr\Container\ContainerInterface;
*/
class NamedArgumentsDummy
{
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $interface, iterable $objects)
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName, ContainerInterface $container, iterable $objects)
{
}

View File

@ -458,7 +458,7 @@ final class Dotenv
} elseif (isset($this->values[$name])) {
$value = $this->values[$name];
} else {
$value = '';
$value = (string) getenv($name);
}
if ('' === $value && isset($matches['default_value']) && '' !== $matches['default_value']) {

View File

@ -443,6 +443,17 @@ class DotenvTest extends TestCase
}
}
public function testGetVariablesValueFromGetenv()
{
putenv('Foo=Bar');
$dotenv = new Dotenv(true);
$values = $dotenv->parse('Foo=${Foo}');
$this->assertSame('Bar', $values['Foo']);
putenv('Foo');
}
public function testNoDeprecationWarning()
{
$dotenv = new Dotenv(true);

View File

@ -190,7 +190,7 @@ final class Psr18Client implements ClientInterface, RequestFactoryInterface, Str
/**
* @internal
*/
trait Psr18ExceptionTrait
class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface
{
private $request;
@ -206,18 +206,21 @@ trait Psr18ExceptionTrait
}
}
/**
* @internal
*/
class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface
{
use Psr18ExceptionTrait;
}
/**
* @internal
*/
class Psr18RequestException extends \InvalidArgumentException implements RequestExceptionInterface
{
use Psr18ExceptionTrait;
private $request;
public function __construct(TransportExceptionInterface $e, RequestInterface $request)
{
parent::__construct($e->getMessage(), 0, $e);
$this->request = $request;
}
public function getRequest(): RequestInterface
{
return $this->request;
}
}

View File

@ -869,10 +869,10 @@ class PdoSessionHandler extends AbstractSessionHandler
$mergeStmt->bindParam(2, $sessionId, \PDO::PARAM_STR);
$mergeStmt->bindParam(3, $data, \PDO::PARAM_LOB);
$mergeStmt->bindValue(4, time() + $maxlifetime, \PDO::PARAM_INT);
$mergeStmt->bindValue(4, time(), \PDO::PARAM_INT);
$mergeStmt->bindParam(5, $data, \PDO::PARAM_LOB);
$mergeStmt->bindValue(6, time() + $maxlifetime, \PDO::PARAM_INT);
$mergeStmt->bindValue(6, time(), \PDO::PARAM_INT);
$mergeStmt->bindValue(5, time(), \PDO::PARAM_INT);
$mergeStmt->bindParam(6, $data, \PDO::PARAM_LOB);
$mergeStmt->bindValue(7, time() + $maxlifetime, \PDO::PARAM_INT);
$mergeStmt->bindValue(8, time(), \PDO::PARAM_INT);
} else {
$mergeStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$mergeStmt->bindParam(':data', $data, \PDO::PARAM_LOB);

View File

@ -401,13 +401,11 @@ class NativeSessionStorage implements SessionStorageInterface
* ini_set('session.save_path', '/tmp');
*
* or pass in a \SessionHandler instance which configures session.save_handler in the
* constructor, for a template see NativeFileSessionHandler or use handlers in
* composer package drak/native-session
* constructor, for a template see NativeFileSessionHandler.
*
* @see https://php.net/session-set-save-handler
* @see https://php.net/sessionhandlerinterface
* @see https://php.net/sessionhandler
* @see https://github.com/zikula/NativeSession
*
* @param AbstractProxy|\SessionHandlerInterface|null $saveHandler
*

View File

@ -471,7 +471,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
}
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) {
opcache_invalidate($this->getPath(), true);
@opcache_invalidate($this->getPath(), true);
}
}