-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from cekta/KeyValue-stringToAlias
KeyValue stringToAlias
- Loading branch information
Showing
11 changed files
with
80 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
#### KeyValue stringToAlias. | ||
|
||
В некоторых случаях людям хочется вынести список все используемых интерфейсов и их реализаций в отдельный файлик, | ||
|
||
Для реализаций этих потребностей есть специальный метод хелпер. | ||
|
||
```php | ||
<?php | ||
use Cekta\DI\Container; | ||
use Cekta\DI\Provider\KeyValue; | ||
use Psr\Container\ContainerInterface; | ||
|
||
interface SomeInterface{} | ||
|
||
class SomeImplementation implements SomeInterface{} | ||
|
||
$providers[] = KeyValue::closureToService([ | ||
SomeInterface::class => SomeImplementation::class, | ||
'example' => 123 | ||
]); | ||
$container = new Container(...$providers); | ||
assert($container->get(SomeInterface::class) instanceof SomeImplementation); | ||
assert($container->get('example') === 123); | ||
``` | ||
|
||
Во втором провайдере любая строка становится Alias, остальные значения не изменяются. | ||
|
||
--- | ||
* [KeyValue](key-value.md) | ||
* [Environment](environment.md) | ||
* [JSON](json.md) | ||
* [PHP](PHP.md) | ||
* [Custom format](custom-format.md) | ||
* [LoaderInterface](loader-interface.md) | ||
* [ClosureToService](closureToService.md) | ||
--- | ||
[Вернуться на главную](../../readme.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters