Skip to content

Commit 036d924

Browse files
adriendupuisdabrt
andauthored
Rework PHP API intro (#2386)
--------- Co-authored-by: Tomasz Dąbrowski <[email protected]>
1 parent 91cb570 commit 036d924

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

docs/api/php_api/php_api.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ Using the API ensures that your code will be forward compatible with future rele
1515

1616
## Using API services
1717

18-
You can access the PHP API by injecting relevant services into your code.
19-
2018
The API provides access to Content, User, content types and other features through various services.
21-
Those services are obtained using `get[ServiceName]()` methods: `getContentService()`, `getUserService()`, etc.
2219

2320
The full list of available services covers:
2421

@@ -48,21 +45,31 @@ The full list of available services covers:
4845
- [UserPreferenceService](https://github.com/ibexa/core/blob/main/src/contracts/Repository/UserPreferenceService.php)
4946
- [UserService](https://github.com/ibexa/core/blob/main/src/contracts/Repository/UserService.php)
5047

48+
You can access the PHP API by injecting relevant services into your code:
49+
50+
- By using [auto-wiring]([[=symfony_doc=]]/service_container/autowiring.html), and the service classname in the `Ibexa\Contracts` namespace (see `bin/console debug:autowiring | grep Ibexa.Contracts`).
51+
- By using [service parameters]([[=symfony_doc=]]/service_container.html#service-parameters), and service aliases (see `bin/console debug:autowiring | grep ibexa.api`).
52+
- By using the Repository's `get[ServiceName]()` methods: [`Repository::getContentService()`](https://github.com/ibexa/core/blob/v4.6.6/src/contracts/Repository/Repository.php#L46), [`getUserService()`](https://github.com/ibexa/core/blob/v4.6.6/src/contracts/Repository/Repository.php#L111), etc.
53+
(Prefer injecting several Repository's dedicated services instead of the whole Repository if the Repository itself is not needed.)
54+
55+
!!! caution
56+
57+
The PHP API's services can be accessed with `Ibexa\Bundle\Core\Controller::getRepository()` by extending it from a [custom controller](controllers.md), but such approach is not recommended, and you should prefer dependency injection.
5158
## Value objects
5259

53-
The services provide interaction with read-only value objects from the `Ibexa\Contracts\Core\Repository\Values` namespace.
54-
Those objects are divided into sub-namespaces, such as `Content`, `User` or `ObjectState`.
60+
The services provide interaction with read-only value objects from the [`Ibexa\Contracts\Core\Repository\Values`](https://github.com/ibexa/core/tree/v4.6.6/src/contracts/Repository/Values) namespace.
61+
Those objects are divided into sub-namespaces, such as [`Content`](https://github.com/ibexa/core/tree/v4.6.6/src/contracts/Repository/Values/Content), [`User`](https://github.com/ibexa/core/tree/v4.6.6/src/contracts/Repository/Values/User) or [`ObjectState`](https://github.com/ibexa/core/tree/v4.6.6/src/contracts/Repository/Values/ObjectState).
5562
Each sub-namespace contains a set of value objects,
5663
such as [`Content\Content`](https://github.com/ibexa/core/blob/main/src/contracts/Repository/Values/Content/Content.php) or [`User\Role`](https://github.com/ibexa/core/blob/main/src/contracts/Repository/Values/User/Role.php).
5764

5865
Value objects come with their own properties, such as `$content->id` or `$location->hidden`,
5966
as well as with methods that provide access to more related information,
60-
such as `Relation::getSourceContentInfo()` or `Role::getPolicies()`.
67+
such as [`Content\Relation::getSourceContentInfo()`](https://github.com/ibexa/core/blob/v4.6.6/src/contracts/Repository/Values/Content/Relation.php#L80) or [`User\Role::getPolicies()`](https://github.com/ibexa/core/blob/v4.6.6/src/contracts/Repository/Values/User/Role.php#L60).
6168

6269
### Creating and updating objects
6370

6471
Value objects fetch data from the Repository and are read-only.
65-
To create and modify Repository values you need to use structs, such as `getContentCreateStruct()` or `getContentUpdateStruct()`.
72+
To create and modify Repository values, use data structures, such as [`ContentService::newContentCreateStruct()`](https://github.com/ibexa/core/blob/v4.6.6/src/contracts/Repository/ContentService.php#L572) or [`LocationService::newLocationUpdateStruct()`](https://github.com/ibexa/core/blob/v4.6.6/src/contracts/Repository/LocationService.php#L238).
6673

6774
### Value info objects
6875

0 commit comments

Comments
 (0)