You are here

public function PhpDumper::dump in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dependency-injection/Dumper/PhpDumper.php \Symfony\Component\DependencyInjection\Dumper\PhpDumper::dump()

Dumps the service container as a PHP class.

Available options:

  • class: The class name
  • base_class: The base class name
  • namespace: The class namespace

Parameters

array $options An array of options:

Return value

string A PHP class representing of the service container

Overrides DumperInterface::dump

File

vendor/symfony/dependency-injection/Dumper/PhpDumper.php, line 104

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

public function dump(array $options = array()) {
  $this->targetDirRegex = null;
  $options = array_merge(array(
    'class' => 'ProjectServiceContainer',
    'base_class' => 'Container',
    'namespace' => '',
  ), $options);
  if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {

    // Build a regexp where the first root dirs are mandatory,
    // but every other sub-dir is optional up to the full path in $dir
    // Mandate at least 2 root dirs and not more that 5 optional dirs.
    $dir = explode(DIRECTORY_SEPARATOR, realpath($dir));
    $i = count($dir);
    if (3 <= $i) {
      $regex = '';
      $lastOptionalDir = $i > 8 ? $i - 5 : 3;
      $this->targetDirMaxMatches = $i - $lastOptionalDir;
      while (--$i >= $lastOptionalDir) {
        $regex = sprintf('(%s%s)?', preg_quote(DIRECTORY_SEPARATOR . $dir[$i], '#'), $regex);
      }
      do {
        $regex = preg_quote(DIRECTORY_SEPARATOR . $dir[$i], '#') . $regex;
      } while (0 < --$i);
      $this->targetDirRegex = '#' . preg_quote($dir[0], '#') . $regex . '#';
    }
  }
  $code = $this
    ->startClass($options['class'], $options['base_class'], $options['namespace']);
  if ($this->container
    ->isFrozen()) {
    $code .= $this
      ->addFrozenConstructor();
    $code .= $this
      ->addFrozenCompile();
  }
  else {
    $code .= $this
      ->addConstructor();
  }
  $code .= $this
    ->addServices() . $this
    ->addDefaultParametersMethod() . $this
    ->endClass() . $this
    ->addProxyClasses();
  $this->targetDirRegex = null;
  return $code;
}