Skip to content

Commit

Permalink
Cache Autowiring::buildServiceClasses into a transient
Browse files Browse the repository at this point in the history
  • Loading branch information
mbmjertan authored Oct 30, 2024
1 parent c7c54bd commit df27181
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Main/Autowiring.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Autowiring
*/
public function buildServiceClasses(array $manuallyDefinedDependencies = [], bool $skipInvalid = false): array
{
if ($cachedValue = \get_transient("{$this->namespace}_autowiring_cache")) {
return $cachedValue;
}

$projectReflectionClasses = $this->validateAndBuildClasses(
$this->filterManuallyDefinedDependencies(
$this->getClassesInNamespace($this->namespace, $this->psr4Prefixes),
Expand Down Expand Up @@ -102,7 +106,9 @@ public function buildServiceClasses(array $manuallyDefinedDependencies = [], boo
}

// Convert dependency tree into PHP-DI's definition list.
return \array_merge($this->convertDependencyTreeIntoDefinitionList($dependencyTree), $manuallyDefinedDependencies);
$value = \array_merge($this->convertDependencyTreeIntoDefinitionList($dependencyTree), $manuallyDefinedDependencies);
\set_transient("{$this->namespace}_autowiring_cache", $value);
return $value;
}

// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
Expand Down

0 comments on commit df27181

Please sign in to comment.