PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/DependencyInjection/FOSFacebookExtension.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle
PHP | 82 lines | 50 code | 15 blank | 17 comment | 3 complexity | 0d8cd2f396c3c259ba3b47cf53928670 MD5 | raw file
 1<?php
 2
 3/*
 4 * This file is part of the FOSFacebookBundle package.
 5 *
 6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 7 *
 8 * For the full copyright and license information, please view the LICENSE
 9 * file that was distributed with this source code.
10 */
11
12namespace FOS\FacebookBundle\DependencyInjection;
13
14use Symfony\Component\Config\Definition\Processor;
15use Symfony\Component\HttpKernel\DependencyInjection\Extension;
16use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
17use Symfony\Component\DependencyInjection\ContainerBuilder;
18use Symfony\Component\Config\FileLocator;
19
20class FOSFacebookExtension extends Extension
21{
22    protected $resources = array(
23        'facebook' => 'facebook.xml',
24        'security' => 'security.xml',
25    );
26
27    public function load(array $configs, ContainerBuilder $container)
28    {
29        $processor = new Processor();
30        $configuration = new Configuration();
31        $config = $processor->processConfiguration($configuration, $configs);
32
33        $this->loadDefaults($container);
34
35        if (isset($config['alias'])) {
36            $container->setAlias($config['alias'], 'fos_facebook.api');
37        }
38
39        foreach (array('api', 'helper', 'twig') as $attribute) {
40            $container->setParameter('fos_facebook.'.$attribute.'.class', $config['class'][$attribute]);
41        }
42
43        foreach (array('app_id', 'secret', 'cookie', 'domain', 'logging', 'culture', 'permissions') as $attribute) {
44            $container->setParameter('fos_facebook.'.$attribute, $config[$attribute]);
45        }
46
47        $container->setParameter('fos_facebook.channel.expire', $config['channel']['expire']);
48
49        if (isset($config['file']) && $container->hasDefinition('fos_facebook.api')) {
50            $facebookApi = $container->getDefinition('fos_facebook.api');
51            $facebookApi->setFile($config['file']);
52        }
53    }
54
55    /**
56     * @codeCoverageIgnore
57     */
58    public function getXsdValidationBasePath()
59    {
60        return __DIR__ . '/../Resources/config/schema';
61    }
62
63    /**
64     * @codeCoverageIgnore
65     */
66    public function getNamespace()
67    {
68        return 'http://symfony.com/schema/dic/fos_facebook';
69    }
70
71    /**
72     * @codeCoverageIgnore
73     */
74    protected function loadDefaults($container)
75    {
76        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
77
78        foreach ($this->resources as $resource) {
79            $loader->load($resource);
80        }
81    }
82}