Merge branch '4.4' into 5.2

* 4.4:
  [Serializer][Validator] Update some phpDoc relative to "getters"
  Update README.md
  [SecurityBundle] Empty line starting with dash under "access_control" causes all rules to be skipped
  [Cache] Apply NullAdapter as Null Object
This commit is contained in:
Alexander M. Turek 2021-04-13 16:17:49 +02:00
commit 255283cb24
7 changed files with 67 additions and 11 deletions

View File

@ -208,6 +208,12 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
$attributes[] = $this->createExpression($container, $access['allow_if']);
}
$emptyAccess = 0 === \count(array_filter($access));
if ($emptyAccess) {
throw new InvalidConfigurationException('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
}
$container->getDefinition('security.access_map')
->addMethodCall('add', [$matcher, $attributes, $access['requires_channel']]);
}

View File

@ -432,6 +432,56 @@ class SecurityExtensionTest extends TestCase
$this->assertEquals(new Reference('security.user.provider.concrete.second'), $container->getDefinition('security.authentication.switchuser_listener.foobar')->getArgument(1));
}
public function testInvalidAccessControlWithEmptyRow()
{
$container = $this->getRawContainer();
$container->loadFromExtension('security', [
'providers' => [
'default' => ['id' => 'foo'],
],
'firewalls' => [
'some_firewall' => [
'pattern' => '/.*',
'http_basic' => [],
],
],
'access_control' => [
[],
['path' => '/admin', 'roles' => 'ROLE_ADMIN'],
],
]);
$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
$container->compile();
}
public function testValidAccessControlWithEmptyRow()
{
$container = $this->getRawContainer();
$container->loadFromExtension('security', [
'providers' => [
'default' => ['id' => 'foo'],
],
'firewalls' => [
'some_firewall' => [
'pattern' => '/.*',
'http_basic' => [],
],
],
'access_control' => [
['path' => '^/login'],
['path' => '^/', 'roles' => 'ROLE_USER'],
],
]);
$container->compile();
$this->assertTrue(true, 'extension throws an InvalidConfigurationException if there is one more more empty access control items');
}
/**
* @dataProvider provideEntryPointFirewalls
*/

View File

@ -112,7 +112,7 @@ class NullAdapter implements AdapterInterface, CacheInterface
*/
public function save(CacheItemInterface $item)
{
return false;
return true;
}
/**
@ -122,7 +122,7 @@ class NullAdapter implements AdapterInterface, CacheInterface
*/
public function saveDeferred(CacheItemInterface $item)
{
return false;
return true;
}
/**
@ -132,7 +132,7 @@ class NullAdapter implements AdapterInterface, CacheInterface
*/
public function commit()
{
return false;
return true;
}
/**

View File

@ -113,7 +113,7 @@ class NullAdapterTest extends TestCase
$this->assertFalse($item->isHit());
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
$this->assertFalse($adapter->save($item));
$this->assertTrue($adapter->save($item));
}
public function testDeferredSave()
@ -124,7 +124,7 @@ class NullAdapterTest extends TestCase
$this->assertFalse($item->isHit());
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
$this->assertFalse($adapter->saveDeferred($item));
$this->assertTrue($adapter->saveDeferred($item));
}
public function testCommit()
@ -135,7 +135,7 @@ class NullAdapterTest extends TestCase
$this->assertFalse($item->isHit());
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
$this->assertFalse($adapter->saveDeferred($item));
$this->assertFalse($this->createCachePool()->commit());
$this->assertTrue($adapter->saveDeferred($item));
$this->assertTrue($this->createCachePool()->commit());
}
}

View File

@ -61,7 +61,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
}
/**
* Checks if the given class has any get{Property} method.
* Checks if the given class has any getter method.
*/
private function supports(string $class): bool
{
@ -77,7 +77,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
}
/**
* Checks if a method's name is get.* or is.*, and can be called without parameters.
* Checks if a method's name matches /^(get|is|has).+$/ and can be called non-statically without parameters.
*/
private function isGetMethod(\ReflectionMethod $method): bool
{

View File

@ -264,7 +264,7 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
* Adds a constraint to the getter of the given property.
*
* The name of the getter is assumed to be the name of the property with an
* uppercased first letter and either the prefix "get" or "is".
* uppercased first letter and the prefix "get", "is" or "has".
*
* @return $this
*/

View File

@ -18,7 +18,7 @@ use Symfony\Component\Validator\Exception\ValidatorException;
* method.
*
* A property getter is any method that is equal to the property's name,
* prefixed with either "get" or "is". That method will be used to access the
* prefixed with "get", "is" or "has". That method will be used to access the
* property's value.
*
* The getter will be invoked by reflection, so the access of private and