Merge branch '5.0'

* 5.0:
  [FrameworkBundle] Fix session.attribute_bag service definition
  [Routing] Remove unused properties from the Route annotation
  [Routing] Add missing _locale requirements
  Update LdapBindAuthenticationProvider.php
  Add reproducer to for hit after update expire cacheItem
  [Cache] fix FilesystemTagAwareAdapter failing when a tag link preexists
This commit is contained in:
Nicolas Grekas 2020-04-21 23:06:40 +02:00
commit 7ce2f2401a
11 changed files with 54 additions and 7 deletions

View File

@ -48,7 +48,8 @@
<service id="Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface" alias="session.flash_bag" />
<service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag">
<factory service="session" method="getAttributeBag" />
<factory service="session" method="getBag"/>
<argument>attributes</argument>
<deprecated package="symfony/framework-bundle" version="5.1">The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.</deprecated>
</service>

View File

@ -107,7 +107,7 @@ class FilesystemTagAwareAdapter extends AbstractTagAwareAdapter implements Prune
$file = $this->getFile($id);
if (!@symlink($file, $this->getFile($id, true, $tagFolder))) {
if (!@symlink($file, $tagLink = $this->getFile($id, true, $tagFolder)) && !is_link($tagLink)) {
@unlink($file);
$failed[] = $id;
}

View File

@ -141,4 +141,42 @@ trait TagAwareTestTrait
$i = $pool->getItem('k');
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);
}
public function testRefreshAfterExpires()
{
$pool = $this->createCachePool();
$pool->clear();
$cacheItem = $pool->getItem('test');
$this->assertFalse($cacheItem->isHit());
// write cache with expires
$cacheItem->set('test');
$cacheItem->tag('1234');
$cacheItem->expiresAfter(1);
$pool->save($cacheItem);
$cacheItem = $pool->getItem('test');
$this->assertTrue($cacheItem->isHit());
// wait until expired
sleep(2);
// item should not longer be a hit
$cacheItem = $pool->getItem('test');
$this->assertFalse($cacheItem->isHit());
// update expired item
$cacheItem->set('test');
$cacheItem->tag('1234');
$cacheItem->expiresAfter(1);
$pool->save($cacheItem);
// item should be again a hit
$cacheItem = $pool->getItem('test');
$this->assertTrue($cacheItem->isHit());
}
}

View File

@ -31,9 +31,6 @@ class Route
private $methods = [];
private $schemes = [];
private $condition;
private $locale;
private $format;
private $utf8;
private $priority;
/**

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Routing\Loader\Configurator;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCompiler;
/**
* @author Nicolas Grekas <p@tchwork.com>

View File

@ -33,6 +33,7 @@ trait PrefixTrait
foreach ($prefix as $locale => $localePrefix) {
$localizedRoute = clone $route;
$localizedRoute->setDefault('_locale', $locale);
$localizedRoute->setRequirement('_locale', preg_quote($locale, RouteCompiler::REGEX_DELIMITER));
$localizedRoute->setDefault('_canonical_route', $name);
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
$routes->add($name.'.'.$locale, $localizedRoute);

View File

@ -8,4 +8,6 @@ return function (RoutingConfigurator $routes) {
$add('foo', ['fr' => '/foo']);
$add('bar', ['fr' => '/bar']);
$routes->add('non_localized', '/non-localized');
};

View File

@ -237,6 +237,7 @@ class PhpFileLoaderTest extends TestCase
$expectedCollection->add('baz.en', (new Route('/baz'))->setDefaults(['_locale' => 'en', '_canonical_route' => 'baz'])->setRequirement('_locale', 'en'));
$expectedCollection->add('c_foo.fr', (new Route('/ench/pub/foo'))->setDefaults(['_locale' => 'fr', '_canonical_route' => 'c_foo'])->setRequirement('_locale', 'fr'));
$expectedCollection->add('c_bar.fr', (new Route('/ench/pub/bar'))->setDefaults(['_locale' => 'fr', '_canonical_route' => 'c_bar'])->setRequirement('_locale', 'fr'));
$expectedCollection->add('non_localized.fr', (new Route('/ench/non-localized'))->setDefaults(['_locale' => 'fr', '_canonical_route' => 'non_localized'])->setRequirement('_locale', 'fr'));
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub_i18n.php')));
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_i18n.php')));

View File

@ -205,6 +205,9 @@ class XmlFileLoaderTest extends TestCase
$this->assertEquals('/le-prefix/suffix', $routeCollection->get('imported.fr')->getPath());
$this->assertEquals('/the-prefix/suffix', $routeCollection->get('imported.en')->getPath());
$this->assertSame('fr', $routeCollection->get('imported.fr')->getRequirement('_locale'));
$this->assertSame('en', $routeCollection->get('imported.en')->getRequirement('_locale'));
}
/**

View File

@ -338,6 +338,9 @@ class YamlFileLoaderTest extends TestCase
$this->assertCount(2, $routes);
$this->assertEquals('/nl/imported', $routes->get('imported.nl')->getPath());
$this->assertEquals('/en/imported', $routes->get('imported.en')->getPath());
$this->assertSame('nl', $routes->get('imported.nl')->getRequirement('_locale'));
$this->assertSame('en', $routes->get('imported.en')->getRequirement('_locale'));
}
public function testImportingRoutesWithOfficialLocales()

View File

@ -82,14 +82,13 @@ class LdapBindAuthenticationProvider extends UserAuthenticationProvider
}
try {
$username = $this->ldap->escape($username, '', LdapInterface::ESCAPE_DN);
if ($this->queryString) {
if ('' !== $this->searchDn && '' !== $this->searchPassword) {
$this->ldap->bind($this->searchDn, $this->searchPassword);
} else {
throw new LogicException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
}
$username = $this->ldap->escape($username, '', LdapInterface::ESCAPE_FILTER);
$query = str_replace('{username}', $username, $this->queryString);
$result = $this->ldap->query($this->dnString, $query)->execute();
if (1 !== $result->count()) {
@ -98,6 +97,7 @@ class LdapBindAuthenticationProvider extends UserAuthenticationProvider
$dn = $result[0]->getDn();
} else {
$username = $this->ldap->escape($username, '', LdapInterface::ESCAPE_DN);
$dn = str_replace('{username}', $username, $this->dnString);
}