Merge branch '3.4' into 4.3
* 3.4: Return null as Expire header if it was set to null [ProxyManager] remove ProxiedMethodReturnExpression polyfill fix dumping not inlined scalar tag values
This commit is contained in:
commit
247815d21c
|
@ -136,8 +136,7 @@
|
||||||
"Symfony\\Component\\": "src/Symfony/Component/"
|
"Symfony\\Component\\": "src/Symfony/Component/"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"src/Symfony/Component/Intl/Resources/stubs",
|
"src/Symfony/Component/Intl/Resources/stubs"
|
||||||
"src/Symfony/Bridge/ProxyManager/Legacy/ProxiedMethodReturnExpression.php"
|
|
||||||
],
|
],
|
||||||
"exclude-from-classmap": [
|
"exclude-from-classmap": [
|
||||||
"**/Tests/"
|
"**/Tests/"
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace ProxyManager\Generator\Util;
|
|
||||||
|
|
||||||
use Composer\Autoload\ClassLoader;
|
|
||||||
use ProxyManager\Version;
|
|
||||||
|
|
||||||
if (class_exists(Version::class) && version_compare(\defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion(), '2.5', '<')) {
|
|
||||||
/**
|
|
||||||
* Utility class to generate return expressions in method, given a method signature.
|
|
||||||
*
|
|
||||||
* This is required since return expressions may be forbidden by the method signature (void).
|
|
||||||
*
|
|
||||||
* @author Marco Pivetta <ocramius@gmail.com>
|
|
||||||
* @license MIT
|
|
||||||
*
|
|
||||||
* @see https://github.com/Ocramius/ProxyManager
|
|
||||||
*/
|
|
||||||
final class ProxiedMethodReturnExpression
|
|
||||||
{
|
|
||||||
public static function generate(string $returnedValueExpression, ?\ReflectionMethod $originalMethod): string
|
|
||||||
{
|
|
||||||
$originalReturnType = null === $originalMethod ? null : $originalMethod->getReturnType();
|
|
||||||
|
|
||||||
$originalReturnTypeName = null === $originalReturnType ? null : $originalReturnType->getName();
|
|
||||||
|
|
||||||
if ('void' === $originalReturnTypeName) {
|
|
||||||
return $returnedValueExpression.";\nreturn;";
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'return '.$returnedValueExpression.';';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback to the original class by unregistering this file from composer class loader
|
|
||||||
$getComposerClassLoader = static function ($functionLoader) use (&$getComposerClassLoader) {
|
|
||||||
if (\is_array($functionLoader)) {
|
|
||||||
$functionLoader = $functionLoader[0];
|
|
||||||
}
|
|
||||||
if (!\is_object($functionLoader)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if ($functionLoader instanceof ClassLoader) {
|
|
||||||
return $functionLoader;
|
|
||||||
}
|
|
||||||
if ($functionLoader instanceof \Symfony\Component\Debug\DebugClassLoader) {
|
|
||||||
return $getComposerClassLoader($functionLoader->getClassLoader());
|
|
||||||
}
|
|
||||||
if ($functionLoader instanceof \Symfony\Component\ErrorHandler\DebugClassLoader) {
|
|
||||||
return $getComposerClassLoader($functionLoader->getClassLoader());
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
$classLoader = null;
|
|
||||||
$functions = spl_autoload_functions();
|
|
||||||
while (null === $classLoader && $functions) {
|
|
||||||
$classLoader = $getComposerClassLoader(array_shift($functions));
|
|
||||||
}
|
|
||||||
$getComposerClassLoader = null;
|
|
||||||
|
|
||||||
if (null !== $classLoader) {
|
|
||||||
$classLoader->addClassMap([ProxiedMethodReturnExpression::class => null]);
|
|
||||||
$classLoader->loadClass(ProxiedMethodReturnExpression::class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,7 +28,6 @@
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" },
|
"psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" },
|
||||||
"classmap": [ "Legacy/ProxiedMethodReturnExpression.php" ],
|
|
||||||
"exclude-from-classmap": [
|
"exclude-from-classmap": [
|
||||||
"/Tests/"
|
"/Tests/"
|
||||||
]
|
]
|
||||||
|
|
|
@ -121,7 +121,15 @@ class HeaderBag implements \IteratorAggregate, \Countable
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($first) {
|
if ($first) {
|
||||||
return \count($headers[$key]) ? (string) $headers[$key][0] : $default;
|
if (!$headers[$key]) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $headers[$key][0]) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $headers[$key][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $headers[$key];
|
return $headers[$key];
|
||||||
|
|
|
@ -48,6 +48,13 @@ class HeaderBagTest extends TestCase
|
||||||
$this->assertInstanceOf('DateTime', $headerDate);
|
$this->assertInstanceOf('DateTime', $headerDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetDateNull()
|
||||||
|
{
|
||||||
|
$bag = new HeaderBag(['foo' => null]);
|
||||||
|
$headerDate = $bag->getDate('foo');
|
||||||
|
$this->assertNull($headerDate);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetDateException()
|
public function testGetDateException()
|
||||||
{
|
{
|
||||||
$this->expectException('RuntimeException');
|
$this->expectException('RuntimeException');
|
||||||
|
@ -96,6 +103,9 @@ class HeaderBagTest extends TestCase
|
||||||
$bag->set('foo', 'bor', false);
|
$bag->set('foo', 'bor', false);
|
||||||
$this->assertEquals('bar', $bag->get('foo'), '->get return first value');
|
$this->assertEquals('bar', $bag->get('foo'), '->get return first value');
|
||||||
$this->assertEquals(['bar', 'bor'], $bag->get('foo', 'nope', false), '->get return all values as array');
|
$this->assertEquals(['bar', 'bor'], $bag->get('foo', 'nope', false), '->get return all values as array');
|
||||||
|
|
||||||
|
$bag->set('baz', null);
|
||||||
|
$this->assertNull($bag->get('baz', 'nope'), '->get return null although different default value is given');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetAssociativeArray()
|
public function testSetAssociativeArray()
|
||||||
|
|
|
@ -370,6 +370,12 @@ class ResponseTest extends ResponseTestCase
|
||||||
$this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh');
|
$this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNullExpireHeader()
|
||||||
|
{
|
||||||
|
$response = new Response(null, 200, ['Expires' => null]);
|
||||||
|
$this->assertNull($response->getExpires());
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetTtl()
|
public function testGetTtl()
|
||||||
{
|
{
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
|
|
|
@ -85,6 +85,10 @@ class Dumper
|
||||||
} else {
|
} else {
|
||||||
$output .= "\n";
|
$output .= "\n";
|
||||||
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
|
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
|
||||||
|
|
||||||
|
if (is_scalar($value->getValue())) {
|
||||||
|
$output .= "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -459,6 +459,23 @@ YAML;
|
||||||
$this->assertSame($expected, $yaml);
|
$this->assertSame($expected, $yaml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDumpingNotInlinedScalarTaggedValue()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user1' => new TaggedValue('user', 'jane'),
|
||||||
|
'user2' => new TaggedValue('user', 'john'),
|
||||||
|
];
|
||||||
|
$expected = <<<YAML
|
||||||
|
user1: !user
|
||||||
|
jane
|
||||||
|
user2: !user
|
||||||
|
john
|
||||||
|
|
||||||
|
YAML;
|
||||||
|
|
||||||
|
$this->assertSame($expected, $this->dumper->dump($data, 2));
|
||||||
|
}
|
||||||
|
|
||||||
public function testDumpMultiLineStringAsScalarBlock()
|
public function testDumpMultiLineStringAsScalarBlock()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
|
Reference in New Issue