JMSAopExtension.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace JMS\AopBundle\DependencyInjection;
  18. use JMS\AopBundle\Exception\RuntimeException;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\Config\FileLocator;
  21. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  22. use Symfony\Component\DependencyInjection\Loader;
  23. /**
  24. * JMSAopExtension.
  25. *
  26. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  27. */
  28. class JMSAopExtension extends Extension
  29. {
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function load(array $configs, ContainerBuilder $container)
  34. {
  35. $configuration = new Configuration();
  36. $config = $this->processConfiguration($configuration, $configs);
  37. $cacheDir = $container->getParameterBag()->resolveValue($config['cache_dir']);
  38. if (!is_dir($cacheDir)) {
  39. if (false === @mkdir($cacheDir, 0777, true)) {
  40. throw new RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
  41. }
  42. }
  43. $container->setParameter('jms_aop.cache_dir', $cacheDir);
  44. $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  45. $loader->load('services.xml');
  46. }
  47. }