Skip to content

Commit

Permalink
Document reference arrays in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Sep 29, 2021
1 parent 50937f0 commit 9501502
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -173,6 +173,30 @@ The `DynamicReference` defines a dependency to a service not defined in the cont
]
```

In order to pass an array of IDs as references to a property or an argument, `Yiisoft\Definitions\ReferencesArray` or
`Yiisoft\Definitions\DynamicReferencesArray` could be used:

```php
//params.php
return [
'yiisoft/data-response' => [
'contentFormatters' => [
'text/html' => HtmlDataResponseFormatter::class,
'application/xml' => XmlDataResponseFormatter::class,
'application/json' => JsonDataResponseFormatter::class,
],
],
];

//web.php

ContentNegotiator::class => [
'__construct()' => [
'contentFormatters' => ReferencesArray::from($params['yiisoft/data-response']['contentFormatters']),
],
],
```

## Testing

### Unit testing
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicReferencesArray.php
Expand Up @@ -35,7 +35,7 @@ final class DynamicReferencesArray
* ],
* ```
*
* That is not very convenient so we can define formatters in a separate config and without explicitly using
* That is not very convenient, so we can define formatters in a separate config and without explicitly using
* `DynamicReference::to()` for each formatter:
*
* ```php
Expand Down
2 changes: 1 addition & 1 deletion src/ReferencesArray.php
Expand Up @@ -34,7 +34,7 @@ final class ReferencesArray
* ],
* ],
* ```
* That is not very convenient so we can define formatters in a separate config and without explicitly using
* That is not very convenient, so we can define formatters in a separate config and without explicitly using
* `Reference::to()` for each formatter:
*
* ```php
Expand Down

0 comments on commit 9501502

Please sign in to comment.