Augmentation vers version 3.3.0
This commit is contained in:
@@ -21,9 +21,7 @@ interface DumperInterface
|
||||
/**
|
||||
* Dumps the service container.
|
||||
*
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return string The representation of the service container
|
||||
* @return string|array The representation of the service container
|
||||
*/
|
||||
public function dump(array $options = array());
|
||||
public function dump(array $options = []);
|
||||
}
|
||||
|
||||
@@ -11,14 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Scope;
|
||||
|
||||
/**
|
||||
* GraphvizDumper dumps a service container as a graphviz file.
|
||||
@@ -33,14 +32,14 @@ class GraphvizDumper extends Dumper
|
||||
{
|
||||
private $nodes;
|
||||
private $edges;
|
||||
private $options = array(
|
||||
'graph' => array('ratio' => 'compress'),
|
||||
'node' => array('fontsize' => 11, 'fontname' => 'Arial', 'shape' => 'record'),
|
||||
'edge' => array('fontsize' => 9, 'fontname' => 'Arial', 'color' => 'grey', 'arrowhead' => 'open', 'arrowsize' => 0.5),
|
||||
'node.instance' => array('fillcolor' => '#9999ff', 'style' => 'filled'),
|
||||
'node.definition' => array('fillcolor' => '#eeeeee'),
|
||||
'node.missing' => array('fillcolor' => '#ff9999', 'style' => 'filled'),
|
||||
);
|
||||
private $options = [
|
||||
'graph' => ['ratio' => 'compress'],
|
||||
'node' => ['fontsize' => 11, 'fontname' => 'Arial', 'shape' => 'record'],
|
||||
'edge' => ['fontsize' => 9, 'fontname' => 'Arial', 'color' => 'grey', 'arrowhead' => 'open', 'arrowsize' => 0.5],
|
||||
'node.instance' => ['fillcolor' => '#9999ff', 'style' => 'filled'],
|
||||
'node.definition' => ['fillcolor' => '#eeeeee'],
|
||||
'node.missing' => ['fillcolor' => '#ff9999', 'style' => 'filled'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Dumps the service container as a graphviz graph.
|
||||
@@ -56,9 +55,9 @@ class GraphvizDumper extends Dumper
|
||||
*
|
||||
* @return string The dot representation of the service container
|
||||
*/
|
||||
public function dump(array $options = array())
|
||||
public function dump(array $options = [])
|
||||
{
|
||||
foreach (array('graph', 'node', 'edge', 'node.instance', 'node.definition', 'node.missing') as $key) {
|
||||
foreach (['graph', 'node', 'edge', 'node.instance', 'node.definition', 'node.missing'] as $key) {
|
||||
if (isset($options[$key])) {
|
||||
$this->options[$key] = array_merge($this->options[$key], $options[$key]);
|
||||
}
|
||||
@@ -66,7 +65,7 @@ class GraphvizDumper extends Dumper
|
||||
|
||||
$this->nodes = $this->findNodes();
|
||||
|
||||
$this->edges = array();
|
||||
$this->edges = [];
|
||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||
$this->edges[$id] = array_merge(
|
||||
$this->findEdges($id, $definition->getArguments(), true, ''),
|
||||
@@ -81,7 +80,7 @@ class GraphvizDumper extends Dumper
|
||||
}
|
||||
}
|
||||
|
||||
return $this->startDot().$this->addNodes().$this->addEdges().$this->endDot();
|
||||
return $this->container->resolveEnvPlaceholders($this->startDot().$this->addNodes().$this->addEdges().$this->endDot(), '__ENV_%s__');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +110,7 @@ class GraphvizDumper extends Dumper
|
||||
$code = '';
|
||||
foreach ($this->edges as $id => $edges) {
|
||||
foreach ($edges as $edge) {
|
||||
$code .= sprintf(" node_%s -> node_%s [label=\"%s\" style=\"%s\"];\n", $this->dotize($id), $this->dotize($edge['to']), $edge['name'], $edge['required'] ? 'filled' : 'dashed');
|
||||
$code .= sprintf(" node_%s -> node_%s [label=\"%s\" style=\"%s\"%s];\n", $this->dotize($id), $this->dotize($edge['to']), $edge['name'], $edge['required'] ? 'filled' : 'dashed', $edge['lazy'] ? ' color="#9999ff"' : '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,9 +127,9 @@ class GraphvizDumper extends Dumper
|
||||
*
|
||||
* @return array An array of edges
|
||||
*/
|
||||
private function findEdges($id, array $arguments, $required, $name)
|
||||
private function findEdges($id, array $arguments, $required, $name, $lazy = false)
|
||||
{
|
||||
$edges = array();
|
||||
$edges = [];
|
||||
foreach ($arguments as $argument) {
|
||||
if ($argument instanceof Parameter) {
|
||||
$argument = $this->container->hasParameter($argument) ? $this->container->getParameter($argument) : null;
|
||||
@@ -139,13 +138,27 @@ class GraphvizDumper extends Dumper
|
||||
}
|
||||
|
||||
if ($argument instanceof Reference) {
|
||||
$lazyEdge = $lazy;
|
||||
|
||||
if (!$this->container->has((string) $argument)) {
|
||||
$this->nodes[(string) $argument] = array('name' => $name, 'required' => $required, 'class' => '', 'attributes' => $this->options['node.missing']);
|
||||
$this->nodes[(string) $argument] = ['name' => $name, 'required' => $required, 'class' => '', 'attributes' => $this->options['node.missing']];
|
||||
} elseif ('service_container' !== (string) $argument) {
|
||||
$lazyEdge = $lazy || $this->container->getDefinition((string) $argument)->isLazy();
|
||||
}
|
||||
|
||||
$edges[] = array('name' => $name, 'required' => $required, 'to' => $argument);
|
||||
$edges[] = ['name' => $name, 'required' => $required, 'to' => $argument, 'lazy' => $lazyEdge];
|
||||
} elseif ($argument instanceof ArgumentInterface) {
|
||||
$edges = array_merge($edges, $this->findEdges($id, $argument->getValues(), $required, $name, true));
|
||||
} elseif ($argument instanceof Definition) {
|
||||
$edges = array_merge($edges,
|
||||
$this->findEdges($id, $argument->getArguments(), $required, ''),
|
||||
$this->findEdges($id, $argument->getProperties(), false, '')
|
||||
);
|
||||
foreach ($argument->getMethodCalls() as $call) {
|
||||
$edges = array_merge($edges, $this->findEdges($id, $call[1], false, $call[0].'()'));
|
||||
}
|
||||
} elseif (\is_array($argument)) {
|
||||
$edges = array_merge($edges, $this->findEdges($id, $argument, $required, $name));
|
||||
$edges = array_merge($edges, $this->findEdges($id, $argument, $required, $name, $lazy));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +172,7 @@ class GraphvizDumper extends Dumper
|
||||
*/
|
||||
private function findNodes()
|
||||
{
|
||||
$nodes = array();
|
||||
$nodes = [];
|
||||
|
||||
$container = $this->cloneContainer();
|
||||
|
||||
@@ -175,20 +188,17 @@ class GraphvizDumper extends Dumper
|
||||
} catch (ParameterNotFoundException $e) {
|
||||
}
|
||||
|
||||
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], array('style' => $definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope(false) ? 'filled' : 'dotted')));
|
||||
$nodes[$id] = ['class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], ['style' => $definition->isShared() ? 'filled' : 'dotted'])];
|
||||
$container->setDefinition($id, new Definition('stdClass'));
|
||||
}
|
||||
|
||||
foreach ($container->getServiceIds() as $id) {
|
||||
$service = $container->get($id);
|
||||
|
||||
if (array_key_exists($id, $container->getAliases())) {
|
||||
if (\array_key_exists($id, $container->getAliases())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$container->hasDefinition($id)) {
|
||||
$class = ('service_container' === $id) ? \get_class($this->container) : \get_class($service);
|
||||
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => $this->options['node.instance']);
|
||||
$nodes[$id] = ['class' => str_replace('\\', '\\\\', \get_class($container->get($id))), 'attributes' => $this->options['node.instance']];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,9 +213,6 @@ class GraphvizDumper extends Dumper
|
||||
$container->setDefinitions($this->container->getDefinitions());
|
||||
$container->setAliases($this->container->getAliases());
|
||||
$container->setResources($this->container->getResources());
|
||||
foreach ($this->container->getScopes(false) as $scope => $parentScope) {
|
||||
$container->addScope(new Scope($scope, $parentScope));
|
||||
}
|
||||
foreach ($this->container->getExtensions() as $extension) {
|
||||
$container->registerExtension($extension);
|
||||
}
|
||||
@@ -246,7 +253,7 @@ class GraphvizDumper extends Dumper
|
||||
*/
|
||||
private function addAttributes(array $attributes)
|
||||
{
|
||||
$code = array();
|
||||
$code = [];
|
||||
foreach ($attributes as $k => $v) {
|
||||
$code[] = sprintf('%s="%s"', $k, $v);
|
||||
}
|
||||
@@ -263,7 +270,7 @@ class GraphvizDumper extends Dumper
|
||||
*/
|
||||
private function addOptions(array $options)
|
||||
{
|
||||
$code = array();
|
||||
$code = [];
|
||||
foreach ($options as $k => $v) {
|
||||
$code[] = sprintf('%s="%s"', $k, $v);
|
||||
}
|
||||
@@ -292,7 +299,7 @@ class GraphvizDumper extends Dumper
|
||||
*/
|
||||
private function getAliases($id)
|
||||
{
|
||||
$aliases = array();
|
||||
$aliases = [];
|
||||
foreach ($this->container->getAliases() as $alias => $origin) {
|
||||
if ($id == $origin) {
|
||||
$aliases[] = $alias;
|
||||
|
||||
1876
vendor/symfony/dependency-injection/Dumper/PhpDumper.php
vendored
1876
vendor/symfony/dependency-injection/Dumper/PhpDumper.php
vendored
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,9 @@
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
@@ -37,14 +40,14 @@ class XmlDumper extends Dumper
|
||||
*
|
||||
* @return string An xml string representing of the service container
|
||||
*/
|
||||
public function dump(array $options = array())
|
||||
public function dump(array $options = [])
|
||||
{
|
||||
$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');
|
||||
$container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd');
|
||||
|
||||
$this->addParameters($container);
|
||||
$this->addServices($container);
|
||||
@@ -53,7 +56,7 @@ class XmlDumper extends Dumper
|
||||
$xml = $this->document->saveXML();
|
||||
$this->document = null;
|
||||
|
||||
return $xml;
|
||||
return $this->container->resolveEnvPlaceholders($xml);
|
||||
}
|
||||
|
||||
private function addParameters(\DOMElement $parent)
|
||||
@@ -63,7 +66,7 @@ class XmlDumper extends Dumper
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->container->isFrozen()) {
|
||||
if ($this->container->isCompiled()) {
|
||||
$data = $this->escape($data);
|
||||
}
|
||||
|
||||
@@ -87,9 +90,8 @@ class XmlDumper extends Dumper
|
||||
/**
|
||||
* Adds a service.
|
||||
*
|
||||
* @param Definition $definition
|
||||
* @param string $id
|
||||
* @param \DOMElement $parent
|
||||
* @param Definition $definition
|
||||
* @param string $id
|
||||
*/
|
||||
private function addService($definition, $id, \DOMElement $parent)
|
||||
{
|
||||
@@ -104,30 +106,15 @@ class XmlDumper extends Dumper
|
||||
|
||||
$service->setAttribute('class', $class);
|
||||
}
|
||||
if ($definition->getFactoryMethod(false)) {
|
||||
$service->setAttribute('factory-method', $definition->getFactoryMethod(false));
|
||||
}
|
||||
if ($definition->getFactoryClass(false)) {
|
||||
$service->setAttribute('factory-class', $definition->getFactoryClass(false));
|
||||
}
|
||||
if ($definition->getFactoryService(false)) {
|
||||
$service->setAttribute('factory-service', $definition->getFactoryService(false));
|
||||
}
|
||||
if (!$definition->isShared()) {
|
||||
$service->setAttribute('shared', 'false');
|
||||
}
|
||||
if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
|
||||
$service->setAttribute('scope', $scope);
|
||||
}
|
||||
if (!$definition->isPublic()) {
|
||||
$service->setAttribute('public', 'false');
|
||||
if (!$definition->isPrivate()) {
|
||||
$service->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
if ($definition->isSynthetic()) {
|
||||
$service->setAttribute('synthetic', 'true');
|
||||
}
|
||||
if ($definition->isSynchronized(false)) {
|
||||
$service->setAttribute('synchronized', 'true');
|
||||
}
|
||||
if ($definition->isLazy()) {
|
||||
$service->setAttribute('lazy', 'true');
|
||||
}
|
||||
@@ -176,7 +163,9 @@ class XmlDumper extends Dumper
|
||||
$this->addService($callable[0], null, $factory);
|
||||
$factory->setAttribute('method', $callable[1]);
|
||||
} elseif (\is_array($callable)) {
|
||||
$factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
|
||||
if (null !== $callable[0]) {
|
||||
$factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
|
||||
}
|
||||
$factory->setAttribute('method', $callable[1]);
|
||||
} else {
|
||||
$factory->setAttribute('function', $callable);
|
||||
@@ -195,13 +184,17 @@ class XmlDumper extends Dumper
|
||||
$service->setAttribute('autowire', 'true');
|
||||
}
|
||||
|
||||
foreach ($definition->getAutowiringTypes() as $autowiringTypeValue) {
|
||||
foreach ($definition->getAutowiringTypes(false) as $autowiringTypeValue) {
|
||||
$autowiringType = $this->document->createElement('autowiring-type');
|
||||
$autowiringType->appendChild($this->document->createTextNode($autowiringTypeValue));
|
||||
|
||||
$service->appendChild($autowiringType);
|
||||
}
|
||||
|
||||
if ($definition->isAutoconfigured()) {
|
||||
$service->setAttribute('autoconfigure', 'true');
|
||||
}
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
$service->setAttribute('abstract', 'true');
|
||||
}
|
||||
@@ -227,17 +220,15 @@ class XmlDumper extends Dumper
|
||||
/**
|
||||
* Adds a service alias.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param Alias $id
|
||||
* @param \DOMElement $parent
|
||||
* @param string $alias
|
||||
*/
|
||||
private function addServiceAlias($alias, Alias $id, \DOMElement $parent)
|
||||
{
|
||||
$service = $this->document->createElement('service');
|
||||
$service->setAttribute('id', $alias);
|
||||
$service->setAttribute('alias', $id);
|
||||
if (!$id->isPublic()) {
|
||||
$service->setAttribute('public', 'false');
|
||||
if (!$id->isPrivate()) {
|
||||
$service->setAttribute('public', $id->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
$parent->appendChild($service);
|
||||
}
|
||||
@@ -267,10 +258,8 @@ class XmlDumper extends Dumper
|
||||
/**
|
||||
* Converts parameters.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param string $type
|
||||
* @param \DOMElement $parent
|
||||
* @param string $keyAttribute
|
||||
* @param string $type
|
||||
* @param string $keyAttribute
|
||||
*/
|
||||
private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key')
|
||||
{
|
||||
@@ -281,20 +270,28 @@ class XmlDumper extends Dumper
|
||||
$element->setAttribute($keyAttribute, $key);
|
||||
}
|
||||
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$value = $value->getValues()[0];
|
||||
}
|
||||
if (\is_array($value)) {
|
||||
$element->setAttribute('type', 'collection');
|
||||
$this->convertParameters($value, $type, $element, 'key');
|
||||
} elseif ($value instanceof TaggedIteratorArgument) {
|
||||
$element->setAttribute('type', 'tagged');
|
||||
$element->setAttribute('tag', $value->getTag());
|
||||
} elseif ($value instanceof IteratorArgument) {
|
||||
$element->setAttribute('type', 'iterator');
|
||||
$this->convertParameters($value->getValues(), $type, $element, 'key');
|
||||
} elseif ($value instanceof Reference) {
|
||||
$element->setAttribute('type', 'service');
|
||||
$element->setAttribute('id', (string) $value);
|
||||
$behaviour = $value->getInvalidBehavior();
|
||||
if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behaviour) {
|
||||
$behavior = $value->getInvalidBehavior();
|
||||
if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behavior) {
|
||||
$element->setAttribute('on-invalid', 'null');
|
||||
} elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behaviour) {
|
||||
} elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behavior) {
|
||||
$element->setAttribute('on-invalid', 'ignore');
|
||||
}
|
||||
if (!$value->isStrict(false)) {
|
||||
$element->setAttribute('strict', 'false');
|
||||
} elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behavior) {
|
||||
$element->setAttribute('on-invalid', 'ignore_uninitialized');
|
||||
}
|
||||
} elseif ($value instanceof Definition) {
|
||||
$element->setAttribute('type', 'service');
|
||||
@@ -304,9 +301,14 @@ class XmlDumper extends Dumper
|
||||
$text = $this->document->createTextNode(self::phpToXml((string) $value));
|
||||
$element->appendChild($text);
|
||||
} else {
|
||||
if (\in_array($value, array('null', 'true', 'false'), true)) {
|
||||
if (\in_array($value, ['null', 'true', 'false'], true)) {
|
||||
$element->setAttribute('type', 'string');
|
||||
}
|
||||
|
||||
if (\is_string($value) && (is_numeric($value) || preg_match('/^0b[01]*$/', $value) || preg_match('/^0x[0-9a-f]++$/i', $value))) {
|
||||
$element->setAttribute('type', 'string');
|
||||
}
|
||||
|
||||
$text = $this->document->createTextNode(self::phpToXml($value));
|
||||
$element->appendChild($text);
|
||||
}
|
||||
@@ -321,7 +323,7 @@ class XmlDumper extends Dumper
|
||||
*/
|
||||
private function escape(array $arguments)
|
||||
{
|
||||
$args = array();
|
||||
$args = [];
|
||||
foreach ($arguments as $k => $v) {
|
||||
if (\is_array($v)) {
|
||||
$args[$k] = $this->escape($v);
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
@@ -19,6 +23,9 @@ use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\Yaml\Dumper as YmlDumper;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
use Symfony\Component\Yaml\Tag\TaggedValue;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* YamlDumper dumps a service container as a YAML string.
|
||||
@@ -34,7 +41,7 @@ class YamlDumper extends Dumper
|
||||
*
|
||||
* @return string A YAML string representing of the service container
|
||||
*/
|
||||
public function dump(array $options = array())
|
||||
public function dump(array $options = [])
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Yaml\Dumper')) {
|
||||
throw new RuntimeException('Unable to dump the container as the Symfony Yaml Component is not installed.');
|
||||
@@ -44,14 +51,13 @@ class YamlDumper extends Dumper
|
||||
$this->dumper = new YmlDumper();
|
||||
}
|
||||
|
||||
return $this->addParameters()."\n".$this->addServices();
|
||||
return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a service.
|
||||
*
|
||||
* @param string $id
|
||||
* @param Definition $definition
|
||||
* @param string $id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -66,14 +72,14 @@ class YamlDumper extends Dumper
|
||||
$code .= sprintf(" class: %s\n", $this->dumper->dump($class));
|
||||
}
|
||||
|
||||
if (!$definition->isPublic()) {
|
||||
$code .= " public: false\n";
|
||||
if (!$definition->isPrivate()) {
|
||||
$code .= sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
$tagsCode = '';
|
||||
foreach ($definition->getTags() as $name => $tags) {
|
||||
foreach ($tags as $attributes) {
|
||||
$att = array();
|
||||
$att = [];
|
||||
foreach ($attributes as $key => $value) {
|
||||
$att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
|
||||
}
|
||||
@@ -94,10 +100,6 @@ class YamlDumper extends Dumper
|
||||
$code .= " synthetic: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isSynchronized(false)) {
|
||||
$code .= " synchronized: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isDeprecated()) {
|
||||
$code .= sprintf(" deprecated: %s\n", $this->dumper->dump($definition->getDeprecationMessage('%service_id%')));
|
||||
}
|
||||
@@ -107,15 +109,15 @@ class YamlDumper extends Dumper
|
||||
}
|
||||
|
||||
$autowiringTypesCode = '';
|
||||
foreach ($definition->getAutowiringTypes() as $autowiringType) {
|
||||
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
|
||||
$autowiringTypesCode .= sprintf(" - %s\n", $this->dumper->dump($autowiringType));
|
||||
}
|
||||
if ($autowiringTypesCode) {
|
||||
$code .= sprintf(" autowiring_types:\n%s", $autowiringTypesCode);
|
||||
}
|
||||
|
||||
if ($definition->getFactoryClass(false)) {
|
||||
$code .= sprintf(" factory_class: %s\n", $this->dumper->dump($definition->getFactoryClass(false)));
|
||||
if ($definition->isAutoconfigured()) {
|
||||
$code .= " autoconfigure: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
@@ -126,14 +128,6 @@ class YamlDumper extends Dumper
|
||||
$code .= " lazy: true\n";
|
||||
}
|
||||
|
||||
if ($definition->getFactoryMethod(false)) {
|
||||
$code .= sprintf(" factory_method: %s\n", $this->dumper->dump($definition->getFactoryMethod(false)));
|
||||
}
|
||||
|
||||
if ($definition->getFactoryService(false)) {
|
||||
$code .= sprintf(" factory_service: %s\n", $this->dumper->dump($definition->getFactoryService(false)));
|
||||
}
|
||||
|
||||
if ($definition->getArguments()) {
|
||||
$code .= sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
|
||||
}
|
||||
@@ -150,10 +144,6 @@ class YamlDumper extends Dumper
|
||||
$code .= " shared: false\n";
|
||||
}
|
||||
|
||||
if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
|
||||
$code .= sprintf(" scope: %s\n", $this->dumper->dump($scope));
|
||||
}
|
||||
|
||||
if (null !== $decorated = $definition->getDecoratedService()) {
|
||||
list($decorated, $renamedId, $priority) = $decorated;
|
||||
$code .= sprintf(" decorates: %s\n", $decorated);
|
||||
@@ -180,17 +170,16 @@ class YamlDumper extends Dumper
|
||||
* Adds a service alias.
|
||||
*
|
||||
* @param string $alias
|
||||
* @param Alias $id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function addServiceAlias($alias, Alias $id)
|
||||
{
|
||||
if ($id->isPublic()) {
|
||||
if ($id->isPrivate()) {
|
||||
return sprintf(" %s: '@%s'\n", $alias, $id);
|
||||
}
|
||||
|
||||
return sprintf(" %s:\n alias: %s\n public: false\n", $alias, $id);
|
||||
return sprintf(" %s:\n alias: %s\n public: %s\n", $alias, $id, $id->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,25 +220,23 @@ class YamlDumper extends Dumper
|
||||
return '';
|
||||
}
|
||||
|
||||
$parameters = $this->prepareParameters($this->container->getParameterBag()->all(), $this->container->isFrozen());
|
||||
$parameters = $this->prepareParameters($this->container->getParameterBag()->all(), $this->container->isCompiled());
|
||||
|
||||
return $this->dumper->dump(array('parameters' => $parameters), 2);
|
||||
return $this->dumper->dump(['parameters' => $parameters], 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps callable to YAML format.
|
||||
*
|
||||
* @param callable $callable
|
||||
*
|
||||
* @return callable
|
||||
* @param mixed $callable
|
||||
*/
|
||||
private function dumpCallable($callable)
|
||||
{
|
||||
if (\is_array($callable)) {
|
||||
if ($callable[0] instanceof Reference) {
|
||||
$callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]);
|
||||
$callable = [$this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]];
|
||||
} else {
|
||||
$callable = array($callable[0], $callable[1]);
|
||||
$callable = [$callable[0], $callable[1]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,8 +254,24 @@ class YamlDumper extends Dumper
|
||||
*/
|
||||
private function dumpValue($value)
|
||||
{
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$value = $value->getValues()[0];
|
||||
}
|
||||
if ($value instanceof ArgumentInterface) {
|
||||
if ($value instanceof TaggedIteratorArgument) {
|
||||
return new TaggedValue('tagged', $value->getTag());
|
||||
}
|
||||
if ($value instanceof IteratorArgument) {
|
||||
$tag = 'iterator';
|
||||
} else {
|
||||
throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', \get_class($value)));
|
||||
}
|
||||
|
||||
return new TaggedValue($tag, $this->dumpValue($value->getValues()));
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
$code = array();
|
||||
$code = [];
|
||||
foreach ($value as $k => $v) {
|
||||
$code[$k] = $this->dumpValue($v);
|
||||
}
|
||||
@@ -280,6 +283,8 @@ class YamlDumper extends Dumper
|
||||
return $this->getParameterCall((string) $value);
|
||||
} elseif ($value instanceof Expression) {
|
||||
return $this->getExpressionCall((string) $value);
|
||||
} elseif ($value instanceof Definition) {
|
||||
return new TaggedValue('service', (new Parser())->parse("_:\n".$this->addService('_', $value), Yaml::PARSE_CUSTOM_TAGS)['_']['_']);
|
||||
} elseif (\is_object($value) || \is_resource($value)) {
|
||||
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
|
||||
}
|
||||
@@ -297,8 +302,12 @@ class YamlDumper extends Dumper
|
||||
*/
|
||||
private function getServiceCall($id, Reference $reference = null)
|
||||
{
|
||||
if (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
|
||||
return sprintf('@?%s', $id);
|
||||
if (null !== $reference) {
|
||||
switch ($reference->getInvalidBehavior()) {
|
||||
case ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE: break;
|
||||
case ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE: return sprintf('@!%s', $id);
|
||||
default: return sprintf('@?%s', $id);
|
||||
}
|
||||
}
|
||||
|
||||
return sprintf('@%s', $id);
|
||||
@@ -324,14 +333,13 @@ class YamlDumper extends Dumper
|
||||
/**
|
||||
* Prepares parameters.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param bool $escape
|
||||
* @param bool $escape
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function prepareParameters(array $parameters, $escape = true)
|
||||
{
|
||||
$filtered = array();
|
||||
$filtered = [];
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (\is_array($value)) {
|
||||
$value = $this->prepareParameters($value, $escape);
|
||||
@@ -352,7 +360,7 @@ class YamlDumper extends Dumper
|
||||
*/
|
||||
private function escape(array $arguments)
|
||||
{
|
||||
$args = array();
|
||||
$args = [];
|
||||
foreach ($arguments as $k => $v) {
|
||||
if (\is_array($v)) {
|
||||
$args[$k] = $this->escape($v);
|
||||
|
||||
Reference in New Issue
Block a user