1 <?php
2 3 4 5 6 7 8 9 10
11
12 MainFactory::load_class('AbstractCustomerServiceFactory');
13
14 15 16 17 18 19 20 21 22
23 class CustomerServiceFactory extends AbstractCustomerServiceFactory
24 {
25 26 27 28
29 protected $ciDatabaseQueryBuilder;
30
31
32 33 34 35 36
37 public function __construct(CI_DB_query_builder $ciDatabaseQueryBuilder)
38 {
39 $this->ciDatabaseQueryBuilder = $ciDatabaseQueryBuilder;
40 }
41
42
43 44 45 46 47
48 public function getCountryService()
49 {
50 $customerCountryRepo = $this->_getCustomerCountryRepository();
51 $customerCountryZoneRepo = $this->_getCustomerCountryZoneRepository();
52
53 $countryService = MainFactory::create('CountryService', $customerCountryRepo, $customerCountryZoneRepo);
54
55 return $countryService;
56 }
57
58
59 60 61 62 63
64 public function getCustomerService()
65 {
66 $customerReadService = $this->createCustomerReadService();
67 $customerWriteService = $this->createCustomerWriteService();
68
69 $customerService = MainFactory::create('CustomerService', $customerReadService, $customerWriteService);
70
71 return $customerService;
72 }
73
74
75 76 77 78 79
80 public function createCustomerReadService()
81 {
82 $customerRepository = $this->_getCustomerRepository();
83
84 $customerReadService = MainFactory::create('CustomerReadService', $customerRepository);
85
86 return $customerReadService;
87 }
88
89
90 91 92 93 94
95 public function createCustomerWriteService()
96 {
97 $addressBookService = $this->getAddressBookService();
98 $customerRepository = $this->_getCustomerRepository();
99 $customerServiceSettings = $this->_getCustomerServiceSettings();
100 $vatValidator = MainFactory::create('VatNumberValidator');
101
102 $customerWriteService = MainFactory::create('CustomerWriteService', $addressBookService, $customerRepository,
103 $customerServiceSettings, $vatValidator);
104
105 return $customerWriteService;
106 }
107
108
109 110 111 112 113
114 public function getAddressBookService()
115 {
116 $addressRepository = $this->_getCustomerAddressRepository();
117 $addressBookService = MainFactory::create('AddressBookService', $addressRepository);
118
119 return $addressBookService;
120 }
121
122
123 124 125 126 127
128 public function getCustomerRegistrationInputValidatorService()
129 {
130 return $this->_getCustomerInputValidatorServiceByValidatorName('CustomerRegistrationInputValidatorService');
131 }
132
133
134 135 136 137 138
139 public function getCustomerAccountInputValidator()
140 {
141 return $this->_getCustomerInputValidatorServiceByValidatorName('CustomerAccountInputValidator');
142 }
143
144
145 146 147 148 149
150 public function getDatabaseQueryBuilder()
151 {
152 return $this->ciDatabaseQueryBuilder;
153 }
154
155
156 157 158 159 160 161 162
163 protected function _getCustomerFactory()
164 {
165 $customerFactory = MainFactory::create('CustomerFactory');
166
167 return $customerFactory;
168 }
169
170
171 172 173 174 175
176 protected function _getCustomerRepository()
177 {
178 $customerWriter = $this->_getCustomerWriter();
179 $customerReader = $this->_getCustomerReader();
180 $customerDeleter = $this->_getCustomerDeleter();
181 $addressRepository = $this->_getCustomerAddressRepository();
182 $customerFactory = $this->_getCustomerFactory();
183
184 $repository = MainFactory::create('CustomerRepository', $customerWriter, $customerReader, $customerDeleter,
185 $addressRepository, $customerFactory);
186
187 return $repository;
188 }
189
190
191 192 193 194 195
196 public function getCustomerAddressInputValidatorService()
197 {
198 return $this->_getCustomerInputValidatorServiceByValidatorName('CustomerAddressInputValidator');
199 }
200
201
202 203 204 205 206
207 protected function _getCustomerCountryRepository()
208 {
209 $reader = $this->_getCustomerCountryReader();
210 $repo = MainFactory::create('CustomerCountryRepository', $reader);
211
212 return $repo;
213 }
214
215
216 217 218 219 220
221 protected function _getCustomerCountryZoneRepository()
222 {
223 $reader = $this->_getCustomerCountryZoneReader();
224 $customerFactory = $this->_getCustomerFactory();
225 $repo = MainFactory::create('CustomerCountryZoneRepository', $reader, $customerFactory);
226
227 return $repo;
228 }
229
230
231 232 233 234 235
236 protected function _getCustomerAddressRepository()
237 {
238 $writer = $this->_getCustomerAddressWriter();
239 $reader = $this->_getCustomerAddressReader();
240 $deleter = $this->_getCustomerAddressDeleter();
241 $factory = $this->_getCustomerFactory();
242 $repository = MainFactory::create('CustomerAddressRepository', $writer, $deleter, $reader, $factory);
243
244 return $repository;
245 }
246
247
248 249 250 251 252 253 254
255 protected function _getCustomerInputValidatorServiceByValidatorName($inputValidatorName)
256 {
257 $customerService = $this->getCustomerService();
258 $countryService = $this->getCountryService();
259 $settings = MainFactory::create('CustomerInputValidatorSettings');
260 $countryRepo = $this->_getCustomerCountryRepository();
261 $countryZoneRepo = $this->_getCustomerCountryZoneRepository();
262 $vatNumberValidator = MainFactory::create('VatNumberValidator');
263
264 $validator = MainFactory::create($inputValidatorName, $customerService, $countryService, $settings,
265 $countryRepo, $countryZoneRepo, $vatNumberValidator);
266
267 return $validator;
268 }
269
270
271 272 273 274 275
276 protected function _getCustomerAddressDeleter()
277 {
278 $deleter = MainFactory::create('CustomerAddressDeleter', $this->getDatabaseQueryBuilder());
279
280 return $deleter;
281 }
282
283
284 285 286 287 288
289 protected function _getCustomerAddressReader()
290 {
291 $customerFactory = $this->_getCustomerFactory();
292 $countryService = $this->getCountryService();
293
294 $reader = MainFactory::create('CustomerAddressReader', $customerFactory, $countryService,
295 $this->getDatabaseQueryBuilder());
296
297 return $reader;
298 }
299
300
301 302 303 304 305
306 protected function _getCustomerCountryZoneReader()
307 {
308 $customerFactory = $this->_getCustomerFactory();
309 $reader = MainFactory::create('CustomerCountryZoneReader', $customerFactory,
310 $this->getDatabaseQueryBuilder());
311
312 return $reader;
313 }
314
315
316 317 318 319 320
321 protected function _getCustomerCountryReader()
322 {
323 $customerFactory = $this->_getCustomerFactory();
324 $reader = MainFactory::create('CustomerCountryReader', $customerFactory,
325 $this->getDatabaseQueryBuilder());
326
327 return $reader;
328 }
329
330
331 332 333 334 335
336 protected function _getCustomerWriter()
337 {
338 $customerWriter = MainFactory::create('CustomerWriter', $this->getDatabaseQueryBuilder());
339
340 return $customerWriter;
341 }
342
343
344 345 346 347 348
349 protected function _getCustomerReader()
350 {
351 $customerFactory = $this->_getCustomerFactory();
352 $customerAddressRepository = $this->_getCustomerAddressRepository();
353 $dbQueryBuilder = $this->getDatabaseQueryBuilder();
354
355 $customerReader = MainFactory::create('CustomerReader', $customerFactory, $customerAddressRepository,
356 $dbQueryBuilder);
357
358 return $customerReader;
359 }
360
361
362 363 364 365 366
367 protected function _getCustomerDeleter()
368 {
369 $customerDeleter = MainFactory::create('CustomerDeleter', $this->getDatabaseQueryBuilder());
370
371 return $customerDeleter;
372 }
373
374
375 376 377 378 379
380 protected function _getCustomerServiceSettings()
381 {
382 $settings = MainFactory::create('CustomerServiceSettings');
383
384 return $settings;
385 }
386
387
388 389 390 391 392
393 protected function _getCustomerAddressWriter()
394 {
395 $writer = MainFactory::create('CustomerAddressWriter', $this->getDatabaseQueryBuilder());
396
397 return $writer;
398 }
399 }