Skip to content

Commit 31dcefe

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: [HttpFoundation] Drop int return type from parseFilesize() Added $translator->addLoader() bug symfony#39878 [doctrine-bridge] Add username to UserNameNotFoundException [Uid] Clarify the format returned by getTime() fix spelling Add check for constant in Curl client Revert symfony#38614, add assert to avoid regression Fix container injection with TypedReference Fix problem when SYMFONY_PHPUNIT_VERSION is empty string value Update PHP CS Fixer config to v2.18
2 parents b82378d + c639531 commit 31dcefe

File tree

23 files changed

+277
-45
lines changed

23 files changed

+277
-45
lines changed

.appveyor.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ install:
2626
- echo memory_limit=-1 >> php.ini-min
2727
- echo serialize_precision=-1 >> php.ini-min
2828
- echo max_execution_time=1200 >> php.ini-min
29+
- echo post_max_size=4G >> php.ini-min
30+
- echo upload_max_filesize=4G >> php.ini-min
2931
- echo date.timezone="America/Los_Angeles" >> php.ini-min
3032
- echo extension_dir=ext >> php.ini-min
3133
- echo extension=php_xsl.dll >> php.ini-min

.php_cs.dist

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ return PhpCsFixer\Config::create()
1111
'@Symfony' => true,
1212
'@Symfony:risky' => true,
1313
'protected_to_private' => false,
14-
'native_constant_invocation' => true,
15-
'list_syntax' => ['syntax' => 'short'],
1614
])
1715
->setRiskyAllowed(true)
1816
->setFinder(

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ public function loadUserByUsername(string $username)
6262
}
6363

6464
if (null === $user) {
65-
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
65+
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
66+
$e->setUsername($username);
67+
68+
throw $e;
6669
}
6770

6871
return $user;
@@ -92,7 +95,10 @@ public function refreshUser(UserInterface $user)
9295

9396
$refreshedUser = $repository->find($id);
9497
if (null === $refreshedUser) {
95-
throw new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
98+
$e = new UsernameNotFoundException('User with id '.json_encode($id).' not found.');
99+
$e->setUsername(json_encode($id));
100+
101+
throw $e;
96102
}
97103
}
98104

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@
9595

9696
if (\PHP_VERSION_ID >= 80000) {
9797
// PHP 8 requires PHPUnit 9.3+
98-
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.4');
98+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.4') ?: '9.4';
9999
} elseif (\PHP_VERSION_ID >= 70200) {
100100
// PHPUnit 8 requires PHP 7.2+
101-
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.3');
101+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.3') ?: '8.3';
102102
} elseif (\PHP_VERSION_ID >= 70100) {
103103
// PHPUnit 7 requires PHP 7.1+
104-
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '7.5');
104+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '7.5') ?: '7.5';
105105
} elseif (\PHP_VERSION_ID >= 70000) {
106106
// PHPUnit 6 requires PHP 7.0+
107-
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
107+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5') ?: '6.5';
108108
} elseif (\PHP_VERSION_ID >= 50600) {
109109
// PHPUnit 4 does not support PHP 7
110-
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
110+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7') ?: '5.7';
111111
} else {
112112
// PHPUnit 5.1 requires PHP 5.6+
113113
$PHPUNIT_VERSION = '4.8';

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public function loadUserByUsername($username)
3434
$user = $this->getUser($username);
3535

3636
if (null === $user) {
37-
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
37+
$e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
38+
$e->setUsername($username);
39+
40+
throw $e;
3841
}
3942

4043
return $user;

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ protected function {$methodName}($lazyInitialization)
904904

905905
$factoryCode = $asFile ? 'self::do($container, false)' : sprintf('$this->%s(false)', $methodName);
906906
$factoryCode = $this->getProxyDumper()->getProxyFactoryCode($definition, $id, $factoryCode);
907-
$code .= $asFile ? preg_replace('/function \(([^)]*+)\) {/', 'function (\1) use ($container) {', $factoryCode) : $factoryCode;
907+
$code .= $asFile ? preg_replace('/function \(([^)]*+)\)( {|:)/', 'function (\1) use ($container)\2', $factoryCode) : $factoryCode;
908908
}
909909

910910
$c = $this->addServiceInclude($id, $definition);
@@ -934,8 +934,7 @@ protected function {$methodName}($lazyInitialization)
934934

935935
if ($asFile) {
936936
$code = str_replace('$this', '$container', $code);
937-
$code = str_replace('function () {', 'function () use ($container) {', $code);
938-
$code = str_replace('function ($lazyLoad = true) {', 'function ($lazyLoad = true) use ($container) {', $code);
937+
$code = preg_replace('/function \(([^)]*+)\)( {|:)/', 'function (\1) use ($container)\2', $code);
939938
}
940939

