Merge branch '3.4' into 4.3

* 3.4:
  SCA: minor code tweaks
  [HttpKernel] Fix Apache mod_expires Session Cache-Control issue
  Fix getFileLinkFormat() to avoid returning the wrong URL in Profiler
This commit is contained in:
Nicolas Grekas 2019-09-08 22:39:53 +02:00
commit 5a06f94c08
7 changed files with 16 additions and 8 deletions

View File

@ -260,11 +260,11 @@ abstract class AbstractDoctrineExtension extends Extension
$configPath = $this->getMappingResourceConfigDirectory(); $configPath = $this->getMappingResourceConfigDirectory();
$extension = $this->getMappingResourceExtension(); $extension = $this->getMappingResourceExtension();
if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml')) { if (glob($dir.'/'.$configPath.'/*.'.$extension.'.xml', GLOB_NOSORT)) {
$driver = 'xml'; $driver = 'xml';
} elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.yml')) { } elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.yml', GLOB_NOSORT)) {
$driver = 'yml'; $driver = 'yml';
} elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.php')) { } elseif (glob($dir.'/'.$configPath.'/*.'.$extension.'.php', GLOB_NOSORT)) {
$driver = 'php'; $driver = 'php';
} else { } else {
// add the closest existing directory as a resource // add the closest existing directory as a resource

View File

@ -1038,8 +1038,7 @@ class Application
*/ */
public function extractNamespace($name, $limit = null) public function extractNamespace($name, $limit = null)
{ {
$parts = explode(':', $name); $parts = explode(':', $name, -1);
array_pop($parts);
return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit)); return implode(':', null === $limit ? $parts : \array_slice($parts, 0, $limit));
} }

View File

@ -96,7 +96,7 @@ class FileLinkFormatter
if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) { if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) {
return [ return [
$request->getSchemeAndHttpHost().$request->getBasePath().$this->urlFormat, $request->getSchemeAndHttpHost().$this->urlFormat,
$this->baseDir.\DIRECTORY_SEPARATOR, '', $this->baseDir.\DIRECTORY_SEPARATOR, '',
]; ];
} }

View File

@ -85,6 +85,7 @@ abstract class AbstractSessionListener implements EventSubscriberInterface
if ($session instanceof Session ? $session->getUsageIndex() !== end($this->sessionUsageStack) : $session->isStarted()) { if ($session instanceof Session ? $session->getUsageIndex() !== end($this->sessionUsageStack) : $session->isStarted()) {
if ($autoCacheControl) { if ($autoCacheControl) {
$response $response
->setExpires(new \DateTime())
->setPrivate() ->setPrivate()
->setMaxAge(0) ->setMaxAge(0)
->headers->addCacheControlDirective('must-revalidate'); ->headers->addCacheControlDirective('must-revalidate');

View File

@ -585,7 +585,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
static $legacyContainers = []; static $legacyContainers = [];
$oldContainerDir = \dirname($oldContainer->getFileName()); $oldContainerDir = \dirname($oldContainer->getFileName());
$legacyContainers[$oldContainerDir.'.legacy'] = true; $legacyContainers[$oldContainerDir.'.legacy'] = true;
foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy') as $legacyContainer) { foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy', GLOB_NOSORT) as $legacyContainer) {
if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) { if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
(new Filesystem())->remove(substr($legacyContainer, 0, -7)); (new Filesystem())->remove(substr($legacyContainer, 0, -7));
} }

View File

@ -84,9 +84,11 @@ class SessionListenerTest extends TestCase
$response = new Response(); $response = new Response();
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->has('Expires'));
$this->assertTrue($response->headers->hasCacheControlDirective('private')); $this->assertTrue($response->headers->hasCacheControlDirective('private'));
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age')); $this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); $this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
} }
@ -110,6 +112,7 @@ class SessionListenerTest extends TestCase
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->has('Expires'));
$this->assertFalse($response->headers->hasCacheControlDirective('private')); $this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage')); $this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
@ -129,6 +132,7 @@ class SessionListenerTest extends TestCase
$listener = new SessionListener($container); $listener = new SessionListener($container);
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertFalse($response->headers->has('Expires'));
$this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private')); $this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
@ -160,6 +164,7 @@ class SessionListenerTest extends TestCase
$listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response)); $listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onFinishRequest(new FinishRequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST)); $listener->onFinishRequest(new FinishRequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST));
$this->assertFalse($response->headers->has('Expires'));
$this->assertFalse($response->headers->hasCacheControlDirective('private')); $this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('30', $response->headers->getCacheControlDirective('max-age')); $this->assertSame('30', $response->headers->getCacheControlDirective('max-age'));
@ -169,5 +174,8 @@ class SessionListenerTest extends TestCase
$this->assertTrue($response->headers->hasCacheControlDirective('private')); $this->assertTrue($response->headers->hasCacheControlDirective('private'));
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('0', $response->headers->getCacheControlDirective('max-age')); $this->assertSame('0', $response->headers->getCacheControlDirective('max-age'));
$this->assertTrue($response->headers->has('Expires'));
$this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires'))));
} }
} }

View File

@ -42,7 +42,7 @@ class LocaleScanner
*/ */
public function scanLocales($sourceDir) public function scanLocales($sourceDir)
{ {
$locales = glob($sourceDir.'/*.txt'); $locales = glob($sourceDir.'/*.txt', GLOB_NOSORT);
// Remove file extension and sort // Remove file extension and sort
array_walk($locales, function (&$locale) { $locale = basename($locale, '.txt'); }); array_walk($locales, function (&$locale) { $locale = basename($locale, '.txt'); });