Merge branch '4.3' into 4.4

* 4.3:
  SCA: minor code tweaks
  [HttpClient] fallbackto CURLMOPT_MAXCONNECTS when CURLMOPT_MAX_HOST_CONNECTIONS is not available
  fixed typo
  [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:40:04 +02:00
commit 81ac674b61
9 changed files with 21 additions and 10 deletions

View File

@ -257,11 +257,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

@ -1047,8 +1047,7 @@ class Application implements ResetInterface
*/ */
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

@ -73,7 +73,10 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface
curl_multi_setopt($this->multi->handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX); curl_multi_setopt($this->multi->handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
} }
if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) { if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
curl_multi_setopt($this->multi->handle, CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : PHP_INT_MAX); $maxHostConnections = curl_multi_setopt($this->multi->handle, CURLMOPT_MAX_HOST_CONNECTIONS, 0 < $maxHostConnections ? $maxHostConnections : PHP_INT_MAX) ? 0 : $maxHostConnections;
}
if (\defined('CURLMOPT_MAXCONNECTS') && 0 < $maxHostConnections) {
curl_multi_setopt($this->multi->handle, CURLMOPT_MAXCONNECTS, $maxHostConnections);
} }
// Skip configuring HTTP/2 push when it's unsupported or buggy, see https://bugs.php.net/77535 // Skip configuring HTTP/2 push when it's unsupported or buggy, see https://bugs.php.net/77535

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

@ -598,7 +598,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

@ -40,7 +40,7 @@ class LocaleScanner
*/ */
public function scanLocales(string $sourceDir): array public function scanLocales(string $sourceDir): array
{ {
$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'); });

View File

@ -26,7 +26,7 @@ class FormDataPartTest extends TestCase
$b = new TextPart('content'); $b = new TextPart('content');
$c = DataPart::fromPath($file = __DIR__.'/../../Fixtures/mimetypes/test.gif'); $c = DataPart::fromPath($file = __DIR__.'/../../Fixtures/mimetypes/test.gif');
$f = new FormDataPart([ $f = new FormDataPart([
'foo' => $content = 'very very long content that will not be cut even if the length i way more than 76 characters, ok?', 'foo' => $content = 'very very long content that will not be cut even if the length is way more than 76 characters, ok?',
'bar' => clone $b, 'bar' => clone $b,
'baz' => clone $c, 'baz' => clone $c,
]); ]);