|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright Iain Cambridge 2020-2023. |
|
7
|
|
|
* |
|
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
|
9
|
|
|
* |
|
10
|
|
|
* Change Date: TBD ( 3 years after 2.2.0 release ) |
|
11
|
|
|
* |
|
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Parthenon\Billing\Plan; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use Parthenon\Billing\Entity\SubscriptionPlan; |
|
19
|
|
|
use Parthenon\Billing\Entity\SubscriptionPlanLimit; |
|
20
|
|
|
use Parthenon\Billing\Repository\SubscriptionPlanRepositoryInterface; |
|
21
|
|
|
|
|
22
|
|
|
class DatabasePlanManager implements PlanManagerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function __construct(private SubscriptionPlanRepositoryInterface $subscriptionPlanRepository) |
|
25
|
|
|
{ |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getPlans(): array |
|
29
|
|
|
{ |
|
30
|
|
|
$planEntities = $this->subscriptionPlanRepository->getAll(); |
|
31
|
|
|
|
|
32
|
|
|
$output = []; |
|
33
|
|
|
foreach ($planEntities as $planEntity) { |
|
34
|
|
|
$output[] = $this->convertPlan($planEntity); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return $output; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getPlanForUser(LimitedUserInterface $limitedUser): Plan |
|
41
|
|
|
{ |
|
42
|
|
|
// TODO: Implement getPlanForUser() method. |
|
43
|
|
|
} |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function getPlanByName(string $planName): Plan |
|
46
|
|
|
{ |
|
47
|
|
|
// TODO: Implement getPlanByName() method. |
|
48
|
|
|
} |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
protected function convertPlan(SubscriptionPlan $subscriptionPlan): Plan |
|
51
|
|
|
{ |
|
52
|
|
|
$plan = new Plan( |
|
53
|
|
|
$subscriptionPlan->getName(), |
|
54
|
|
|
$this->convertLimits($subscriptionPlan->getLimits()), |
|
55
|
|
|
$this->convertFeatures(), |
|
56
|
|
|
$this->convertPrices(), |
|
57
|
|
|
$subscriptionPlan->isFree(), |
|
58
|
|
|
$subscriptionPlan->isPerSeat(), |
|
59
|
|
|
$subscriptionPlan->getUserCount(), |
|
60
|
|
|
$subscriptionPlan->isPublic(), |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
return $plan; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param SubscriptionPlanLimit[] $limits |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function convertLimits(array|Collection $limits): array |
|
70
|
|
|
{ |
|
71
|
|
|
$output = []; |
|
72
|
|
|
|
|
73
|
|
|
foreach ($limits as $limit) { |
|
74
|
|
|
$output[$limit->getSubscriptionLimit()->getCode()] = [ |
|
75
|
|
|
'name' => $limit->getSubscriptionLimit()->getName(), |
|
76
|
|
|
'code' => $limit->getSubscriptionLimit()->getCode(), |
|
77
|
|
|
'limit' => $limit->getLimit(), |
|
78
|
|
|
'description' => $limit->getSubscriptionLimit()->getDescription(), |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $output; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
protected function convertFeatures(): array |
|
86
|
|
|
{ |
|
87
|
|
|
$output = []; |
|
88
|
|
|
|
|
89
|
|
|
return $output; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
protected function convertPrices(): array |
|
93
|
|
|
{ |
|
94
|
|
|
$output = []; |
|
95
|
|
|
|
|
96
|
|
|
return $output; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: