1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Debril\RssAtomBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
8
|
|
|
use Symfony\Component\Config\FileLocator; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This is the class that loads and manages your bundle configuration. |
14
|
|
|
* |
15
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
16
|
|
|
*/ |
17
|
|
|
class DebrilRssAtomExtension extends Extension implements CompilerPassInterface |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $defaultDateFormats = [ |
24
|
|
|
\DateTime::RFC3339, |
25
|
|
|
\DateTime::RSS, |
26
|
|
|
\DateTime::W3C, |
27
|
|
|
'Y-m-d\TH:i:s.uP', |
28
|
|
|
'Y-m-d', |
29
|
|
|
'd/m/Y', |
30
|
|
|
'd M Y H:i:s P', |
31
|
|
|
'D, d M Y H:i O', |
32
|
|
|
'D, d M Y H:i:s O', |
33
|
|
|
'D M d Y H:i:s e', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
*/ |
39
|
|
|
public function load(array $configs, ContainerBuilder $container) : void |
40
|
|
|
{ |
41
|
|
|
$configuration = new Configuration(); |
42
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
43
|
|
|
|
44
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
45
|
|
|
$loader->load('services.yml'); |
46
|
|
|
|
47
|
|
|
$this->setDateFormats($container, $config); |
48
|
|
|
$container->setParameter('debril_rss_atom.public_feeds', !$config['private']); |
49
|
|
|
$container->setParameter('debril_rss_atom.force_refresh', $config['force_refresh']); |
50
|
|
|
$container->setParameter('debril_rss_atom.content_type_json', $config['content_type_json']); |
51
|
|
|
$container->setParameter('debril_rss_atom.content_type_xml', $config['content_type_xml']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param ContainerBuilder $container |
56
|
|
|
* @param array $config |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
|
|
protected function setDateFormats(ContainerBuilder $container, array $config) : self |
60
|
|
|
{ |
61
|
|
|
$dateFormats = isset($config['date_formats']) ? |
62
|
|
|
array_merge($this->defaultDateFormats, $config['date_formats']): |
63
|
|
|
$this->defaultDateFormats; |
64
|
|
|
|
65
|
|
|
$container->setParameter( |
66
|
|
|
'debril_rss_atom.date_formats', |
67
|
|
|
$dateFormats |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param ContainerBuilder $container |
75
|
|
|
*/ |
76
|
|
|
public function process(ContainerBuilder $container) : void |
77
|
|
|
{ |
78
|
|
|
$this->setDefinition($container, 'logger', 'Psr\Log\NullLogger'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param ContainerBuilder $container |
83
|
|
|
* @param string $serviceName |
84
|
|
|
* @param string $className |
85
|
|
|
* @return DebrilRssAtomExtension |
86
|
|
|
*/ |
87
|
|
|
protected function setDefinition(ContainerBuilder $container, string $serviceName, string $className) : self |
88
|
|
|
{ |
89
|
|
|
if ( ! $container->has($serviceName) ) { |
90
|
|
|
$container->setDefinition($serviceName, new Definition($className)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|