Business API invocation service¶
This service is the access point to the Business API and defined by a service with the ID ses_eshop.business_api.invocation
.
Because this service acts only as a proxy, the business logic itself is handled by different operation services.
Calling Business API operation service¶
To call Business API operation service, use the call()
method of the Business API invocation service.
method | parameters | returns |
---|---|---|
call() | string $operationIdentifier ValueObject $operationInput |
ValueObject $operationOutput |
Creating $operationIdentifier¶
The identifier of the Business API operation service consists of two parts separated by a dot.
- The first part is the alias of the operation service that can be found in the configuration:
services.business_layer.xml
. - The second part is the operation method that should be invoked.
The method name must be lowercase, separated by underscore instead of the method's camelCase notation (
get_basket
=>getBasket()
).
For examples:
1 2 3 |
|
Example¶
The following example shows how to use the Business API basket operation service.
1 2 3 4 5 6 7 8 |
|
Implementing a Business API operation¶
To extend the Business API, you need to create a new service class.
The operations of that class contain the business logic respectively and are stored in EshopBundle/Services/BusinessLayer/Operations/*
.
Each operation, e.g. basket, is a service which must be tagged in the following way:
1 2 3 4 |
|
Note
The tag name
must always be business_api_operation
.
The attribute alias
defines the first part in the operation identifier.
Derive your new service from the common parent class BaseOperation
to get access to commonly needed dependencies (e.g. logging and translations).
Overriding an existing Business API class¶
If you want to override a particular API service you need to create a new service class, which extends the original. Within that class you can override individual methods or add new methods. Then you need to redefine the service in the Symfony configuration with the new class and the same tag values (name and alias).
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
There are two ways to redefine the service configuration:
If the original service is defined with a configuration parameter (%
notation) in its class attribute,
you need to redefine that parameter with a fully-qualified class name.
1 2 |
|
The other option is to completely redefine the original service with a new fully-qualified class name.
1 2 3 4 |
|