Symfony\Component\DependencyInjection\Dumper\XmlDumper::dump PHP Method

dump() public method

Dumps the service container as an XML string.
public dump ( array $options = [] ) : string
$options array An array of options
return string An xml string representing of the service container
    public function dump(array $options = array())
    {
        $this->document = new \DOMDocument('1.0', 'utf-8');
        $this->document->formatOutput = true;

        $container = $this->document->createElementNS('http://symfony.com/schema/dic/services', 'container');
        $container->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
        $container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd');

        $this->addParameters($container);
        $this->addServices($container);

        $this->document->appendChild($container);
        $xml = $this->document->saveXML();
        $this->document = null;

        return $xml;
    }

Usage Example

Example #1
0
 /**
  * Loads a container and returns it.
  *
  * If the cache file for the service container exists and is current, it
  * will be loaded and returned. Otherwise, a new container will be built
  * using the configuration file and the provided optional builder. The
  * builder will be used to make changes to the service container before
  * it is compiled and cached.
  *
  * It may be important to note that debug mode for the `ConfigCache` class
  * is enabled by default. This will ensure that cached configuration files
  * are updated whenever they are changed.
  *
  * @param string   $containerCacheFilePath     The container cache file path.
  * @param callable $containerBuilderCallable   The new container builder callable.
  * @param string   $compiledContainerClassName The compiled container class name.
  * @param boolean  $debug                      Is debugging mode enabled?
  *
  * @return Jarvis The loaded application.
  */
 public static function create($containerCacheFilePath, callable $containerBuilderCallable = null, $compiledContainerClassName = 'AppCachedContainer', $debug = true)
 {
     $cacheManager = new ConfigCache($containerCacheFilePath, $debug);
     if (!$cacheManager->isFresh()) {
         $container = static::createContainer();
         if (null !== $containerBuilderCallable) {
             $containerBuilderCallable($container);
         }
         if ($debug) {
             $filename = pathinfo($containerCacheFilePath, PATHINFO_DIRNAME) . '/' . pathinfo($containerCacheFilePath, PATHINFO_FILENAME) . '.xml';
             $container->setParameter('debug.container.dump', $filename);
         }
         $container->compile();
         $dumper = new PhpDumper($container);
         $cacheManager->write($dumper->dump(array('class' => $compiledContainerClassName)), $container->getResources());
         if ($debug) {
             $filename = $container->getParameter('debug.container.dump');
             $dumper = new XmlDumper($container);
             $filesystem = new Filesystem();
             $filesystem->dumpFile($filename, $dumper->dump(), null);
             try {
                 $filesystem->chmod($filename, 0666, umask());
             } catch (IOException $e) {
                 // discard chmod failure (some filesystem may not support it)
             }
         }
     }
     if (!class_exists($compiledContainerClassName)) {
         /** @noinspection PhpIncludeInspection */
         require $containerCacheFilePath;
     }
     return new Jarvis(new $compiledContainerClassName());
 }
All Usage Examples Of Symfony\Component\DependencyInjection\Dumper\XmlDumper::dump