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

Lazy services #232

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a0fdad8
Decorate definition when it contains lazy
xepozz Aug 1, 2021
61f2bff
Add tests
xepozz Aug 1, 2021
1b4cfae
Normalize definition out of the building process
xepozz Aug 1, 2021
abb2e83
Rework test cases
xepozz Aug 1, 2021
15f8a66
Add class resolver
xepozz Aug 1, 2021
dbed5b3
Apply fixes from StyleCI
samdark Aug 1, 2021
4bdd4bc
Merge branch 'master' into lazy-services
xepozz Aug 7, 2021
592c239
Fix tests
xepozz Aug 7, 2021
e4bd46f
Apply fixes from StyleCI
samdark Aug 7, 2021
2f8c8b5
Merge branch 'master' into lazy-services
xepozz Aug 10, 2021
8212a39
Merge branch 'master' into lazy-services
xepozz Nov 20, 2022
5136d8d
[ci-review] Apply changes from Rector action.
Nov 20, 2022
47dc088
Fix resolving lazy service
xepozz Nov 20, 2022
40ad592
Merge remote-tracking branch 'origin/lazy-services' into lazy-services
xepozz Nov 20, 2022
125231d
Merge branch 'master' into lazy-services
xepozz Dec 2, 2022
51789d0
Merge branch 'master' into lazy-services
xepozz Dec 3, 2022
1d59fbd
Use `friendsofphp/proxy-manager-lts` package
xepozz Dec 3, 2022
95cdd9e
Fix psalm
xepozz Dec 3, 2022
0b0b784
Rework lazy definition
xepozz Dec 3, 2022
20db77b
Merge branch 'master' into lazy-services
xepozz Jul 29, 2023
d1b0c55
Apply Rector changes (CI)
xepozz Jul 29, 2023
feff3b7
Apply fixes from StyleCI
StyleCIBot Jul 29, 2023
5bf1e81
Fix annotation
xepozz Aug 1, 2023
1d04fbc
Add new test case
xepozz Aug 1, 2023
bc7f70e
Fix psalm
xepozz Aug 1, 2023
fedff5e
Merge branch 'master' into lazy-services
xepozz Mar 3, 2024
51fefa2
Suggestion for lazy service (#355)
vjik Apr 16, 2024
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
Prev Previous commit
Next Next commit
Fix psalm
  • Loading branch information
xepozz committed Aug 1, 2023
commit bc7f70e9f5a68fae0712ad15846a16255fc99aff
6 changes: 5 additions & 1 deletion src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Psr\Container\NotFoundExceptionInterface;
use Throwable;
use Yiisoft\Definitions\ArrayDefinition;
use Yiisoft\Definitions\DefinitionStorage;
use Yiisoft\Definitions\Contract\DefinitionInterface;
use Yiisoft\Definitions\DefinitionStorage;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
Expand Down Expand Up @@ -282,7 +282,7 @@

$this->delegates->attach($delegate);
}
$this->definitions->setDelegateContainer($this->delegates);

Check warning on line 285 in src/Container.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ } $this->delegates->attach($delegate); } - $this->definitions->setDelegateContainer($this->delegates); + } /** * @param mixed $definition Definition to validate.

Check warning on line 285 in src/Container.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ } $this->delegates->attach($delegate); } - $this->definitions->setDelegateContainer($this->delegates); + } /** * @param mixed $definition Definition to validate.
}

/**
Expand All @@ -309,7 +309,7 @@

$definition = array_merge(
$class === null ? [] : [ArrayDefinition::CLASS_NAME => $class],
[ArrayDefinition::CONSTRUCTOR => $constructorArguments],

Check warning on line 312 in src/Container.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $methodsAndProperties = $definition['methodsAndProperties']; $definition = array_merge( $class === null ? [] : [ArrayDefinition::CLASS_NAME => $class], - [ArrayDefinition::CONSTRUCTOR => $constructorArguments], + [], // extract only value from parsed definition method array_map(fn(array $data): mixed => $data[2], $methodsAndProperties) );

Check warning on line 312 in src/Container.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $methodsAndProperties = $definition['methodsAndProperties']; $definition = array_merge( $class === null ? [] : [ArrayDefinition::CLASS_NAME => $class], - [ArrayDefinition::CONSTRUCTOR => $constructorArguments], + [], // extract only value from parsed definition method array_map(fn(array $data): mixed => $data[2], $methodsAndProperties) );
// extract only value from parsed definition method
array_map(fn (array $data): mixed => $data[2], $methodsAndProperties),
);
Expand Down Expand Up @@ -495,7 +495,7 @@
);
}

$this->building[$id] = 1;

Check warning on line 498 in src/Container.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ } throw new CircularReferenceException(sprintf('Circular reference to "%s" detected while building: %s.', $id, implode(', ', array_keys($this->building)))); } - $this->building[$id] = 1; + $this->building[$id] = 2; try { /** @var mixed $object */ $object = $this->buildInternal($id);

Check warning on line 498 in src/Container.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ } throw new CircularReferenceException(sprintf('Circular reference to "%s" detected while building: %s.', $id, implode(', ', array_keys($this->building)))); } - $this->building[$id] = 1; + $this->building[$id] = 2; try { /** @var mixed $object */ $object = $this->buildInternal($id);
try {
/** @var mixed $object */
$object = $this->buildInternal($id);
Expand Down Expand Up @@ -635,15 +635,19 @@
} elseif (is_array($definition) && array_key_exists(ArrayDefinition::CLASS_NAME, $definition)) {
$class = (string) $definition[ArrayDefinition::CLASS_NAME];
} else {
throw new InvalidConfigException(
sprintf(
'Invalid definition: lazy services are only available with array definitions or references. Got type "%s" for definition ID: "%s"',
get_debug_type($definition),
$id,
)
);

Check warning on line 644 in src/Container.php

View check run for this annotation

Codecov / codecov/patch

src/Container.php#L638-L644

Added lines #L638 - L644 were not covered by tests
}

/**
* @var class-string $class
*/

return new LazyDefinition($definition, $class);
}
}
Loading