8000 [FrameworkBundle] Backport type fixes by derrabus · Pull Request #43871 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Backport type fixes #43871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ final class CachePoolClearerCacheWarmer implements CacheWarmerInterface
private $poolClearer;
private $pools;

/**
* @param string[] $pools
*/
public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
{
$this->poolClearer = $poolClearer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class CachePoolClearCommand extends Command
private $poolClearer;
private $poolNames;

/**
* @param string[]|null $poolNames
*/
public function __construct(Psr6CacheClearer $poolClearer, array $poolNames = null)
{
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ final class CachePoolDeleteCommand extends Command
private $poolClearer;
private $poolNames;

/**
* @param string[]|null $poolNames
*/
public function __construct(Psr6CacheClearer $poolClearer, array $poolNames = null)
{
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ final class CachePoolListCommand extends Command

private $poolNames;

/**
* @param string[] $poolNames
*/
public function __construct(array $poolNames)
{
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class CachePoolPruneCommand extends Command
private $pools;

/**
* @param iterable|PruneableInterface[] $pools
* @param iterable<mixed, PruneableInterface> $pools
*/
public function __construct(iterable $pools)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
use Symfony\Component\Routing\RouterInterface;

Expand All @@ -36,6 +37,9 @@ class RouterMatchCommand extends Command
private $router;
private $expressionLanguageProviders;

/**
* @param iterable<mixed, ExpressionFunctionProviderInterface> $expressionLanguageProviders
*/
public function __construct(RouterInterface $router, iterable $expressionLanguageProviders = [])
{
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class UnusedTagsPass implements CompilerPassInterface
{
private $knownTags = [
private const KNOWN_TAGS = [
'annotations.cached_reader',
'assets.package',
'auto_alias',
Expand Down Expand Up @@ -74,10 +74,10 @@ class UnusedTagsPass implements CompilerPassInterface
'routing.expression_language_provider',
'routing.loader',
'routing.route_loader',
'security.authenticator.login_linker',
'security.expression_language_provider',
'security.remember_me_aware',
'security.remember_me_handler',
'security.authenticator.login_linker',
'security.voter',
'serializer.encoder',
'serializer.normalizer',
Expand All @@ -96,11 +96,11 @@ class UnusedTagsPass implements CompilerPassInterface

public function process(ContainerBuilder $container)
{
$tags = array_unique(array_merge($container->findTags(), $this->knownTags));
$tags = array_unique(array_merge($container->findTags(), self::KNOWN_TAGS));

foreach ($container->findUnusedTags() as $tag) {
// skip known tags
if (\in_array($tag, $this->knownTags)) {
if (\in_array($tag, self::KNOWN_TAGS)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

$target = dirname(__DIR__, 2).'/DependencyInjection/Compiler/UnusedTagsPass.php';
$contents = file_get_contents($target);
$contents = preg_replace('{private \$knownTags = \[(.+?)\];}sm', "private \$knownTags = [\n '".implode("',\n '", UnusedTagsPassUtils::getDefinedTags())."',\n ];", $contents);
$contents = preg_replace('{private const KNOWN_TAGS = \[(.+?)\];}sm', "private const KNOWN_TAGS = [\n '".implode(&q F438 uot;',\n '", UnusedTagsPassUtils::getDefinedTags())."',\n ];", $contents);
file_put_contents($target, $contents);
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function __construct(ContainerInterface $container, $resource, array $opt
$this->setOptions($options);

if ($parameters) {
$this->paramFetcher = [$parameters, 'get'];
$this->paramFetcher = \Closure::fromCallable([$parameters, 'get']);
} elseif ($container instanceof SymfonyContainerInterface) {
$this->paramFetcher = [$container, 'getParameter'];
$this->paramFetcher = \Closure::fromCallable([$container, 'getParameter']);
} else {
throw new \LogicException(sprintf('You should either pass a "%s" instance or provide the $parameters argument of the "%s" method.', SymfonyContainerInterface::class, __METHOD__));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function testMissingKnownTags()

private function getKnownTags(): array
{
// get tags in UnusedTagsPass
$target = \dirname(__DIR__, 3).'/DependencyInjection/Compiler/UnusedTagsPass.php';
$contents = file_get_contents($target);
preg_match('{private \$knownTags = \[(.+?)\];}sm', $contents, $matches);
$tags = array_values(array_filter(array_map(function ($str) {
return trim(preg_replace('{^ +\'(.+)\',}', '$1', $str));
}, explode("\n", $matches[1]))));
$tags = \Closure::bind(
static function () {
return UnusedTagsPass::KNOWN_TAGS;
},
null,
UnusedTagsPass::class
)();
sort($tags);

return $tags;
Expand Down
15 changes: 9 additions & 6 deletions src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ class Translator extends BaseTranslator implements WarmableInterface
];

/**
* @var array
* @var list<string>
*/
private $resourceLocales;

/**
* Holds parameters from addResource() calls so we can defer the actual
* parent::addResource() calls until initialize() is executed.
*
* @var array
* @var array[]
*/
private $resources = [];

/**
* @var string[][]
*/
private $resourceFiles;

/**
Expand Down Expand Up @@ -152,7 +155,7 @@ protected function initialize()
if ($this->resourceFiles) {
$this->addResourceFiles();
}
foreach ($this->resources as $key => $params) {
foreach ($this->resources as $params) {
[$format, $resource, $locale, $domain] = $params;
parent::addResource($format, $resource, $locale, $domain);
}
Expand All @@ -165,13 +168,13 @@ protected function initialize()
}
}

private function addResourceFiles()
private function addResourceFiles(): void
{
$filesByLocale = $this->resourceFiles;
$this->resourceFiles = [];

foreach ($filesByLocale as $locale => $files) {
foreach ($files as $key => $file) {
foreach ($filesByLocale as $files) {
foreach ($files as $file) {
// filename is domain.locale.format
$fileNameParts = explode('.', basename($file));
$format = array_pop($fileNameParts);
Expand Down
0