8000 Merge branch '3.1' · symfony/symfony@b376d92 · GitHub
[go: up one dir, main page]

Skip to content

Commit b376d92

Browse files
committed
Merge branch '3.1'
* 3.1: 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
2 parents a6ea24e + 790e7dd commit b376d92

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testTrans($template, $expected, array $variables = array())
3636
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
3737
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
3838

39-
echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n";
39+
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext('index'))))."\n\n";
4040
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
4141
}
4242

src/Symfony/Bridge/Twig/TwigEngine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public function exists($name)
7575

7676
$loader = $this->environment->getLoader();
7777

78-
if ($loader instanceof \Twig_ExistsLoaderInterface) {
78+
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
7979
return $loader->exists 8000 ((string) $name);
8080
}
8181

8282
try {
8383
// cast possible TemplateReferenceInterface to string because the
8484
// EngineInterface supports them but Twig_LoaderInterface does not
85-
$loader->getSource((string) $name);
85+
$loader->getSourceContext((string) $name)->getCode();
8686
} catch (\Twig_Error_Loader $e) {
8787
return false;
8888
}

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
132132
// load any messages from templates
133133
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
134134
$io->comment('Parsing templates...');
135-
$prefix = $input->getOption('prefix');
136135
$extractor = $this->getContainer()->get('translation.extractor');
137-
$extractor->setPrefix(null === $prefix ? '' : $prefix);
136+
$extractor->setPrefix($input->getOption('prefix'));
138137
foreach ($transPaths as $path) {
139138
$path .= 'views';
140139
if (is_dir($path)) {

src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ protected function templateExists($template)
129129
$template = (string) $template;
130130

131131
$loader = $this->twig->getLoader();
132-
if ($loader instanceof \Twig_ExistsLoaderInterface) {
132+
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
133133
return $loader->exists($template);
134134
}
135135

136136
try {
137-
$loader->getSource($template);
137+
$loader->getSourceContext($template)->getCode();
138138

139139
return true;
140140
} catch (\Twig_Error_Loader $e) {

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
class RequestMatcher implements RequestMatcherInterface
2020
{
2121
/**
22-
* @var string
22+
* @var string|null
2323
*/
2424
private $path;
2525

2626
/**
27-
* @var string
27+
* @var string|null
2828
*/
2929
private $host;
3030

3131
/**
32-
* @var array
32+
* @var string[]
3333
*/
3434
private $methods = array();
3535

3636
/**
37-
* @var string
37+
* @var string[]
3838
*/
3939
private $ips = array();
4040

@@ -76,13 +76,13 @@ public function __construct($path = null, $host = null, $methods = null, $ips =
7676
*/
7777
public function matchScheme($scheme)
7878
{
79-
$this->schemes = array_map('strtolower', (array) $scheme);
79+
$this->schemes = null !== $scheme ? array_map('strtolower', (array) $scheme) : array();
8080
}
8181

8282
/**
8383
* Adds a check for the URL host name.
8484
*
85-
* @param string $regexp A Regexp
85+
* @param string|null $regexp A Regexp
8686
*/
8787
public function matchHost($regexp)
8888
{
@@ -92,7 +92,7 @@ public function matchHost($regexp)
9292
/**
9393
* Adds a check for the URL path info.
9494
*
95-
* @param string $regexp A Regexp
95+
* @param string|null $regexp A Regexp
9696
*/
9797
public function matchPath($regexp)
9898
{
@@ -112,21 +112,21 @@ public function matchIp($ip)
112112
/**
113113
* Adds a check for the client IP.
114114
*
115-
* @param string|string[] $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
115+
* @param string|string[]|null $ips A specific IP address or a range specified using IP/netmask like 192.168.1.0/24
116116
*/
117117
public function matchIps($ips)
118118
{
119-
$this->ips = (array) $ips;
119+
$this->ips = null !== $ips ? (array) $ips : array();
120120
}
121121

122122
/**
123123
* Adds a check for the HTTP method.
124124
*
125-
* @param string|string[] $method An HTTP method or an array of HTTP methods
125+
* @param string|string[]|null $method An HTTP method or an array of HTTP methods
126126
*/
127127
public function matchMethod($method)
128128
{
129-
$this->methods = array_map('strtoupper', (array) $method);
129+
$this->methods = null !== $method ? array_map('strtoupper', (array) $method) : array();
130130
}
131131

132132
/**
@@ -145,11 +145,11 @@ public function matchAttribute($key, $regexp)
145145
*/
146146
public function matches(Request $request)
147147
{
148-
if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
148+
if ($this->schemes && !in_array($request->getScheme(), $this->schemes, true)) {
149149
return false;
150150
}
151151

152-
if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
152+
if ($this->methods && !in_array($request->getMethod(), $this->methods, true)) {
153153
return false;
154154
}
155155

src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ private function templateExists($template)
136136
}
137137

138138
$loader = $this->templating->getLoader();
139-
if ($loader instanceof \Twig_ExistsLoaderInterface) {
139+
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
140140
return $loader->exists($template);
141141
}
142142

143143
try {
144-
$loader->getSource($template);
144+
if (method_exists($loader, 'getSourceContext')) {
145+
$loader->getSourceContext($template);
146+
} else {
147+
$loader->getSource($template);
148+
}
145149

146150
return true;
147151
} catch (\Twig_Error_Loader $e) {

0 commit comments

Comments
 (0)
0