|
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\plan; |
|
12
|
|
|
|
|
13
|
|
|
use hiqdev\php\billing\customer\Customer; |
|
14
|
|
|
use hiqdev\php\billing\plan\Plan; |
|
15
|
|
|
use hiqdev\php\billing\price\PriceInterface; |
|
16
|
|
|
use hiqdev\yii\DataMapper\hydrator\GeneratedHydrator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class PlanHydrator. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Andrii Vasyliev <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class PlanHydrator extends GeneratedHydrator |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
* @param object|Plan $object |
|
28
|
|
|
* @throws \Exception |
|
29
|
|
|
*/ |
|
30
|
|
|
public function hydrate(array $data, $object) |
|
31
|
|
|
{ |
|
32
|
|
|
$data['seller'] = $this->hydrator->hydrate($data['seller'], Customer::class); |
|
33
|
|
|
$raw_prices = $data['prices']; |
|
34
|
|
|
unset($data['prices']); |
|
35
|
|
|
|
|
36
|
|
|
/** @var Plan $plan */ |
|
37
|
|
|
$plan = parent::hydrate($data, $object); |
|
38
|
|
|
|
|
39
|
|
|
if (is_array($raw_prices)) { |
|
40
|
|
|
$prices = []; |
|
41
|
|
|
foreach ($raw_prices as $key => $price) { |
|
42
|
|
|
if ($price instanceof PriceInterface) { |
|
43
|
|
|
$price->setPlan($plan); |
|
|
|
|
|
|
44
|
|
|
$prices[$key] = $price; |
|
45
|
|
|
} else { |
|
46
|
|
|
$price['plan'] = $plan; |
|
47
|
|
|
$prices[$key] = $this->hydrator->hydrate($price, PriceInterface::class); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
$plan->setPrices($prices); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $plan; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
* @param Plan $object |
|
59
|
|
|
*/ |
|
60
|
|
|
public function extract($object) |
|
61
|
|
|
{ |
|
62
|
|
|
$result = array_filter([ |
|
63
|
|
|
'id' => $object->getId(), |
|
64
|
|
|
'name' => $object->getName(), |
|
|
|
|
|
|
65
|
|
|
'seller' => $object->getSeller() ? $this->hydrator->extract($object->getSeller()) : null, |
|
66
|
|
|
'parent' => $object->getParent() ? $this->hydrator->extract($object->getParent()) : null, |
|
|
|
|
|
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
return $result; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.