Merge branch '4.3' into 4.4
* 4.3: [FrameworkBundle] Remove project dir from Translator cache vary scanned directories [HttpFoundation] Allow redirecting to URLs that contain a semicolon catch exceptions when using PDO directly [SecurityBundle] fix failing test
This commit is contained in:
commit
88cf8a7d48
|
@ -1234,11 +1234,18 @@ class FrameworkExtension extends Extension
|
||||||
$files[$locale][] = (string) $file;
|
$files[$locale][] = (string) $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$projectDir = $container->getParameter('kernel.project_dir');
|
||||||
|
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
$translator->getArgument(4),
|
$translator->getArgument(4),
|
||||||
[
|
[
|
||||||
'resource_files' => $files,
|
'resource_files' => $files,
|
||||||
'scanned_directories' => array_merge($dirs, $nonExistingDirs),
|
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
|
||||||
|
'cache_vary' => [
|
||||||
|
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
|
||||||
|
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
|
||||||
|
}, $scannedDirectories),
|
||||||
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -838,6 +838,8 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
|
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
|
||||||
|
|
||||||
|
$this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -255,8 +255,10 @@ class TranslatorTest extends TestCase
|
||||||
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
|
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'scanned_directories' => [
|
'cache_vary' => [
|
||||||
__DIR__.'/../Fixtures/Resources/translations/',
|
'scanned_directories' => [
|
||||||
|
'/Fixtures/Resources/translations/',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
], 'yml');
|
], 'yml');
|
||||||
|
|
||||||
|
@ -271,9 +273,11 @@ class TranslatorTest extends TestCase
|
||||||
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
|
__DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'scanned_directories' => [
|
'cache_vary' => [
|
||||||
__DIR__.'/../Fixtures/Resources/translations/',
|
'scanned_directories' => [
|
||||||
__DIR__.'/../Fixtures/Resources/translations2/',
|
'/Fixtures/Resources/translations/',
|
||||||
|
'/Fixtures/Resources/translations2/',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
], 'yml');
|
], 'yml');
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class Translator extends BaseTranslator implements WarmableInterface
|
||||||
'debug' => false,
|
'debug' => false,
|
||||||
'resource_files' => [],
|
'resource_files' => [],
|
||||||
'scanned_directories' => [],
|
'scanned_directories' => [],
|
||||||
|
'cache_vary' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,9 +62,10 @@ class Translator extends BaseTranslator implements WarmableInterface
|
||||||
*
|
*
|
||||||
* Available options:
|
* Available options:
|
||||||
*
|
*
|
||||||
* * cache_dir: The cache directory (or null to disable caching)
|
* * cache_dir: The cache directory (or null to disable caching)
|
||||||
* * debug: Whether to enable debugging or not (false by default)
|
* * debug: Whether to enable debugging or not (false by default)
|
||||||
* * resource_files: List of translation resources available grouped by locale.
|
* * resource_files: List of translation resources available grouped by locale.
|
||||||
|
* * cache_vary: An array of data that is serialized to generate the cached catalogue name.
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@ -82,9 +84,7 @@ class Translator extends BaseTranslator implements WarmableInterface
|
||||||
$this->resourceFiles = $this->options['resource_files'];
|
$this->resourceFiles = $this->options['resource_files'];
|
||||||
$this->scannedDirectories = $this->options['scanned_directories'];
|
$this->scannedDirectories = $this->options['scanned_directories'];
|
||||||
|
|
||||||
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], [
|
parent::__construct($defaultLocale, $formatter, $this->options['cache_dir'], $this->options['debug'], $this->options['cache_vary']);
|
||||||
'scanned_directories' => $this->scannedDirectories,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -160,6 +160,8 @@ trait PdoTrait
|
||||||
$delete = $this->getConnection()->prepare($deleteSql);
|
$delete = $this->getConnection()->prepare($deleteSql);
|
||||||
} catch (TableNotFoundException $e) {
|
} catch (TableNotFoundException $e) {
|
||||||
return true;
|
return true;
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
$delete->bindValue(':time', time(), \PDO::PARAM_INT);
|
$delete->bindValue(':time', time(), \PDO::PARAM_INT);
|
||||||
|
|
||||||
|
@ -170,6 +172,8 @@ trait PdoTrait
|
||||||
return $delete->execute();
|
return $delete->execute();
|
||||||
} catch (TableNotFoundException $e) {
|
} catch (TableNotFoundException $e) {
|
||||||
return true;
|
return true;
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,6 +249,7 @@ trait PdoTrait
|
||||||
try {
|
try {
|
||||||
$conn->exec($sql);
|
$conn->exec($sql);
|
||||||
} catch (TableNotFoundException $e) {
|
} catch (TableNotFoundException $e) {
|
||||||
|
} catch (\PDOException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -261,6 +266,7 @@ trait PdoTrait
|
||||||
$stmt = $this->getConnection()->prepare($sql);
|
$stmt = $this->getConnection()->prepare($sql);
|
||||||
$stmt->execute(array_values($ids));
|
$stmt->execute(array_values($ids));
|
||||||
} catch (TableNotFoundException $e) {
|
} catch (TableNotFoundException $e) {
|
||||||
|
} catch (\PDOException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -317,6 +323,11 @@ trait PdoTrait
|
||||||
$this->createTable();
|
$this->createTable();
|
||||||
}
|
}
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
|
||||||
|
$this->createTable();
|
||||||
|
}
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('sqlsrv' === $driver || 'oci' === $driver) {
|
if ('sqlsrv' === $driver || 'oci' === $driver) {
|
||||||
|
@ -351,6 +362,11 @@ trait PdoTrait
|
||||||
$this->createTable();
|
$this->createTable();
|
||||||
}
|
}
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
|
||||||
|
$this->createTable();
|
||||||
|
}
|
||||||
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
if (null === $driver && !$stmt->rowCount()) {
|
if (null === $driver && !$stmt->rowCount()) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -98,7 +98,7 @@ class RedirectResponse extends Response
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta http-equiv="refresh" content="0;url=%1$s" />
|
<meta http-equiv="refresh" content="0;url=\'%1$s\'" />
|
||||||
|
|
||||||
<title>Redirecting to %1$s</title>
|
<title>Redirecting to %1$s</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -20,10 +20,7 @@ class RedirectResponseTest extends TestCase
|
||||||
{
|
{
|
||||||
$response = new RedirectResponse('foo.bar');
|
$response = new RedirectResponse('foo.bar');
|
||||||
|
|
||||||
$this->assertEquals(1, preg_match(
|
$this->assertRegExp('#<meta http-equiv="refresh" content="\d+;url=\'foo\.bar\'" />#', preg_replace('/\s+/', ' ', $response->getContent()));
|
||||||
'#<meta http-equiv="refresh" content="\d+;url=foo\.bar" />#',
|
|
||||||
preg_replace(['/\s+/', '/\'/'], [' ', '"'], $response->getContent())
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRedirectResponseConstructorEmptyUrl()
|
public function testRedirectResponseConstructorEmptyUrl()
|
||||||
|
|
Reference in New Issue