ContainerBuilderDebugDumpPass.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
  14. use Symfony\Component\Filesystem\Exception\IOException;
  15. use Symfony\Component\Filesystem\Filesystem;
  16. /**
  17. * Dumps the ContainerBuilder to a cache file so that it can be used by
  18. * debugging tools such as the debug:container console command.
  19. *
  20. * @author Ryan Weaver <ryan@thatsquality.com>
  21. * @author Fabien Potencier <fabien@symfony.com>
  22. */
  23. class ContainerBuilderDebugDumpPass implements CompilerPassInterface
  24. {
  25. public function process(ContainerBuilder $container)
  26. {
  27. $dumper = new XmlDumper($container);
  28. $filename = $container->getParameter('debug.container.dump');
  29. $filesystem = new Filesystem();
  30. $filesystem->dumpFile($filename, $dumper->dump(), null);
  31. try {
  32. $filesystem->chmod($filename, 0666, umask());
  33. } catch (IOException $e) {
  34. // discard chmod failure (some filesystem may not support it)
  35. }
  36. }
  37. }