API Platform Flashcards
Data Providers
To retrieve data exposed by the API, API Platform uses classes called data providers. A data provider using Doctrine ORM to retrieve data from a database, a data provider using Doctrine MongoDB ODM to retrieve data from a document database, and a data provider using Elasticsearch-PHP to retrieve data from an Elasticsearch cluster are included with the library. The first one is enabled by default. These data providers natively support paged collections and filters.
Data Providers - two kinds of interface
For a given resource, you can implement two kinds of interface:
- the CollectionDataProviderInterface is used when fetching a collection.
- the ItemDataProviderInterface is used when fetching items.
Both implementations can also implement a third, optional, interface called ‘RestrictedDataProviderInterface’ if you want to limit their effects to a single resource or operation.
then yok them tov prer in controller’s construct to invoke method. Example:
public function __invoke($id, $invoiceNumber) {
return $this->contractInvoiceDataProvider->getItem(AccountsReceivableInvoice::class, [$id, $invoiceNumber], ‘GET’, [‘accounts_receivable_invoice_attachment_read’]);
}
Custom Collection Data Provider
- implements CollectionDataProviderInterface
2.
Custom Item Data Provider
implementing the ItemDataProviderInterface interface:
Extensions
API Platform Core provides a system to extend queries on items and collections.
Custom Doctrine ORM Extension
Custom extensions must implement the ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface and / or the ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface interfaces, to be run when querying for a collection of items and when querying for an item respectively. If you use custom data providers, they must support extensions and be aware of active extensions to work properly.
Data Providers
purpose pjenh data from Doctrine -> khang krav
tver ban, trov mean
- entity
- Class data provider implements interface CollectionDataProviderInterface or ItemDataProviderInterface and/or ‘RestrictedDataProviderInterface’
- Then yok tov dak knong controllers
- Oy invoke method
public function __invoke($id)
{
return $this->arInvoiceDataProvider->getItem(AccountsReceivableInvoice::class, $id, ‘GET’, [‘accounts_receivable_invoice_read’]);
}