941940
$code .= " }\n";

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ public function testDumpAsFiles()
244244
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_as_files.txt', $dump);
245245
}
246246

247+
public function testDumpAsFilesWithTypedReference()
248+
{
249+
$container = include self::$fixturesPath.'/containers/container10.php';
250+
$container->getDefinition('foo')->addTag('hot');
251+
$container->register('bar', 'stdClass');
252+
$container->register('closure', 'stdClass')
253+
->setProperty('closures', [
254+
new ServiceClosureArgument(new TypedReference('foo', \stdClass::class, $container::IGNORE_ON_UNINITIALIZED_REFERENCE)),
255+
])
256+
->setPublic(true);
257+
$container->compile();
258+
$dumper = new PhpDumper($container);
259+
$dump = print_r($dumper->dump(['as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot', 'inline_factories_parameter' => false, 'inline_class_loader_parameter' => false]), true);
260+
if ('\\' === \DIRECTORY_SEPARATOR) {
261+
$dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump);
262+
}
263+
264+
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services10_as_files.txt', $dump);
265+
}
266+
247267
public function testDumpAsFilesWithFactoriesInlined()
248268
{
249269
$container = include self::$fixturesPath.'/containers/container9.php';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Array
2+
(
3+
[Container%s/removed-ids.php] => <?php
4+
5+
namespace Container%s;
6+
7+
return [
8+
'Psr\\Container\\ContainerInterface' => true,
9+
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
10+
'bar' => true,
11+
];
12+
13+
[Container%s/getClosureService.php] => <?php
14+
15+
namespace Container%s;
16+
17+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
18+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
19+
20+
/**
21+
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
22+
*/
23+
class getClosureService extends ProjectServiceContainer
24+
{
25+
/**
26+
* Gets the public 'closure' shared service.
27+
*
28+
* @return \stdClass
29+
*/
30+
public static function do($container, $lazyLoad = true)
31+
{
32+
$container->services['closure'] = $instance = new \stdClass();
33+
34+
$instance->closures = [0 => function () use ($container): ?\stdClass {
35+
return ($container->services['foo'] ?? null);
36+
}];
37+
38+
return $instance;
39+
}
40+
}
41+
42+
[Container%s/ProjectServiceContainer.php] => <?php
43+
44+
namespace Container%s;
45+
46+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
47+
use Symfony\Component\DependencyInjection\ContainerInterface;
48+
use Symfony\Component\DependencyInjection\Container;
49+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
50+
use Symfony\Component\DependencyInjection\Exception\LogicException;
51+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
52+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
53+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
54+
55+
/**
56+
* @internal This class has been auto-generated by the Symfony Dependency Injection Component.
57+
*/
58+
class ProjectServiceContainer extends Container
59+
{
60+
protected $containerDir;
61+
protected $targetDir;
62+
protected $parameters = [];
63+
private $buildParameters;
64+
65+
public function __construct(array $buildParameters = [], $containerDir = __DIR__)
66+
{
67+
$this->buildParameters = $buildParameters;
68+
$this->containerDir = $containerDir;
69+
$this->targetDir = \dirname($containerDir);
70+
$this->services = $this->privates = [];
71+
$this->methodMap = [
72+
'foo' => 'getFooService',
73+
];
74+
$this->fileMap = [
75+
'closure' => 'getClosureService',
76+
];
77+
78+
$this->aliases = [];
79+
}
80+
81+
public function compile(): void
82+
{
83+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
84+
}
85+
86+
public function isCompiled(): bool
87+
{
88+
return true;
89+
}
90+
91+
public function getRemovedIds(): array
92+
{
93+
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
94+
}
95+
96+
protected function load($file, $lazyLoad = true)
97+
{
98+
if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) {
99+
return $class::do($this, $lazyLoad);
100+
}
101+
102+
if ('.' === $file[-4]) {
103+
$class = substr($class, 0, -4);
104+
} else {
105+
$file .= '.php';
106+
}
107+
108+
$service = require $this->containerDir.\DIRECTORY_SEPARATOR.$file;
109+
110+
return class_exists($class, false) ? $class::do($this, $lazyLoad) : $service;
111+
}
112+
113+
/**
114+
* Gets the public 'foo' shared service.
115+
*
116+
* @return \FooClass
117+
*/
118+
protected function getFooService()
119+
{
120+
return $this->services['foo'] = new \FooClass(new \stdClass());
121+
}
122+
}
123+
124+
[ProjectServiceContainer.preload.php] => <?php
125+
126+
// This file has been auto-generated by the Symfony Dependency Injection Component
127+
// You can reference it in the "opcache.preload" php.ini setting on PHP >= 7.4 when preloading is desired
128+
129+
use Symfony\Component\DependencyInjection\Dumper\Preloader;
130+
131+
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
132+
return;
133+
}
134+
135+
require dirname(__DIR__, %d).'%svendor/autoload.php';
136+
require __DIR__.'/Container%s/ProjectServiceContainer.php';
137+
require __DIR__.'/Container%s/getClosureService.php';
138+
139+
$classes = [];
140+
$classes[] = 'FooClass';
141+
$classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface';
142+
143+
Preloader::preload($classes);
144+
145+
[ProjectServiceContainer.php] => <?php
146+
147+
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
148+
149+
if (\class_exists(\Container%s\ProjectServiceContainer::class, false)) {
150+
// no-op
151+
} elseif (!include __DIR__.'/Container%s/ProjectServiceContainer.php') {
152+
touch(__DIR__.'/Container%s.legacy');
153+
154+
return;
155+
}
156+
157+
if (!\class_exists(ProjectServiceContainer::class, false)) {
158+
\class_alias(\Container%s\ProjectServiceContainer::class, ProjectServiceContainer::class, false);
159+
}
160+
161+
return new \Container%s\ProjectServiceContainer([
162+
'container.build_hash' => '%s',
163+
'container.build_id' => '%s',
164+
'container.build_time' => %d,
165+
], __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
166+
167+
)

