1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* API for Billing |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/billing-hiapi |
6
|
|
|
* @package billing-hiapi |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\billing\hiapi\action; |
12
|
|
|
|
13
|
|
|
use DateTimeImmutable; |
14
|
|
|
use hiqdev\php\billing\customer\Customer; |
15
|
|
|
use hiqdev\php\billing\action\Action; |
16
|
|
|
use hiqdev\php\billing\type\Type; |
17
|
|
|
use hiqdev\php\billing\target\Target; |
18
|
|
|
use hiqdev\php\units\Quantity; |
19
|
|
|
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Action Hydrator. |
23
|
|
|
* |
24
|
|
|
* @author Andrii Vasyliev <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ActionHydrator extends GeneratedHydrator |
27
|
|
|
{ |
28
|
|
|
/** {@inheritdoc} */ |
29
|
|
|
public function hydrate(array $data, $object) |
30
|
|
|
{ |
31
|
|
|
$data['type'] = $this->hydrator->hydrate($data['type'], Type::class); |
32
|
|
|
$data['target'] = $this->hydrator->hydrate($data['target'], Target::class); |
33
|
|
|
$data['quantity'] = $this->hydrator->hydrate($data['quantity'], Quantity::class); |
34
|
|
|
$data['customer'] = $this->hydrator->hydrate($data['customer'], Customer::class); |
35
|
|
|
$data['time'] = $this->hydrator->hydrate([$data['time']], DateTimeImmutable::class); |
36
|
|
|
if (isset($data['sale'])) { |
37
|
|
|
$data['sale'] = $this->hydrator->hydrate($data['sale'], Sale::class); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
if (isset($data['parent'])) { |
40
|
|
|
$data['parent'] = $this->hydrator->hydrate($data['parent'], Action::class); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return parent::hydrate($data, $object); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
* @param object|Action $object |
49
|
|
|
*/ |
50
|
|
|
public function extract($object) |
51
|
|
|
{ |
52
|
|
|
$result = array_filter([ |
53
|
|
|
'id' => $object->getId(), |
54
|
|
|
'type' => $this->hydrator->extract($object->getType()), |
55
|
|
|
'target' => $this->hydrator->extract($object->getTarget()), |
56
|
|
|
'quantity' => $this->hydrator->extract($object->getQuantity()), |
57
|
|
|
'customer' => $this->hydrator->extract($object->getCustomer()), |
58
|
|
|
'time' => $this->hydrator->extract($object->getTime()), |
59
|
|
|
'sale' => $object->getSale() ? $this->hydrator->extract($object->getSale()) : null, |
60
|
|
|
'parent' => $object->getParent() ? $this->hydrator->extract($object->getParent()) : null, |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
return $result; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: