* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace Chill\PersonBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Chill\MainBundle\DependencyInjection\MissingBundleException; use Chill\PersonBundle\Security\Authorization\PersonVoter; /** * This is the class that loads and manages your bundle configuration * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} */ class ChillPersonExtension extends Extension implements PrependExtensionInterface { /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); // set configuration for double metaphone $container->setParameter('cl_chill_person.search.use_double_metaphone', $config['search']['use_double_metaphone']); // set configuration for validation $container->setParameter('chill_person.validation.birtdate_not_before', $config['validation']['birthdate_not_after']); $this->handlePersonFieldsParameters($container, $config['person_fields']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); $loader->load('services/widgets.yml'); } private function handlePersonFieldsParameters(ContainerBuilder $container, $config) { if (array_key_exists('enabled', $config)) { unset($config['enabled']); } $container->setParameter('chill_person.person_fields', $config); foreach ($config as $key => $value) { $container->setParameter('chill_person.person_fields.'.$key, $value); } } private function declarePersonAsCustomizable (ContainerBuilder $container) { $bundles = $container->getParameter('kernel.bundles'); if (!isset($bundles['ChillCustomFieldsBundle'])) { throw new MissingBundleException('ChillCustomFieldsBundle'); } $container->prependExtensionConfig('chill_custom_fields', array('customizables_entities' => array( array('class' => 'Chill\PersonBundle\Entity\Person', 'name' => 'PersonEntity') ) ) ); } public function prepend(ContainerBuilder $container) { $this->prependRoleHierarchy($container); $bundles = $container->getParameter('kernel.bundles'); //add ChillMain to assetic-enabled bundles if (!isset($bundles['AsseticBundle'])) { throw new MissingBundleException('AsseticBundle'); } $asseticConfig = $container->getExtensionConfig('assetic'); $asseticConfig['bundles'][] = 'ChillPersonBundle'; $container->prependExtensionConfig('assetic', array('bundles' => array('ChillPersonBundle'))); //add person_fields parameter as global $chillPersonConfig = $container->getExtensionConfig($this->getAlias()); $config = $this->processConfiguration(new Configuration(), $chillPersonConfig); $twigConfig = array( 'globals' => array( 'chill_person' => array( 'fields' => $config['person_fields'] ) ) ); $container->prependExtensionConfig('twig', $twigConfig); $this-> declarePersonAsCustomizable($container); //declare routes for person bundle $container->prependExtensionConfig('chill_main', array( 'routing' => array( 'resources' => array( '@ChillPersonBundle/Resources/config/routing.yml' ) ) )); } protected function prependRoleHierarchy(ContainerBuilder $container) { $container->prependExtensionConfig('security', array( 'role_hierarchy' => array( 'CHILL_PERSON_UPDATE' => array('CHILL_PERSON_SEE'), 'CHILL_PERSON_CREATE' => array('CHILL_PERSON_SEE'), 'CHILL_PERSON_SEE' => array(PersonVoter::STATS) ) )); } }