|
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\charge; |
|
12
|
|
|
|
|
13
|
|
|
use hiqdev\php\billing\action\Action; |
|
14
|
|
|
use hiqdev\php\billing\charge\Charge; |
|
15
|
|
|
use hiqdev\php\billing\bill\Bill; |
|
16
|
|
|
use hiqdev\php\billing\price\PriceInterface; |
|
17
|
|
|
use hiqdev\php\units\Quantity; |
|
18
|
|
|
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator; |
|
19
|
|
|
use Money\Money; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Charge Hydrator. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class ChargeHydrator extends GeneratedHydrator |
|
27
|
|
|
{ |
|
28
|
|
|
/** {@inheritdoc} */ |
|
29
|
|
|
public function hydrate(array $data, $object) |
|
30
|
|
|
{ |
|
31
|
|
|
$data['action'] = $this->hydrator->hydrate($data['action'], Action::class); |
|
32
|
|
|
$data['price'] = $this->hydrator->hydrate($data['price'], PriceInterface::class); |
|
33
|
|
|
$data['usage'] = $this->hydrator->hydrate($data['usage'], Quantity::class); |
|
34
|
|
|
$data['sum'] = $this->hydrator->hydrate($data['sum'], Money::class); |
|
35
|
|
|
if (isset($data['bill'])) { |
|
36
|
|
|
$data['bill'] = $this->hydrator->hydrate($data['bill'], Bill::class); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return parent::hydrate($data, $object); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
* @param object|Charge $object |
|
45
|
|
|
*/ |
|
46
|
|
|
public function extract($object) |
|
47
|
|
|
{ |
|
48
|
|
|
$result = array_filter([ |
|
49
|
|
|
'id' => $object->getId(), |
|
50
|
|
|
'action' => $this->hydrator->extract($object->getAction()), |
|
51
|
|
|
'price' => $this->hydrator->extract($object->getPrice()), |
|
52
|
|
|
'usage' => $this->hydrator->extract($object->getUsage()), |
|
53
|
|
|
'sum' => $this->hydrator->extract($object->getSum()), |
|
54
|
|
|
'bill' => $object->getBill() ? $this->hydrator->extract($object->getBill()) : null, |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
return $result; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
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: