public function PhpDumper::dump in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/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
@api
Parameters
array $options An array of options:
Return value
string A PHP class representing of the service container
Overrides DumperInterface::dump
File
- modules/
providers/ service_container_symfony/ lib/ Symfony/ Component/ DependencyInjection/ Dumper/ PhpDumper.php, line 110
Class
- PhpDumper
- PhpDumper dumps a service container as a PHP class.
Namespace
Symfony\Component\DependencyInjection\DumperCode
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;
}