src/Symfony/Component/Form/Extension/Core/Type/FileType.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ private function getFileUploadError(int $errorCode)
176176
* Returns the maximum size of an uploaded file as configured in php.ini.
177177
*
178178
* This method should be kept in sync with Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize().
179+
*
180+
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
179181
*/
180-
private static function getMaxFilesize(): int
182+
private static function getMaxFilesize()
181183
{
182184
$iniMax = strtolower(ini_get('upload_max_filesize'));
183185

@@ -212,8 +214,10 @@ private static function getMaxFilesize(): int
212214
* (i.e. try "MB", then "kB", then "bytes").
213215
*
214216
* This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::factorizeSizes().
217+
*
218+
* @param int|float $limit
215219
*/
216-
private function factorizeSizes(int $size, int $limit)
220+
private function factorizeSizes(int $size, $limit)
217221
{
218222
$coef = self::MIB_BYTES;
219223
$coefFactor = self::KIB_BYTES;

src/Symfony/Component/HttpClient/CurlHttpClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function request(string $method, string $url, array $options = []): Respo
173173
$curlopts[\CURLOPT_DNS_USE_GLOBAL_CACHE] = false;
174174
}
175175

176-
if (\defined('CURLOPT_HEADEROPT')) {
176+
if (\defined('CURLOPT_HEADEROPT') && \defined('CURLHEADER_SEPARATE')) {
177177
$curlopts[\CURLOPT_HEADEROPT] = \CURLHEADER_SEPARATE;
178178
}
179179

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function move(string $directory, string $name = null)
216216
/**
217217
* Returns the maximum size of an uploaded file as configured in php.ini.
218218
*
219-
* @return int The maximum size of an uploaded file in bytes
219+
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
220220
*/
221221
public static function getMaxFilesize()
222222
{
@@ -228,8 +228,10 @@ public static function getMaxFilesize()
228228

229229
/**
230230
* Returns the given size from an ini value in bytes.
231+
*
232+
* @return int|float Returns float if size > PHP_INT_MAX
231233
*/
232-
private static function parseFilesize($size): int
234+
private static function parseFilesize($size)
233235
{
234236
if ('' === $size) {
235237
return 0;

src/Symfony/Component/HttpFoundation/Request.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -1895,15 +1895,9 @@ protected function prepareBaseUrl()
18951895
}
18961896

18971897
$basename = basename($baseUrl);
1898-
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
1899-
// strip autoindex filename, for virtualhost based on URL path
1900-
$baseUrl = \dirname($baseUrl).'/';
1901-
1902-
$basename = basename($baseUrl);
1903-
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri).'/', '/'.$basename.'/')) {
1904-
// no match whatsoever; set it blank
1905-
return '';
1906-
}
1898+
if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
1899+
// no match whatsoever; set it blank
1900+
return '';
19071901
}
19081902

19091903
// If using mod_rewrite or ISAPI_Rewrite strip the script filename

0 commit comments

Comments
 (0)