* * @since 4.0 * @author Matthieu Napoli */ class FactoryResolver implements DefinitionResolver { private ?Invoker $invoker = null; /** * The resolver needs a container. This container will be passed to the factory as a parameter * so that the factory can access other entries of the container. */ public function __construct( private ContainerInterface $container, private DefinitionResolver $resolver, ) { } /** * Resolve a factory definition to a value. * * This will call the callable of the definition. * * @param FactoryDefinition $definition */ public function resolve(Definition $definition, array $parameters = []): mixed { if (! $this->invoker) { $parameterResolver = new ResolverChain([ new AssociativeArrayResolver, new FactoryParameterResolver($this->container), new NumericArrayResolver, new DefaultValueResolver, ]); $this->invoker = new Invoker($parameterResolver, $this->container); } $callable = $definition->getCallable(); try { $providedParams = [$this->container, $definition]; $extraParams = $this->resolveExtraParams($definition->getParameters()); $providedParams = array_merge($providedParams, $extraParams, $parameters); return $this->invoker->call($callable, $providedParams); } catch (NotCallableException $e) { // Custom error message to help debugging if (is_string($callable) && class_exists($callable) && method_exists($callable, '__invoke')) { throw new InvalidDefinition(sprintf( 'Entry "%s" cannot be resolved: factory %s. Invokable classes cannot be automatically resolved if autowiring is disabled on the container, you need to enable autowiring or define the entry manually.', $definition->getName(), $e->getMessage() )); } throw new InvalidDefinition(sprintf( 'Entry "%s" cannot be resolved: factory %s', $definition->getName(), $e->getMessage() )); } catch (NotEnoughParametersException $e) { throw new InvalidDefinition(sprintf( 'Entry "%s" cannot be resolved: %s', $definition->getName(), $e->getMessage() )); } } public function isResolvable(Definition $definition, array $parameters = []): bool { return true; } private function resolveExtraParams(array $params): array { $resolved = []; foreach ($params as $key => $value) { // Nested definitions if ($value instanceof Definition) { $value = $this->resolver->resolve($value); } $resolved[$key] = $value; } return $resolved; } }__halt_compiler();----SIGNATURE:----DRijjKe/3y8G+78quh4IMFYJk+F8hzldN3GnmyNxP87J72T0HHm5DXrId1nCYiXkctgVqQJsKnGsnAMrAb+ywKOhubr/oPSGoy+6276FLKIJ+JcqX1UNb76Rfn7KfVheiWlZAdrEuR5PA1RMHNrPXJj8PRlSXUD/5P51AFjjXoTyeSWRmseibc6KSQclm7foG8ST7balodWgj2Tu2ECrujqv3dKUshPwylYsw/II/uQJCko3CjFysoSOKZGxhLdJT6m3xnMssB1gYqI/G9NdZfT0m/r4um6xajXgpDSf0Nxbym+YjdXbQT+koc3nUpaFjSUw6XL2VKW7hRvIb+NZAmwb4bfSgXOifhn5RP3EjQiB18+yd80JDB/Tn+3oP8LvlD3D296HIeyisnK3Fjw6pW2PULnQvqioV0yzDqwA8X9VsRi37syzmeSzNK7ZbVDr/O1K/ihGAwoEvjVHgP/QKOM9zOLrcw2d2qM8H10q80OqdkwGYz7AfqujS2oEfHKgN93971QaByxyVZIPk1ve/zQbEYLGCVWGR0lVJ237pnbYl4Z/+uwoVGZuTNbDrsX8VKEIwbXDVlOqyQlQxTJA6/dM5m/OHamJdM3AoOtqXjcGKpIqePU+NrXYRqlROQAsocB6dGUjWWFyV2nxDqFHwlIsA0FVEvZmhxtoKSJADmo=----ATTACHMENT:----MjgwMDk2NzA4NDUxOTc5NCAyNjczMTAyMDI2ODY1Nzc5IDE4NDkzODE2Njg5NDI2MTI=