Merge branch '4.1'
* 4.1: [SecurityBundle] fix test [DI] Fix bad exception on uninitialized references to non-shared services [HttpFoundation] Fix perf issue during MimeTypeGuesser intialization
This commit is contained in:
commit
29fa8119b9
@ -35,18 +35,18 @@ class LogoutTest extends WebTestCase
|
|||||||
public function testCsrfTokensAreClearedOnLogout()
|
public function testCsrfTokensAreClearedOnLogout()
|
||||||
{
|
{
|
||||||
$client = $this->createClient(array('test_case' => 'LogoutWithoutSessionInvalidation', 'root_config' => 'config.yml'));
|
$client = $this->createClient(array('test_case' => 'LogoutWithoutSessionInvalidation', 'root_config' => 'config.yml'));
|
||||||
$client->getContainer()->get('test.security.csrf.token_storage')->setToken('foo', 'bar');
|
static::$kernel->getContainer()->get('test.security.csrf.token_storage')->setToken('foo', 'bar');
|
||||||
|
|
||||||
$client->request('POST', '/login', array(
|
$client->request('POST', '/login', array(
|
||||||
'_username' => 'johannes',
|
'_username' => 'johannes',
|
||||||
'_password' => 'test',
|
'_password' => 'test',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertTrue($client->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
|
$this->assertTrue(static::$kernel->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
|
||||||
$this->assertSame('bar', $client->getContainer()->get('test.security.csrf.token_storage')->getToken('foo'));
|
$this->assertSame('bar', static::$kernel->getContainer()->get('test.security.csrf.token_storage')->getToken('foo'));
|
||||||
|
|
||||||
$client->request('GET', '/logout');
|
$client->request('GET', '/logout');
|
||||||
|
|
||||||
$this->assertFalse($client->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
|
$this->assertFalse(static::$kernel->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
"twig/twig": "~1.34|~2.4"
|
"twig/twig": "~1.34|~2.4"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"symfony/security": "4.1.0-beta1,4.1.0-beta2",
|
"symfony/security": "4.1.0-beta1|4.1.0-beta2",
|
||||||
"symfony/var-dumper": "<3.4",
|
"symfony/var-dumper": "<3.4",
|
||||||
"symfony/event-dispatcher": "<3.4",
|
"symfony/event-dispatcher": "<3.4",
|
||||||
"symfony/framework-bundle": "<4.1",
|
"symfony/framework-bundle": "<4.1",
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
@ -31,9 +30,6 @@ class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
|
|||||||
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
|
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
|
||||||
throw new ServiceNotFoundException($id, $this->currentId);
|
throw new ServiceNotFoundException($id, $this->currentId);
|
||||||
}
|
}
|
||||||
if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() && $this->container->has($id = (string) $value) && !$this->container->findDefinition($id)->isShared()) {
|
|
||||||
throw new InvalidArgumentException(sprintf('Invalid ignore-on-uninitialized reference found in service "%s": target service "%s" is not shared.', $this->currentId, $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
@ -1666,6 +1666,9 @@ EOF;
|
|||||||
if ($this->container->hasDefinition($id) && ($definition = $this->container->getDefinition($id)) && !$definition->isSynthetic()) {
|
if ($this->container->hasDefinition($id) && ($definition = $this->container->getDefinition($id)) && !$definition->isSynthetic()) {
|
||||||
if (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
|
if (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
|
||||||
$code = 'null';
|
$code = 'null';
|
||||||
|
if (!$definition->isShared()) {
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
} elseif ($this->isTrivialInstance($definition)) {
|
} elseif ($this->isTrivialInstance($definition)) {
|
||||||
$code = substr($this->addNewInstance($definition, '', '', $id), 8, -2);
|
$code = substr($this->addNewInstance($definition, '', '', $id), 8, -2);
|
||||||
if ($definition->isShared() && !isset($this->singleUsePrivateIds[$id])) {
|
if ($definition->isShared() && !isset($this->singleUsePrivateIds[$id])) {
|
||||||
|
@ -68,27 +68,6 @@ class CheckExceptionOnInvalidReferenceBehaviorPassTest extends TestCase
|
|||||||
$this->process($container);
|
$this->process($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
|
||||||
* @expectedExceptionMessage Invalid ignore-on-uninitialized reference found in service
|
|
||||||
*/
|
|
||||||
public function testProcessThrowsExceptionOnNonSharedUninitializedReference()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
|
|
||||||
$container
|
|
||||||
->register('a', 'stdClass')
|
|
||||||
->addArgument(new Reference('b', $container::IGNORE_ON_UNINITIALIZED_REFERENCE))
|
|
||||||
;
|
|
||||||
|
|
||||||
$container
|
|
||||||
->register('b', 'stdClass')
|
|
||||||
->setShared(false)
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testProcessDefinitionWithBindings()
|
public function testProcessDefinitionWithBindings()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
@ -80,13 +80,8 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
if (FileBinaryMimeTypeGuesser::isSupported()) {
|
$this->register(new FileBinaryMimeTypeGuesser());
|
||||||
$this->register(new FileBinaryMimeTypeGuesser());
|
$this->register(new FileinfoMimeTypeGuesser());
|
||||||
}
|
|
||||||
|
|
||||||
if (FileinfoMimeTypeGuesser::isSupported()) {
|
|
||||||
$this->register(new FileinfoMimeTypeGuesser());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,18 +120,14 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
throw new AccessDeniedException($path);
|
throw new AccessDeniedException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->guessers) {
|
|
||||||
$msg = 'Unable to guess the mime type as no guessers are available';
|
|
||||||
if (!FileinfoMimeTypeGuesser::isSupported()) {
|
|
||||||
$msg .= ' (Did you enable the php_fileinfo extension?)';
|
|
||||||
}
|
|
||||||
throw new \LogicException($msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->guessers as $guesser) {
|
foreach ($this->guessers as $guesser) {
|
||||||
if (null !== $mimeType = $guesser->guess($path)) {
|
if (null !== $mimeType = $guesser->guess($path)) {
|
||||||
return $mimeType;
|
return $mimeType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) {
|
||||||
|
throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user