Skip to content

Commit

Permalink
Reformat provider documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-goncalves-kununu committed Jan 8, 2024
1 parent 97c5f6d commit e42e987
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions docs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ final class MyCachedProvider extends AbstractCachedProvider implements MyProvide
{
return $this->getAndCacheData(
new CustomerByIdProjectionItem($customerId),
// This callable will get the data when there is a cache miss (e.g. data was not found on the cache)
// This callable will get the data when there is a cache miss
// (e.g. data was not found on the cache)
fn(): ?iterable => $this->myProvider->getCustomerData($customerId),
// Additional callables to do pre-processing before projecting the items to the cache. They are optional
// and only called in the event of a cache miss (and after the data getter callable returns the data)
// Additional callables to do pre-processing before projecting the
// items to the cache. They are optional and only called in the event of
// a cache miss (and after the data getter callable returns the data)
function(ProjectionItemIterableInterface $item, iterable $data): ?iterable {
// A case where I don't want to store the projection because it does not have
// relevant information
// A case where I don't want to store the projection
// because it does not have relevant information
if($data['customer_id'] > 200) {
return null;
}

// We could also add more info here...
// E.g.: we fetch some data from database, but we need to call some external API to get additional data
// E.g.: we fetch some data from database, but we need
// to call some external API to get additional data.
// This is a perfect place to do that
$data['new_value'] = 500;

Expand Down Expand Up @@ -162,8 +165,8 @@ public static function getCustomerDataDataProvider(): array
// before projecting the item to the cache.
//
// To test this cases you can change the item as you expect it before doing the projection
// The $item received here is a clone of the $item defined above and if $providerData is iterable it is already
// injected in the item via the storeData method
// The $item received here is a clone of the $item defined above and if $providerData is iterable it
// is already injected in the item via the storeData method
function($itemToProject) {
// Do something to the item before adding it to the cache
// E.g. set a property on the item that usually is set on the pre-projection callables of the
Expand Down

0 comments on commit e42e987

Please sign in to comment.