1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Knp\Bundle\SnappyBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Processor; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
10
|
|
|
|
11
|
|
|
class KnpSnappyExtension extends Extension |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
|
|
public function load(array $configs, ContainerBuilder $container) |
17
|
|
|
{ |
18
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config')); |
19
|
|
|
|
20
|
|
|
$configuration = new Configuration(); |
21
|
|
|
$processor = new Processor(); |
22
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
23
|
|
|
|
24
|
|
|
if ($config['pdf']['enabled']) { |
25
|
|
|
$loader->load('pdf.xml'); |
26
|
|
|
|
27
|
|
|
$container->setParameter('knp_snappy.pdf.binary', $config['pdf']['binary']); |
28
|
|
|
$container->setParameter('knp_snappy.pdf.options', $config['pdf']['options']); |
29
|
|
|
$container->setParameter('knp_snappy.pdf.env', $config['pdf']['env']); |
30
|
|
|
|
31
|
|
|
if (!empty($config['temporary_folder'])) { |
32
|
|
|
$container->findDefinition('knp_snappy.pdf') |
33
|
|
|
->addMethodCall('setTemporaryFolder', [$config['temporary_folder']]); |
34
|
|
|
} |
35
|
|
|
if (!empty($config['process_timeout'])) { |
36
|
|
|
$container->findDefinition('knp_snappy.pdf') |
37
|
|
|
->addMethodCall('setTimeout', [$config['process_timeout']]); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($config['image']['enabled']) { |
42
|
|
|
$loader->load('image.xml'); |
43
|
|
|
|
44
|
|
|
$container->setParameter('knp_snappy.image.binary', $config['image']['binary']); |
45
|
|
|
$container->setParameter('knp_snappy.image.options', $config['image']['options']); |
46
|
|
|
$container->setParameter('knp_snappy.image.env', $config['image']['env']); |
47
|
|
|
|
48
|
|
|
if (!empty($config['temporary_folder'])) { |
49
|
|
|
$container->findDefinition('knp_snappy.image') |
50
|
|
|
->addMethodCall('setTemporaryFolder', [$config['temporary_folder']]); |
51
|
|
|
} |
52
|
|
|
if (!empty($config['process_timeout'])) { |
53
|
|
|
$container->findDefinition('knp_snappy.image') |
54
|
|
|
->addMethodCall('setTimeout', [$config['process_timeout']]); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|