1 | <?php |
||
20 | abstract class Base extends \Aimeos\Controller\Frontend\Common\Decorator\Base |
||
21 | { |
||
22 | /** |
||
23 | * Returns the service items that are available for the service type and the content of the basket. |
||
24 | * |
||
25 | * @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
||
26 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket of the user |
||
27 | * @param array $ref List of domains for which the items referenced by the services should be fetched too |
||
28 | * @return array List of service items implementing \Aimeos\MShop\Service\Item\Iface with referenced items |
||
29 | */ |
||
30 | public function getServices( $type, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Returns the list of attribute definitions which must be used to render the input form where the customer can |
||
39 | * enter or chose the required data necessary by the service provider. |
||
40 | * |
||
41 | * @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
||
42 | * @param string $serviceId Identifier of one of the service option returned by getService() |
||
43 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
||
44 | * @return array List of attribute definitions implementing \Aimeos\MW\Criteria\Attribute\Iface |
||
45 | */ |
||
46 | public function getServiceAttributes( $type, $serviceId, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
||
50 | |||
51 | |||
52 | /** |
||
53 | * Returns the price of the service. |
||
54 | * |
||
55 | * @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
||
56 | * @param string $serviceId Identifier of one of the service option returned by getService() |
||
57 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket with products |
||
58 | * @return \Aimeos\MShop\Price\Item\Iface Price item |
||
59 | * @throws \Aimeos\Controller\Frontend\Service\Exception If no active service provider for this ID is available |
||
60 | * @throws \Aimeos\MShop\Exception If service provider isn't available |
||
61 | * @throws \Exception If an error occurs |
||
62 | */ |
||
63 | public function getServicePrice( $type, $serviceId, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
||
67 | |||
68 | |||
69 | /** |
||
70 | * Returns a list of attributes that are invalid. |
||
71 | * |
||
72 | * @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
||
73 | * @param string $serviceId Identifier of the service option chosen by the customer |
||
74 | * @param array $attributes List of key/value pairs with name of the attribute from attribute definition object as |
||
75 | * key and the string entered by the customer as value |
||
76 | * @return array List of key/value pairs of attributes keys and an error message for values that are invalid or |
||
77 | * missing |
||
78 | */ |
||
79 | public function checkServiceAttributes( $type, $serviceId, array $attributes ) |
||
83 | } |
||
84 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: