1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arp\LaminasDateTime\Factory; |
6
|
|
|
|
7
|
|
|
use Arp\DateTime\DateTimeFactory; |
8
|
|
|
use Arp\DateTime\Factory\DateTimeFactoryFactory as ArpDateTimeFactoryFactory; |
9
|
|
|
use Arp\Factory\Exception\FactoryException; |
10
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
11
|
|
|
use Interop\Container\ContainerInterface; |
12
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Alex Patterson <[email protected]> |
16
|
|
|
* @package Arp\LaminasDateTime\Factory |
17
|
|
|
*/ |
18
|
|
|
final class DateTimeFactoryFactory extends AbstractFactory |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param ContainerInterface $container |
22
|
|
|
* @param string $requestedName |
23
|
|
|
* @param array|null $options |
24
|
|
|
* |
25
|
|
|
* @return DateTimeFactory |
26
|
|
|
* |
27
|
|
|
* @noinspection PhpMissingParamTypeInspection |
28
|
|
|
* |
29
|
|
|
* @throws ServiceNotCreatedException |
30
|
|
|
*/ |
31
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): DateTimeFactory |
32
|
|
|
{ |
33
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName); |
34
|
|
|
|
35
|
|
|
$config = [ |
36
|
|
|
'date_class_name' => $options['date_class_name'] ?? null, |
37
|
|
|
'time_zone_class_name' => $options['time_zone_class_name'] ?? null, |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
return (new ArpDateTimeFactoryFactory())->create($config); |
42
|
|
|
} catch (FactoryException $e) { |
43
|
|
|
throw new ServiceNotCreatedException( |
44
|
|
|
sprintf('Failed to create DateTimeFactory service \'%s\': %s', $requestedName, $e->getMessage()), |
45
|
|
|
$e->getCode(), |
46
|
|
|
$e |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|