Skip to content
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

Suggestion for lazy definition #88

Merged
merged 1 commit into from
Apr 16, 2024
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
8 changes: 2 additions & 6 deletions src/ArrayDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ public function withReferenceContainer(?ContainerInterface $referenceContainer):
}

/**
* Create ArrayDefinition from array config.
* Create `ArrayDefinition` from array config.
*
* @psalm-param ArrayDefinitionConfig $config
*/
public static function fromConfig(array $config): self
{
/**
* @psalm-suppress MixedArgument
*/
return new self(
$config[self::CLASS_NAME],
$config[self::CONSTRUCTOR] ?? [],
// Already normalized config. Ignore all the rest parameters
$config['methodsAndProperties'] ?? self::getMethodsAndPropertiesFromConfig($config),
self::getMethodsAndPropertiesFromConfig($config),
);
}

Expand Down
13 changes: 3 additions & 10 deletions src/LazyDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
{
/** @var LazyLoadingValueHolderFactory $factory */
$factory = $container->get(LazyLoadingValueHolderFactory::class);
/**
* @var mixed $definition
*/
$definition = $this->definition;
$class = $this->class;

return $factory->createProxy(
$class,
static function (mixed &$wrappedObject) use ($container, $class, $definition) {
$definition = Normalizer::normalize($definition, $class);
/**
* @var mixed $wrappedObject
*/
$this->class,
static function (mixed &$wrappedObject) use ($container, $definition) {
$definition = Normalizer::normalize($definition);

Check warning on line 33 in src/LazyDefinition.php

View check run for this annotation

Codecov / codecov/patch

src/LazyDefinition.php#L33

Added line #L33 was not covered by tests
$wrappedObject = $definition->resolve($container);
return true;
}
Expand Down
Loading