API Platform Flashcards

1
Q

Data Providers

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Data Providers - two kinds of interface

A

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’]);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Custom Collection Data Provider

A
  1. implements CollectionDataProviderInterface

2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Custom Item Data Provider

A

implementing the ItemDataProviderInterface interface:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Extensions

A

API Platform Core provides a system to extend queries on items and collections.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Custom Doctrine ORM Extension

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Data Providers
purpose pjenh data from Doctrine -> khang krav
tver ban, trov mean

A
  • 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’]);
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly