Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -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);