generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
- Loading branch information
Showing
39 changed files
with
848 additions
and
222 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Yii Hydrator | ||
|
||
The package provides a way to create and hydrate objects from a set of raw data. | ||
|
||
- [General usage](general-usage.md) | ||
- [Type casting](typecasting.md) | ||
- [Mapping](mapping.md) | ||
- [Creating own attributes](creating-own-attributes.md) | ||
- [Attribute resolver factory](attribute-resolver-factory.md) | ||
- [Object factory](object-factory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Attribute resolver factory | ||
|
||
The hydrator uses `AttributeResolverFactoryInterface` implementation to create attribute resolvers. | ||
The package provides two implementations out of the box: | ||
|
||
- `ReflectionAttributeResolverFactory`. Uses reflection to create attribute resolver, and can create attribute resolvers | ||
without dependencies only. | ||
- `ContainerAttributeResolverFactory`. Uses [PSR-11](https://www.php-fig.org/psr/psr-11/) compatible DI container | ||
to create attribute resolver. | ||
|
||
Default factory used depends on the environment. When using hydrator package within the Yii ecosystem (an application | ||
uses [Yii Config](https://github.com/yiisoft/config)), default is `ContainerAttributeResolverFactory`. Otherwise, | ||
it is `ReflectionAttributeResolverFactory`. | ||
|
||
## Using attribute resolver factory | ||
|
||
To use non-default attribute resolver factory, pass it to the hydrator constructor: | ||
|
||
```php | ||
use Yiisoft\Hydrator\AttributeHandling\ResolverFactory\ContainerAttributeResolverFactory; | ||
|
||
/** | ||
* @var Psr\Container\ContainerInterface $container | ||
*/ | ||
$attributeResolverFactory = new ContainerAttributeResolverFactory($container); | ||
|
||
$hydrator = new Hydrator( | ||
attributeResolverFactory: $attributeResolverFactory, | ||
// ... | ||
); | ||
``` |
Oops, something went wrong.