Merge branch '2.7' into 2.8

* 2.7:
  prefer getSourceContext() over getSource()
  [HttpFoundation] Avoid implicit null to array conversion in request matcher
  Revert "bug #20184 [FrameworkBundle] Convert null prefix to an empty string in translation:update (chalasr)"
  Update UPGRADE-2.7.md
This commit is contained in:
Fabien Potencier 2016-11-07 11:34:39 -08:00
commit 570bebdcb3
7 changed files with 26 additions and 23 deletions

View File

@ -40,7 +40,7 @@ Form
----
* In form types and extension overriding the "setDefaultOptions" of the
AbstractType or AbstractExtensionType has been deprecated in favor of
AbstractType or AbstractTypeExtension has been deprecated in favor of
overriding the new "configureOptions" method.
The method "setDefaultOptions(OptionsResolverInterface $resolver)" will

View File

@ -36,7 +36,7 @@ class TranslationExtensionTest extends \PHPUnit_Framework_TestCase
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n";
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext('index'))))."\n\n";
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
}

View File

@ -75,14 +75,14 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
$loader = $this->environment->getLoader();
if ($loader instanceof \Twig_ExistsLoaderInterface) {
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
return $loader->exists((string) $name);
}
try {
// cast possible TemplateReferenceInterface to string because the
// EngineInterface supports them but Twig_LoaderInterface does not
$loader->getSource((string) $name);
$loader->getSourceContext((string) $name)->getCode();
} catch (\Twig_Error_Loader $e) {
return false;
}

View File

@ -119,9 +119,8 @@ EOF
// load any messages from templates
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$io->comment('Parsing templates...');
$prefix = $input->getOption('prefix');
$extractor = $this->getContainer()->get('translation.extractor');
$extractor->setPrefix(null === $prefix ? '' : $prefix);
$extractor->setPrefix($input->getOption('prefix'));
foreach ($transPaths as $path) {
$path .= 'views';
if (is_dir($path)) {

View File

@ -129,12 +129,12 @@ class ExceptionController
$template = (string) $template;
$loader = $this->twig->getLoader();
if ($loader instanceof \Twig_ExistsLoaderInterface) {
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
return $loader->exists($template);
}
try {
$loader->getSource($template);
$loader->getSourceContext($template)->getCode();
return true;
} catch (\Twig_Error_Loader $e) {

View File

@ -19,22 +19,22 @@ namespace Symfony\Component\HttpFoundation;
class RequestMatcher implements RequestMatcherInterface
{
/**
* @var string
* @var string|null
*/
private $path;
/**
* @var string
* @var string|null
*/
private $host;
/**
* @var array
* @var string[]
*/
private $methods = array();
/**
* @var string
* @var string[]
*/
private $ips = array();
@ -76,13 +76,13 @@ class RequestMatcher implements RequestMatcherInterface
*/
public function matchScheme($scheme)
{
$this->schemes = array_map('strtolower', (array) $scheme);
$this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : array();
}
/**
* Adds a check for the URL host name.
*
* @param string $regexp A Regexp
* @param string|null $regexp A Regexp
*/
public function matchHost($regexp)
{
@ -92,7 +92,7 @@ class RequestMatcher implements RequestMatcherInterface
/**
* Adds a check for the URL path info.
*
* @param string $regexp A Regexp
* @param string|null $regexp A Regexp
*/
public function matchPath($regexp)
{
@ -112,21 +112,21 @@ class RequestMatcher implements RequestMatcherInterface
/**
* Adds a check for the client IP.
*
* @param string|string[] $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
* @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
*/
public function matchIps($ips)
{
$this->ips = (array) $ips;
$this->ips = null !== $ips ? (array) $ips : array();
}
/**
* Adds a check for the HTTP method.
*
* @param string|string[] $method An HTTP method or an array of HTTP methods
* @param string|string[]|null $method An HTTP method or an array of HTTP methods
*/
public function matchMethod($method)
{
$this->methods = array_map('strtoupper', (array) $method);
$this->methods = null !== $method ? array_map('strtoupper', (array) $method) : array();
}
/**
@ -145,11 +145,11 @@ class RequestMatcher implements RequestMatcherInterface
*/
public function matches(Request $request)
{
if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
if ($this->schemes && !in_array($request->getScheme(), $this->schemes, true)) {
return false;
}
if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
if ($this->methods && !in_array($request->getMethod(), $this->methods, true)) {
return false;
}

View File

@ -140,12 +140,16 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
}
$loader = $this->templating->getLoader();
if ($loader instanceof \Twig_ExistsLoaderInterface) {
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
return $loader->exists($template);
}
try {
$loader->getSource($template);
if (method_exists($loader, 'getSourceContext')) {
$loader->getSourceContext($template);
} else {
$loader->getSource($template);
}
return true;
} catch (\Twig_Error_Loader $e) {