Skip to content

Commit

Permalink
Update warmup signature on all WarmableInterface implementations
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
  • Loading branch information
Okhoshi committed Oct 12, 2023
1 parent 2d6bfb7 commit 9d49f41
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function isOptional(): bool
}

/**
* @return string[] A list of files to preload on PHP 7.4+
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$files = [];
foreach ($this->registry->getManagers() as $em) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ public function isOptional(): bool
}

/**
* @return string[] A list of classes to preload on PHP 7.4+
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$buildDir = 1 < \func_num_args() ? func_get_arg(1) : null;
$arrayAdapter = new ArrayAdapter();

spl_autoload_register([ClassExistenceResource::class, 'throwOnRequiredClass']);
try {
if (!$this->doWarmUp($cacheDir, $arrayAdapter)) {
if (!$this->doWarmUp($cacheDir, $arrayAdapter, $buildDir)) {
return [];
}
} finally {
Expand Down Expand Up @@ -78,7 +79,9 @@ final protected function ignoreAutoloadException(string $class, \Exception $exce
}

/**
* @param string|null $buildDir
*
* @return bool false if there is nothing to warm-up
*/
abstract protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool;
abstract protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public function __construct(
parent::__construct($phpArrayFile);
}

protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
/**
* @param string|null $buildDir
*/
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool
{
$annotatedClassPatterns = $cacheDir.'/annotations.map';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
$this->pools = $pools;
}

/**
* @return string[]
*/
public function warmUp(string $cacheDirectory): array
public function warmUp(string $cacheDir, string $buildDir = null): array
{
foreach ($this->pools as $pool) {
if ($this->poolClearer->hasPool($pool)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public function __construct(ContainerInterface $container)
$this->container = $container;
}

public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir, string $buildDir = null): array
{
$router = $this->container->get('router');

if ($router instanceof WarmableInterface) {
return (array) $router->warmUp($cacheDir);
return (array) $router->warmUp($cacheDir, $buildDir);
}

throw new \LogicException(sprintf('The router "%s" cannot be warmed up because it does not implement "%s".', get_debug_type($router), WarmableInterface::class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public function __construct(array $loaders, string $phpArrayFile)
$this->loaders = $loaders;
}

protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
/**
* @param string|null $buildDir
*/
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool
{
if (!$this->loaders) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public function __construct(ContainerInterface $container)
}

/**
* @return string[]
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$this->translator ??= $this->container->get('translator');

if ($this->translator instanceof WarmableInterface) {
return (array) $this->translator->warmUp($cacheDir);
$buildDir = 1 < \func_num_args() ? func_get_arg(1) : null;

return (array) $this->translator->warmUp($cacheDir, $buildDir);
}

return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public function __construct(ValidatorBuilder $validatorBuilder, string $phpArray
$this->validatorBuilder = $validatorBuilder;
}

protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
/**
* @param string|null $buildDir
*/
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool
{
$loaders = $this->validatorBuilder->getLoaders();
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), $arrayAdapter);
Expand Down
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 @@ -81,9 +81,9 @@ public function getRouteCollection(): RouteCollection
}

/**
* @return string[] A list of classes to preload on PHP 7.4+
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$currentDir = $this->getOption('cache_dir');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function isOptional(): bool
return false;
}

public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir, string $buildDir = null): array
{
file_put_contents($cacheDir.'/dummy.txt', 'Hello');

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public function __construct(ContainerInterface $container, MessageFormatterInter
}

/**
* @return string[]
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
// skip warmUp when translator doesn't use cache
if (null === $this->options['cache_dir']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function isOptional(): bool
}

/**
* @return string[]
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
foreach ($this->expressions as $expression) {
$this->expressionLanguage->parse($expression, ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function __construct(ContainerInterface $container, iterable $iterator)
}

/**
* @return string[] A list of template files to preload on PHP 7.4+
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$this->twig ??= $this->container->get('twig');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(string $file)
$this->file = $file;
}

public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir, string $buildDir = null): array
{
$this->writeCacheFile($this->file, 'content');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
) {
}

public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir, string $buildDir = null): array
{
$metadatas = [];

Expand Down
8 changes: 5 additions & 3 deletions src/Symfony/Component/Translation/DataCollectorTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ public function getCatalogues(): array
}

/**
* @return string[]
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir): array
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$buildDir = 1 < \func_num_args() ? func_get_arg(1) : null;

if ($this->translator instanceof WarmableInterface) {
return (array) $this->translator->warmUp($cacheDir);
return (array) $this->translator->warmUp($cacheDir, $buildDir);
}

return [];
Expand Down

0 comments on commit 9d49f41

Please sign in to comment.