This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices.php
206 lines (187 loc) · 6.98 KB
/
services.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
use Dhii\Exception\CreateInvalidArgumentExceptionCapableTrait;
use Dhii\I18n\StringTranslatingTrait;
use Dhii\Iterator\NormalizeIteratorCapableTrait;
use Dhii\Util\Normalization\NormalizeArrayCapableTrait;
use Psr\Container\ContainerInterface;
use RebelCode\EddBookings\Services\Module\AdminDeleteServiceHandler;
use RebelCode\EddBookings\Services\Module\GetServiceHasPriceOptionsHandler;
use RebelCode\EddBookings\Services\Module\GetServicePriceHandler;
use RebelCode\EddBookings\Services\Module\GetServicePriceOptionsHandler;
use RebelCode\EddBookings\Services\Module\HideServicesFromDownloadsHandler;
use RebelCode\EddBookings\Services\Module\SessionTypesMigrationHandler;
use RebelCode\EddBookings\Services\Storage\ServicesEntityManager;
use RebelCode\Transformers\CallbackTransformer;
/**
* The service list for the EDD Bookings Services module.
*
* @since [*next-version*]
*/
class EddBkServicesServiceList extends ArrayObject
{
/* @since [*next-version*] */
use NormalizeArrayCapableTrait;
/* @since [*next-version*] */
use NormalizeIteratorCapableTrait;
/* @since [*next-version*] */
use CreateInvalidArgumentExceptionCapableTrait;
/* @since [*next-version*] */
use StringTranslatingTrait;
/**
* Constructor.
*
* @since [*next-version*]
*/
public function __construct()
{
parent::__construct($this->_getServices());
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
protected function _createArrayIterator(array $array)
{
return new ArrayIterator($array);
}
/**
* {@inheritdoc}
*
* @since [*next-version*]
*/
protected function _createTraversableIterator(Traversable $traversable)
{
return new IteratorIterator($traversable);
}
/**
* Retrieves the services.
*
* @since [*next-version*]
*
* @return array
*/
protected function _getServices()
{
return [
/**
* The services manager.
*
* @since [*next-version*]
*/
'eddbk_services_manager' => function (ContainerInterface $c) {
return new ServicesEntityManager(
$c->get('eddbk_services/post_type'),
$c->get('eddbk_services/meta_prefix'),
$c->get('resources_entity_manager'),
$c->get('session_rules_select_rm'),
$c->get('session_rules_insert_rm'),
$c->get('session_rules_update_rm'),
$c->get('session_rules_delete_rm'),
$c->get('sql_expression_builder')
);
},
/*
* The handler for handling service deletion.
*
* @since [*next-version*]
*/
'eddbk_admin_delete_service_handler' => function (ContainerInterface $c) {
return new AdminDeleteServiceHandler(
$c->get('eddbk_services/post_type'),
$c->get('eddbk_services/meta_prefix'),
$c->get('resources_delete_rm'),
$c->get('sessions_delete_rm'),
$c->get('session_rules_delete_rm'),
$c->get('sql_expression_builder')
);
},
/*
* The transformer for transforming a price amount into its formatted counterpart.
*
* @since [*next-version*]
*/
'eddbk_price_transformer' => function (ContainerInterface $c) {
return new CallbackTransformer(function ($price) use ($c) {
return html_entity_decode(edd_currency_filter(edd_format_amount($price)));
});
},
/*
* The transformer for transforming comma separating strings into arrays.
*
* @since [*next-version*]
*/
'eddbk_comma_list_array_transformer' => function (ContainerInterface $c) {
return new CallbackTransformer(function ($commaList) {
return (strlen($commaList) > 0)
? explode(',', $commaList)
: [];
});
},
/*
* The transformer for transforming values into booleans.
*
* @since [*next-version*]
*/
'eddbk_boolean_transformer' => function (ContainerInterface $c) {
return new CallbackTransformer(function ($value) {
return (bool) $value;
});
},
/*
* The handler that changes the Download price to the smallest session length's price.
*
* @since [*next-version*]
*/
'eddbk_get_service_price_handler' => function (ContainerInterface $c) {
return new GetServicePriceHandler(
$c->get('eddbk_services_manager')
);
},
/*
* The handler that changes the Download price options to the session length prices.
*
* @since [*next-version*]
*/
'eddbk_get_service_price_options_handler' => function (ContainerInterface $c) {
return new GetServicePriceOptionsHandler(
$c->get('eddbk_services_manager')
);
},
/*
* The handler that filters the Download price options flag.
*
* @since [*next-version*]
*/
'eddbk_get_service_has_price_options_handler' => function (ContainerInterface $c) {
return new GetServiceHasPriceOptionsHandler(
$c->get('eddbk_services_manager')
);
},
/**
* The handler that hides services from the downloads list.
*
* @since [*next-version*]
*/
'eddbk_hide_services_from_downloads_list_handler' => function (ContainerInterface $c) {
return new HideServicesFromDownloadsHandler(
$c->get('eddbk_services/post_type'),
$c->get('eddbk_services_manager')
);
},
/*
* The migration handler updating service session types when the database is upgraded to version 3.
*
* @since [*next-version*]
*/
'eddbk_services_session_types_migration_3_handler' => function (ContainerInterface $c) {
return new SessionTypesMigrationHandler(
$c->get('wpdb'),
$c->get('eddbk_services/post_type'),
$c->get('eddbk_services/meta_prefix')
);
}
];
}
}
return new EddBkServicesServiceList();