init
This commit is contained in:
27
backend/vendor/symfony/dependency-injection/Dumper/Dumper.php
vendored
Normal file
27
backend/vendor/symfony/dependency-injection/Dumper/Dumper.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Dumper is the abstract class for all built-in dumpers.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class Dumper implements DumperInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected ContainerBuilder $container,
|
||||
) {
|
||||
}
|
||||
}
|
||||
25
backend/vendor/symfony/dependency-injection/Dumper/DumperInterface.php
vendored
Normal file
25
backend/vendor/symfony/dependency-injection/Dumper/DumperInterface.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
/**
|
||||
* DumperInterface is the interface implemented by service container dumper classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface DumperInterface
|
||||
{
|
||||
/**
|
||||
* Dumps the service container.
|
||||
*/
|
||||
public function dump(array $options = []): string|array;
|
||||
}
|
||||
249
backend/vendor/symfony/dependency-injection/Dumper/GraphvizDumper.php
vendored
Normal file
249
backend/vendor/symfony/dependency-injection/Dumper/GraphvizDumper.php
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
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;
|
||||
|
||||
/**
|
||||
* GraphvizDumper dumps a service container as a graphviz file.
|
||||
*
|
||||
* You can convert the generated dot file with the dot utility (http://www.graphviz.org/):
|
||||
*
|
||||
* dot -Tpng container.dot > foo.png
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class GraphvizDumper extends Dumper
|
||||
{
|
||||
private array $nodes;
|
||||
private array $edges;
|
||||
// All values should be strings
|
||||
private array $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.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * graph: The default options for the whole graph
|
||||
* * node: The default options for nodes
|
||||
* * edge: The default options for edges
|
||||
* * node.instance: The default options for services that are defined directly by object instances
|
||||
* * node.definition: The default options for services that are defined via service definition instances
|
||||
* * node.missing: The default options for missing services
|
||||
*/
|
||||
public function dump(array $options = []): string
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->nodes = $this->findNodes();
|
||||
|
||||
$this->edges = [];
|
||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||
$this->edges[$id] = array_merge(
|
||||
$this->findEdges($id, $definition->getArguments(), true, ''),
|
||||
$this->findEdges($id, $definition->getProperties(), false, '')
|
||||
);
|
||||
|
||||
foreach ($definition->getMethodCalls() as $call) {
|
||||
$this->edges[$id] = array_merge(
|
||||
$this->edges[$id],
|
||||
$this->findEdges($id, $call[1], false, $call[0].'()')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($this->startDot().$this->addNodes().$this->addEdges().$this->endDot(), '__ENV_%s__');
|
||||
}
|
||||
|
||||
private function addNodes(): string
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->nodes as $id => $node) {
|
||||
$aliases = $this->getAliases($id);
|
||||
|
||||
$code .= \sprintf(" node_%s [label=\"%s\\n%s\\n\", shape=%s%s];\n", $this->dotize($id), $id.($aliases ? ' ('.implode(', ', $aliases).')' : ''), $node['class'], $this->options['node']['shape'], $this->addAttributes($node['attributes']));
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
private function addEdges(): string
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->edges as $id => $edges) {
|
||||
foreach ($edges as $edge) {
|
||||
$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"' : '');
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all edges belonging to a specific service id.
|
||||
*/
|
||||
private function findEdges(string $id, array $arguments, bool $required, string $name, bool $lazy = false): array
|
||||
{
|
||||
$edges = [];
|
||||
foreach ($arguments as $argument) {
|
||||
if ($argument instanceof Parameter) {
|
||||
$argument = $this->container->hasParameter($argument) ? $this->container->getParameter($argument) : null;
|
||||
} elseif (\is_string($argument) && preg_match('/^%([^%]+)%$/', $argument, $match)) {
|
||||
$argument = $this->container->hasParameter($match[1]) ? $this->container->getParameter($match[1]) : null;
|
||||
}
|
||||
|
||||
if ($argument instanceof Reference) {
|
||||
$lazyEdge = $lazy;
|
||||
|
||||
if (!$this->container->has((string) $argument)) {
|
||||
$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[] = [['name' => $name, 'required' => $required, 'to' => $argument, 'lazy' => $lazyEdge]];
|
||||
} elseif ($argument instanceof ArgumentInterface) {
|
||||
$edges[] = $this->findEdges($id, $argument->getValues(), $required, $name, true);
|
||||
} elseif ($argument instanceof Definition) {
|
||||
$edges[] = $this->findEdges($id, $argument->getArguments(), $required, '');
|
||||
$edges[] = $this->findEdges($id, $argument->getProperties(), false, '');
|
||||
|
||||
foreach ($argument->getMethodCalls() as $call) {
|
||||
$edges[] = $this->findEdges($id, $call[1], false, $call[0].'()');
|
||||
}
|
||||
} elseif (\is_array($argument)) {
|
||||
$edges[] = $this->findEdges($id, $argument, $required, $name, $lazy);
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge([], ...$edges);
|
||||
}
|
||||
|
||||
private function findNodes(): array
|
||||
{
|
||||
$nodes = [];
|
||||
|
||||
$container = $this->cloneContainer();
|
||||
|
||||
foreach ($container->getDefinitions() as $id => $definition) {
|
||||
$class = $definition->getClass();
|
||||
|
||||
if (str_starts_with($class, '\\')) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
try {
|
||||
$class = $this->container->getParameterBag()->resolveValue($class);
|
||||
} catch (ParameterNotFoundException) {
|
||||
}
|
||||
|
||||
$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) {
|
||||
if (\array_key_exists($id, $container->getAliases())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$container->hasDefinition($id)) {
|
||||
$nodes[$id] = ['class' => str_replace('\\', '\\\\', $container->get($id)::class), 'attributes' => $this->options['node.instance']];
|
||||
}
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
private function cloneContainer(): ContainerBuilder
|
||||
{
|
||||
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
|
||||
|
||||
$container = new ContainerBuilder($parameterBag);
|
||||
$container->setDefinitions($this->container->getDefinitions());
|
||||
$container->setAliases($this->container->getAliases());
|
||||
$container->setResources($this->container->getResources());
|
||||
foreach ($this->container->getExtensions() as $extension) {
|
||||
$container->registerExtension($extension);
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
private function startDot(): string
|
||||
{
|
||||
return \sprintf("digraph sc {\n %s\n node [%s];\n edge [%s];\n\n",
|
||||
$this->addOptions($this->options['graph']),
|
||||
$this->addOptions($this->options['node']),
|
||||
$this->addOptions($this->options['edge'])
|
||||
);
|
||||
}
|
||||
|
||||
private function endDot(): string
|
||||
{
|
||||
return "}\n";
|
||||
}
|
||||
|
||||
private function addAttributes(array $attributes): string
|
||||
{
|
||||
$code = [];
|
||||
foreach ($attributes as $k => $v) {
|
||||
$code[] = \sprintf('%s="%s"', $k, $v);
|
||||
}
|
||||
|
||||
return $code ? ', '.implode(', ', $code) : '';
|
||||
}
|
||||
|
||||
private function addOptions(array $options): string
|
||||
{
|
||||
$code = [];
|
||||
foreach ($options as $k => $v) {
|
||||
$code[] = \sprintf('%s="%s"', $k, $v);
|
||||
}
|
||||
|
||||
return implode(' ', $code);
|
||||
}
|
||||
|
||||
private function dotize(string $id): string
|
||||
{
|
||||
return preg_replace('/\W/i', '_', $id);
|
||||
}
|
||||
|
||||
private function getAliases(string $id): array
|
||||
{
|
||||
$aliases = [];
|
||||
foreach ($this->container->getAliases() as $alias => $origin) {
|
||||
if ($id == $origin) {
|
||||
$aliases[] = $alias;
|
||||
}
|
||||
}
|
||||
|
||||
return $aliases;
|
||||
}
|
||||
}
|
||||
2438
backend/vendor/symfony/dependency-injection/Dumper/PhpDumper.php
vendored
Normal file
2438
backend/vendor/symfony/dependency-injection/Dumper/PhpDumper.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
129
backend/vendor/symfony/dependency-injection/Dumper/Preloader.php
vendored
Normal file
129
backend/vendor/symfony/dependency-injection/Dumper/Preloader.php
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
final class Preloader
|
||||
{
|
||||
public static function append(string $file, array $list): void
|
||||
{
|
||||
if (!file_exists($file)) {
|
||||
throw new \LogicException(\sprintf('File "%s" does not exist.', $file));
|
||||
}
|
||||
|
||||
$cacheDir = \dirname($file);
|
||||
$classes = [];
|
||||
|
||||
foreach ($list as $item) {
|
||||
if (str_starts_with($item, $cacheDir)) {
|
||||
file_put_contents($file, \sprintf("require_once __DIR__.%s;\n", var_export(strtr(substr($item, \strlen($cacheDir)), \DIRECTORY_SEPARATOR, '/'), true)), \FILE_APPEND);
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes[] = \sprintf("\$classes[] = %s;\n", var_export($item, true));
|
||||
}
|
||||
|
||||
file_put_contents($file, \sprintf("\n\$classes = [];\n%s\$preloaded = Preloader::preload(\$classes, \$preloaded);\n", implode('', $classes)), \FILE_APPEND);
|
||||
}
|
||||
|
||||
public static function preload(array $classes, array $preloaded = []): array
|
||||
{
|
||||
set_error_handler(function ($t, $m, $f, $l) {
|
||||
if (error_reporting() & $t) {
|
||||
if (__FILE__ !== $f) {
|
||||
throw new \ErrorException($m, 0, $t, $f, $l);
|
||||
}
|
||||
|
||||
throw new \ReflectionException($m);
|
||||
}
|
||||
});
|
||||
|
||||
$prev = [];
|
||||
|
||||
try {
|
||||
while ($prev !== $classes) {
|
||||
$prev = $classes;
|
||||
foreach ($classes as $c) {
|
||||
if (!isset($preloaded[$c])) {
|
||||
self::doPreload($c, $preloaded);
|
||||
}
|
||||
}
|
||||
$classes = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
|
||||
}
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
return $preloaded;
|
||||
}
|
||||
|
||||
private static function doPreload(string $class, array &$preloaded): void
|
||||
{
|
||||
if (isset($preloaded[$class]) || \in_array($class, ['self', 'static', 'parent'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$preloaded[$class] = true;
|
||||
|
||||
try {
|
||||
if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$r = new \ReflectionClass($class);
|
||||
|
||||
if ($r->isInternal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$r->getConstants();
|
||||
$r->getDefaultProperties();
|
||||
|
||||
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
|
||||
self::preloadType($p->getType(), $preloaded);
|
||||
}
|
||||
|
||||
foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
|
||||
foreach ($m->getParameters() as $p) {
|
||||
if ($p->isDefaultValueAvailable() && $p->isDefaultValueConstant()) {
|
||||
$c = $p->getDefaultValueConstantName();
|
||||
|
||||
if ($i = strpos($c, '::')) {
|
||||
self::doPreload(substr($c, 0, $i), $preloaded);
|
||||
}
|
||||
}
|
||||
|
||||
self::preloadType($p->getType(), $preloaded);
|
||||
}
|
||||
|
||||
self::preloadType($m->getReturnType(), $preloaded);
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
// ignore missing classes
|
||||
}
|
||||
}
|
||||
|
||||
private static function preloadType(?\ReflectionType $t, array &$preloaded): void
|
||||
{
|
||||
if (!$t) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (($t instanceof \ReflectionUnionType || $t instanceof \ReflectionIntersectionType) ? $t->getTypes() : [$t] as $t) {
|
||||
if (!$t->isBuiltin()) {
|
||||
self::doPreload($t instanceof \ReflectionNamedType ? $t->getName() : $t, $preloaded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
441
backend/vendor/symfony/dependency-injection/Dumper/XmlDumper.php
vendored
Normal file
441
backend/vendor/symfony/dependency-injection/Dumper/XmlDumper.php
vendored
Normal file
@@ -0,0 +1,441 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
|
||||
/**
|
||||
* XmlDumper dumps a service container as an XML string.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Martin Hasoň <martin.hason@gmail.com>
|
||||
*/
|
||||
class XmlDumper extends Dumper
|
||||
{
|
||||
/**
|
||||
* Dumps the service container as an XML string.
|
||||
*/
|
||||
public function dump(array $options = []): string
|
||||
{
|
||||
$xml = <<<EOXML
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
EOXML;
|
||||
|
||||
foreach ($this->addParameters() as $line) {
|
||||
$xml .= "\n ".$line;
|
||||
}
|
||||
foreach ($this->addServices() as $line) {
|
||||
$xml .= "\n ".$line;
|
||||
}
|
||||
|
||||
$xml .= "\n</container>\n";
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($xml);
|
||||
}
|
||||
|
||||
private function addParameters(): iterable
|
||||
{
|
||||
if (!$data = $this->container->getParameterBag()->all()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->container->isCompiled()) {
|
||||
$data = $this->escape($data);
|
||||
}
|
||||
|
||||
yield '<parameters>';
|
||||
foreach ($this->convertParameters($data, 'parameter') as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
yield '</parameters>';
|
||||
}
|
||||
|
||||
private function addMethodCalls(array $methodcalls): iterable
|
||||
{
|
||||
foreach ($methodcalls as $methodcall) {
|
||||
$xmlAttr = \sprintf(' method="%s"%s', $this->encode($methodcall[0]), ($methodcall[2] ?? false) ? ' returns-clone="true"' : '');
|
||||
|
||||
if ($methodcall[1]) {
|
||||
yield \sprintf('<call%s>', $xmlAttr);
|
||||
foreach ($this->convertParameters($methodcall[1], 'argument') as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
yield '</call>';
|
||||
} else {
|
||||
yield \sprintf('<call%s/>', $xmlAttr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function addService(Definition $definition, ?string $id): iterable
|
||||
{
|
||||
$xmlAttr = '';
|
||||
if (null !== $id) {
|
||||
$xmlAttr .= \sprintf(' id="%s"', $this->encode($id));
|
||||
}
|
||||
if ($class = $definition->getClass()) {
|
||||
if (str_starts_with($class, '\\')) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
$xmlAttr .= \sprintf(' class="%s"', $this->encode($class));
|
||||
}
|
||||
if (!$definition->isShared()) {
|
||||
$xmlAttr .= ' shared="false"';
|
||||
}
|
||||
if ($definition->isPublic()) {
|
||||
$xmlAttr .= ' public="true"';
|
||||
}
|
||||
if ($definition->isSynthetic()) {
|
||||
$xmlAttr .= ' synthetic="true"';
|
||||
}
|
||||
if ($definition->isLazy()) {
|
||||
$xmlAttr .= ' lazy="true"';
|
||||
}
|
||||
if (null !== $decoratedService = $definition->getDecoratedService()) {
|
||||
[$decorated, $renamedId, $priority] = $decoratedService;
|
||||
$xmlAttr .= \sprintf(' decorates="%s"', $this->encode($decorated));
|
||||
|
||||
$decorationOnInvalid = $decoratedService[3] ?? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
if (\in_array($decorationOnInvalid, [ContainerInterface::IGNORE_ON_INVALID_REFERENCE, ContainerInterface::NULL_ON_INVALID_REFERENCE], true)) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE === $decorationOnInvalid ? 'null' : 'ignore';
|
||||
$xmlAttr .= \sprintf(' decoration-on-invalid="%s"', $invalidBehavior);
|
||||
}
|
||||
if (null !== $renamedId) {
|
||||
$xmlAttr .= \sprintf(' decoration-inner-name="%s"', $this->encode($renamedId));
|
||||
}
|
||||
if (0 !== $priority) {
|
||||
$xmlAttr .= \sprintf(' decoration-priority="%d"', $priority);
|
||||
}
|
||||
}
|
||||
|
||||
$xml = [];
|
||||
|
||||
$tags = $definition->getTags();
|
||||
$tags['container.error'] = array_map(fn ($e) => ['message' => $e], $definition->getErrors());
|
||||
foreach ($tags as $name => $tags) {
|
||||
foreach ($tags as $attributes) {
|
||||
// Check if we have recursive attributes
|
||||
if (array_filter($attributes, \is_array(...))) {
|
||||
$xml[] = \sprintf(' <tag name="%s">', $this->encode($name));
|
||||
foreach ($this->addTagRecursiveAttributes($attributes) as $line) {
|
||||
$xml[] = ' '.$line;
|
||||
}
|
||||
$xml[] = ' </tag>';
|
||||
} else {
|
||||
$hasNameAttr = \array_key_exists('name', $attributes);
|
||||
$attr = \sprintf(' name="%s"', $this->encode($hasNameAttr ? $attributes['name'] : $name));
|
||||
foreach ($attributes as $key => $value) {
|
||||
if ('name' !== $key) {
|
||||
$attr .= \sprintf(' %s="%s"', $this->encode($key), $this->encode(self::phpToXml($value ?? '')));
|
||||
}
|
||||
}
|
||||
if ($hasNameAttr) {
|
||||
$xml[] = \sprintf(' <tag%s>%s</tag>', $attr, $this->encode($name, 0));
|
||||
} else {
|
||||
$xml[] = \sprintf(' <tag%s/>', $attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition->getFile()) {
|
||||
$xml[] = \sprintf(' <file>%s</file>', $this->encode($definition->getFile(), 0));
|
||||
}
|
||||
|
||||
foreach ($this->convertParameters($definition->getArguments(), 'argument') as $line) {
|
||||
$xml[] = ' '.$line;
|
||||
}
|
||||
|
||||
foreach ($this->convertParameters($definition->getProperties(), 'property', 'name') as $line) {
|
||||
$xml[] = ' '.$line;
|
||||
}
|
||||
|
||||
foreach ($this->addMethodCalls($definition->getMethodCalls()) as $line) {
|
||||
$xml[] = ' '.$line;
|
||||
}
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
if (\is_array($callable) && ['Closure', 'fromCallable'] !== $callable && $definition->getClass() === $callable[0]) {
|
||||
$xmlAttr .= \sprintf(' constructor="%s"', $this->encode($callable[1]));
|
||||
} else {
|
||||
if (\is_array($callable) && $callable[0] instanceof Definition) {
|
||||
$xml[] = \sprintf(' <factory method="%s">', $this->encode($callable[1]));
|
||||
foreach ($this->addService($callable[0], null) as $line) {
|
||||
$xml[] = ' '.$line;
|
||||
}
|
||||
$xml[] = ' </factory>';
|
||||
} elseif (\is_array($callable)) {
|
||||
if (null !== $callable[0]) {
|
||||
$xml[] = \sprintf(' <factory %s="%s" method="%s"/>', $callable[0] instanceof Reference ? 'service' : 'class', $this->encode($callable[0]), $this->encode($callable[1]));
|
||||
} else {
|
||||
$xml[] = \sprintf(' <factory method="%s"/>', $this->encode($callable[1]));
|
||||
}
|
||||
} else {
|
||||
$xml[] = \sprintf(' <factory function="%s"/>', $this->encode($callable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition->isDeprecated()) {
|
||||
$deprecation = $definition->getDeprecation('%service_id%');
|
||||
$xml[] = \sprintf(' <deprecated package="%s" version="%s">%s</deprecated>', $this->encode($deprecation['package']), $this->encode($deprecation['version']), $this->encode($deprecation['message'], 0));
|
||||
}
|
||||
|
||||
if ($definition->isAutowired()) {
|
||||
$xmlAttr .= ' autowire="true"';
|
||||
}
|
||||
|
||||
if ($definition->isAutoconfigured()) {
|
||||
$xmlAttr .= ' autoconfigure="true"';
|
||||
}
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
$xmlAttr .= ' abstract="true"';
|
||||
}
|
||||
|
||||
if ($callable = $definition->getConfigurator()) {
|
||||
if (\is_array($callable) && $callable[0] instanceof Definition) {
|
||||
$xml[] = \sprintf(' <configurator method="%s">', $this->encode($callable[1]));
|
||||
foreach ($this->addService($callable[0], null) as $line) {
|
||||
$xml[] = ' '.$line;
|
||||
}
|
||||
$xml[] = ' </configurator>';
|
||||
} elseif (\is_array($callable)) {
|
||||
$xml[] = \sprintf(' <configurator %s="%s" method="%s"/>', $callable[0] instanceof Reference ? 'service' : 'class', $this->encode($callable[0]), $this->encode($callable[1]));
|
||||
} else {
|
||||
$xml[] = \sprintf(' <configurator function="%s"/>', $this->encode($callable));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$xml) {
|
||||
yield \sprintf('<service%s/>', $xmlAttr);
|
||||
} else {
|
||||
yield \sprintf('<service%s>', $xmlAttr);
|
||||
yield from $xml;
|
||||
yield '</service>';
|
||||
}
|
||||
}
|
||||
|
||||
private function addServiceAlias(string $alias, Alias $id): iterable
|
||||
{
|
||||
$xmlAttr = \sprintf(' id="%s" alias="%s"%s', $this->encode($alias), $this->encode($id), $id->isPublic() ? ' public="true"' : '');
|
||||
|
||||
if ($id->isDeprecated()) {
|
||||
$deprecation = $id->getDeprecation('%alias_id%');
|
||||
yield \sprintf('<service%s>', $xmlAttr);
|
||||
yield \sprintf(' <deprecated package="%s" version="%s">%s</deprecated>', $this->encode($deprecation['package']), $this->encode($deprecation['version']), $this->encode($deprecation['message'], 0));
|
||||
yield '</service>';
|
||||
} else {
|
||||
yield \sprintf('<service%s/>', $xmlAttr);
|
||||
}
|
||||
}
|
||||
|
||||
private function addServices(): iterable
|
||||
{
|
||||
if (!$definitions = $this->container->getDefinitions()) {
|
||||
return;
|
||||
}
|
||||
|
||||
yield '<services>';
|
||||
foreach ($definitions as $id => $definition) {
|
||||
foreach ($this->addService($definition, $id) as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
}
|
||||
|
||||
$aliases = $this->container->getAliases();
|
||||
foreach ($aliases as $alias => $id) {
|
||||
while (isset($aliases[(string) $id])) {
|
||||
$id = $aliases[(string) $id];
|
||||
}
|
||||
foreach ($this->addServiceAlias($alias, $id) as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
}
|
||||
yield '</services>';
|
||||
}
|
||||
|
||||
private function addTagRecursiveAttributes(array $attributes): iterable
|
||||
{
|
||||
foreach ($attributes as $name => $value) {
|
||||
if (\is_array($value)) {
|
||||
yield \sprintf('<attribute name="%s">', $this->encode($name));
|
||||
foreach ($this->addTagRecursiveAttributes($value) as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
yield '</attribute>';
|
||||
} elseif ('' !== $value = self::phpToXml($value ?? '')) {
|
||||
yield \sprintf('<attribute name="%s">%s</attribute>', $this->encode($name), $this->encode($value, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function convertParameters(array $parameters, string $type, string $keyAttribute = 'key'): iterable
|
||||
{
|
||||
$withKeys = !array_is_list($parameters);
|
||||
foreach ($parameters as $key => $value) {
|
||||
$xmlAttr = $withKeys ? \sprintf(' %s="%s"', $keyAttribute, $this->encode($key)) : '';
|
||||
|
||||
if (($value instanceof TaggedIteratorArgument && $tag = $value)
|
||||
|| ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())
|
||||
) {
|
||||
$xmlAttr .= \sprintf(' type="%s"', $value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator');
|
||||
$xmlAttr .= \sprintf(' tag="%s"', $this->encode($tag->getTag()));
|
||||
|
||||
if (null !== $tag->getIndexAttribute()) {
|
||||
$xmlAttr .= \sprintf(' index-by="%s"', $this->encode($tag->getIndexAttribute()));
|
||||
|
||||
if (null !== $tag->getDefaultIndexMethod()) {
|
||||
$xmlAttr .= \sprintf(' default-index-method="%s"', $this->encode($tag->getDefaultIndexMethod()));
|
||||
}
|
||||
if (null !== $tag->getDefaultPriorityMethod()) {
|
||||
$xmlAttr .= \sprintf(' default-priority-method="%s"', $this->encode($tag->getDefaultPriorityMethod()));
|
||||
}
|
||||
}
|
||||
if (1 === \count($excludes = $tag->getExclude())) {
|
||||
$xmlAttr .= \sprintf(' exclude="%s"', $this->encode($excludes[0]));
|
||||
}
|
||||
if (!$tag->excludeSelf()) {
|
||||
$xmlAttr .= ' exclude-self="false"';
|
||||
}
|
||||
|
||||
if (1 < \count($excludes)) {
|
||||
yield \sprintf('<%s%s>', $type, $xmlAttr);
|
||||
foreach ($excludes as $exclude) {
|
||||
yield \sprintf(' <exclude>%s</exclude>', $this->encode($exclude, 0));
|
||||
}
|
||||
yield \sprintf('</%s>', $type);
|
||||
} else {
|
||||
yield \sprintf('<%s%s/>', $type, $xmlAttr);
|
||||
}
|
||||
} elseif (match (true) {
|
||||
\is_array($value) && $xmlAttr .= ' type="collection"' => true,
|
||||
$value instanceof IteratorArgument && $xmlAttr .= ' type="iterator"' => true,
|
||||
$value instanceof ServiceLocatorArgument && $xmlAttr .= ' type="service_locator"' => true,
|
||||
$value instanceof ServiceClosureArgument && !$value->getValues()[0] instanceof Reference && $xmlAttr .= ' type="service_closure"' => true,
|
||||
default => false,
|
||||
}) {
|
||||
if ($value instanceof ArgumentInterface) {
|
||||
$value = $value->getValues();
|
||||
}
|
||||
if ($value) {
|
||||
yield \sprintf('<%s%s>', $type, $xmlAttr);
|
||||
foreach ($this->convertParameters($value, $type, 'key') as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
yield \sprintf('</%s>', $type);
|
||||
} else {
|
||||
yield \sprintf('<%s%s/>', $type, $xmlAttr);
|
||||
}
|
||||
} elseif ($value instanceof Reference || $value instanceof ServiceClosureArgument) {
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$xmlAttr .= ' type="service_closure"';
|
||||
$value = $value->getValues()[0];
|
||||
} else {
|
||||
$xmlAttr .= ' type="service"';
|
||||
}
|
||||
$xmlAttr .= \sprintf(' id="%s"', $this->encode((string) $value));
|
||||
$xmlAttr .= match ($value->getInvalidBehavior()) {
|
||||
ContainerInterface::NULL_ON_INVALID_REFERENCE => ' on-invalid="null"',
|
||||
ContainerInterface::IGNORE_ON_INVALID_REFERENCE => ' on-invalid="ignore"',
|
||||
ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE => ' on-invalid="ignore_uninitialized"',
|
||||
default => '',
|
||||
};
|
||||
|
||||
yield \sprintf('<%s%s/>', $type, $xmlAttr);
|
||||
} elseif ($value instanceof Definition) {
|
||||
$xmlAttr .= ' type="service"';
|
||||
|
||||
yield \sprintf('<%s%s>', $type, $xmlAttr);
|
||||
foreach ($this->addService($value, null) as $line) {
|
||||
yield ' '.$line;
|
||||
}
|
||||
yield \sprintf('</%s>', $type);
|
||||
} else {
|
||||
if ($value instanceof Expression) {
|
||||
$xmlAttr .= ' type="expression"';
|
||||
$value = (string) $value;
|
||||
} elseif (\is_string($value) && !preg_match('/^[^\x00-\x08\x0B\x0C\x0E-\x1F\x7F]*+$/u', $value)) {
|
||||
$xmlAttr .= ' type="binary"';
|
||||
$value = base64_encode($value);
|
||||
} elseif ($value instanceof \UnitEnum) {
|
||||
$xmlAttr .= ' type="constant"';
|
||||
} elseif ($value instanceof AbstractArgument) {
|
||||
$xmlAttr .= ' type="abstract"';
|
||||
$value = $value->getText();
|
||||
} elseif (\in_array($value, ['null', 'true', 'false'], true)) {
|
||||
$xmlAttr .= ' type="string"';
|
||||
} elseif (\is_string($value) && (is_numeric($value) || preg_match('/^0b[01]*$/', $value) || preg_match('/^0x[0-9a-f]++$/i', $value))) {
|
||||
$xmlAttr .= ' type="string"';
|
||||
}
|
||||
|
||||
if ('' === $value = self::phpToXml($value)) {
|
||||
yield \sprintf('<%s%s/>', $type, $xmlAttr);
|
||||
} else {
|
||||
yield \sprintf('<%s%s>%s</%1$s>', $type, $xmlAttr, $this->encode($value, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function encode(string $value, int $flags = \ENT_COMPAT): string
|
||||
{
|
||||
return str_replace("\r", ' ', htmlspecialchars($value, \ENT_XML1 | \ENT_SUBSTITUTE | $flags, 'UTF-8'));
|
||||
}
|
||||
|
||||
private function escape(array $arguments): array
|
||||
{
|
||||
$args = [];
|
||||
foreach ($arguments as $k => $v) {
|
||||
$args[$k] = match (true) {
|
||||
\is_array($v) => $this->escape($v),
|
||||
\is_string($v) => str_replace('%', '%%', $v),
|
||||
default => $v,
|
||||
};
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts php types to xml types.
|
||||
*
|
||||
* @throws RuntimeException When trying to dump object or resource
|
||||
*/
|
||||
public static function phpToXml(mixed $value): string
|
||||
{
|
||||
return match (true) {
|
||||
null === $value => 'null',
|
||||
true === $value => 'true',
|
||||
false === $value => 'false',
|
||||
$value instanceof Parameter => '%'.$value.'%',
|
||||
$value instanceof \UnitEnum => \sprintf('%s::%s', $value::class, $value->name),
|
||||
\is_object($value),
|
||||
\is_resource($value) => throw new RuntimeException(\sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value))),
|
||||
default => (string) $value,
|
||||
};
|
||||
}
|
||||
}
|
||||
380
backend/vendor/symfony/dependency-injection/Dumper/YamlDumper.php
vendored
Normal file
380
backend/vendor/symfony/dependency-injection/Dumper/YamlDumper.php
vendored
Normal file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
|
||||
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
|
||||
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
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.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class YamlDumper extends Dumper
|
||||
{
|
||||
private YmlDumper $dumper;
|
||||
|
||||
/**
|
||||
* Dumps the service container as an YAML string.
|
||||
*/
|
||||
public function dump(array $options = []): string
|
||||
{
|
||||
if (!class_exists(YmlDumper::class)) {
|
||||
throw new LogicException('Unable to dump the container as the Symfony Yaml Component is not installed. Try running "composer require symfony/yaml".');
|
||||
}
|
||||
|
||||
$this->dumper ??= new YmlDumper();
|
||||
|
||||
return $this->addParameters()."\n".$this->addServices();
|
||||
}
|
||||
|
||||
private function addService(string $id, Definition $definition): string
|
||||
{
|
||||
$code = " {$this->dumper->dump($id)}:\n";
|
||||
if ($class = $definition->getClass()) {
|
||||
if (str_starts_with($class, '\\')) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
$code .= \sprintf(" class: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($class)));
|
||||
}
|
||||
|
||||
if (!$definition->isPrivate()) {
|
||||
$code .= \sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
$tagsCode = '';
|
||||
$tags = $definition->getTags();
|
||||
$tags['container.error'] = array_map(fn ($e) => ['message' => $e], $definition->getErrors());
|
||||
foreach ($tags as $name => $tags) {
|
||||
foreach ($tags as $attributes) {
|
||||
$att = [];
|
||||
foreach ($attributes as $key => $value) {
|
||||
$att[] = \sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
|
||||
}
|
||||
$att = $att ? ': { '.implode(', ', $att).' }' : '';
|
||||
|
||||
$tagsCode .= \sprintf(" - %s%s\n", $this->dumper->dump($name), $att);
|
||||
}
|
||||
}
|
||||
if ($tagsCode) {
|
||||
$code .= " tags:\n".$tagsCode;
|
||||
}
|
||||
|
||||
if ($definition->getFile()) {
|
||||
$code .= \sprintf(" file: %s\n", $this->dumper->dump($this->container->resolveEnvPlaceholders($definition->getFile())));
|
||||
}
|
||||
|
||||
if ($definition->isSynthetic()) {
|
||||
$code .= " synthetic: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isDeprecated()) {
|
||||
$code .= " deprecated:\n";
|
||||
foreach ($definition->getDeprecation('%service_id%') as $key => $value) {
|
||||
if ('' !== $value) {
|
||||
$code .= \sprintf(" %s: %s\n", $key, $this->dumper->dump($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition->isAutowired()) {
|
||||
$code .= " autowire: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isAutoconfigured()) {
|
||||
$code .= " autoconfigure: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
$code .= " abstract: true\n";
|
||||
}
|
||||
|
||||
if ($definition->isLazy()) {
|
||||
$code .= " lazy: true\n";
|
||||
}
|
||||
|
||||
if ($definition->getArguments()) {
|
||||
$code .= \sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
|
||||
}
|
||||
|
||||
if ($definition->getProperties()) {
|
||||
$code .= \sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
|
||||
}
|
||||
|
||||
if ($definition->getMethodCalls()) {
|
||||
$code .= \sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
|
||||
}
|
||||
|
||||
if (!$definition->isShared()) {
|
||||
$code .= " shared: false\n";
|
||||
}
|
||||
|
||||
if (null !== $decoratedService = $definition->getDecoratedService()) {
|
||||
[$decorated, $renamedId, $priority] = $decoratedService;
|
||||
$code .= \sprintf(" decorates: %s\n", $decorated);
|
||||
if (null !== $renamedId) {
|
||||
$code .= \sprintf(" decoration_inner_name: %s\n", $renamedId);
|
||||
}
|
||||
if (0 !== $priority) {
|
||||
$code .= \sprintf(" decoration_priority: %s\n", $priority);
|
||||
}
|
||||
|
||||
$decorationOnInvalid = $decoratedService[3] ?? ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
if (\in_array($decorationOnInvalid, [ContainerInterface::IGNORE_ON_INVALID_REFERENCE, ContainerInterface::NULL_ON_INVALID_REFERENCE], true)) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE === $decorationOnInvalid ? 'null' : 'ignore';
|
||||
$code .= \sprintf(" decoration_on_invalid: %s\n", $invalidBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
if (\is_array($callable) && ['Closure', 'fromCallable'] !== $callable && $definition->getClass() === $callable[0]) {
|
||||
$code .= \sprintf(" constructor: %s\n", $callable[1]);
|
||||
} else {
|
||||
$code .= \sprintf(" factory: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
|
||||
}
|
||||
}
|
||||
|
||||
if ($callable = $definition->getConfigurator()) {
|
||||
$code .= \sprintf(" configurator: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
private function addServiceAlias(string $alias, Alias $id): string
|
||||
{
|
||||
$deprecated = '';
|
||||
|
||||
if ($id->isDeprecated()) {
|
||||
$deprecated = " deprecated:\n";
|
||||
|
||||
foreach ($id->getDeprecation('%alias_id%') as $key => $value) {
|
||||
if ('' !== $value) {
|
||||
$deprecated .= \sprintf(" %s: %s\n", $key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id->isDeprecated() && $id->isPrivate()) {
|
||||
return \sprintf(" %s: '@%s'\n", $alias, $id);
|
||||
}
|
||||
|
||||
if ($id->isPublic()) {
|
||||
$deprecated = " public: true\n".$deprecated;
|
||||
}
|
||||
|
||||
return \sprintf(" %s:\n alias: %s\n%s", $alias, $id, $deprecated);
|
||||
}
|
||||
|
||||
private function addServices(): string
|
||||
{
|
||||
if (!$this->container->getDefinitions()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$code = "services:\n";
|
||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||
$code .= $this->addService($id, $definition);
|
||||
}
|
||||
|
||||
$aliases = $this->container->getAliases();
|
||||
foreach ($aliases as $alias => $id) {
|
||||
while (isset($aliases[(string) $id])) {
|
||||
$id = $aliases[(string) $id];
|
||||
}
|
||||
$code .= $this->addServiceAlias($alias, $id);
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
private function addParameters(): string
|
||||
{
|
||||
if (!$this->container->getParameterBag()->all()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$parameters = $this->prepareParameters($this->container->getParameterBag()->all(), $this->container->isCompiled());
|
||||
|
||||
return $this->dumper->dump(['parameters' => $parameters], 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps callable to YAML format.
|
||||
*/
|
||||
private function dumpCallable(mixed $callable): mixed
|
||||
{
|
||||
if (\is_array($callable)) {
|
||||
if ($callable[0] instanceof Reference) {
|
||||
$callable = [$this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]];
|
||||
} else {
|
||||
$callable = [$callable[0], $callable[1]];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the value to YAML format.
|
||||
*
|
||||
* @throws RuntimeException When trying to dump object or resource
|
||||
*/
|
||||
private function dumpValue(mixed $value): mixed
|
||||
{
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$value = $value->getValues()[0];
|
||||
|
||||
return new TaggedValue('service_closure', $this->dumpValue($value));
|
||||
}
|
||||
if ($value instanceof ArgumentInterface) {
|
||||
$tag = $value;
|
||||
|
||||
if ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
|
||||
if (null === $tag->getIndexAttribute()) {
|
||||
$content = $tag->getTag();
|
||||
} else {
|
||||
$content = [
|
||||
'tag' => $tag->getTag(),
|
||||
'index_by' => $tag->getIndexAttribute(),
|
||||
];
|
||||
|
||||
if (null !== $tag->getDefaultIndexMethod()) {
|
||||
$content['default_index_method'] = $tag->getDefaultIndexMethod();
|
||||
}
|
||||
if (null !== $tag->getDefaultPriorityMethod()) {
|
||||
$content['default_priority_method'] = $tag->getDefaultPriorityMethod();
|
||||
}
|
||||
}
|
||||
if ($excludes = $tag->getExclude()) {
|
||||
if (!\is_array($content)) {
|
||||
$content = ['tag' => $content];
|
||||
}
|
||||
$content['exclude'] = 1 === \count($excludes) ? $excludes[0] : $excludes;
|
||||
}
|
||||
if (!$tag->excludeSelf()) {
|
||||
$content['exclude_self'] = false;
|
||||
}
|
||||
|
||||
return new TaggedValue($value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator', $content);
|
||||
}
|
||||
|
||||
if ($value instanceof IteratorArgument) {
|
||||
$tag = 'iterator';
|
||||
} elseif ($value instanceof ServiceLocatorArgument) {
|
||||
$tag = 'service_locator';
|
||||
} else {
|
||||
throw new RuntimeException(\sprintf('Unspecified Yaml tag for type "%s".', get_debug_type($value)));
|
||||
}
|
||||
|
||||
return new TaggedValue($tag, $this->dumpValue($value->getValues()));
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
$code = [];
|
||||
foreach ($value as $k => $v) {
|
||||
$code[$this->container->resolveEnvPlaceholders($k)] = $this->dumpValue($v);
|
||||
}
|
||||
|
||||
return $code;
|
||||
} elseif ($value instanceof Reference) {
|
||||
return $this->getServiceCall((string) $value, $value);
|
||||
} elseif ($value instanceof Parameter) {
|
||||
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 ($value instanceof \UnitEnum) {
|
||||
return new TaggedValue('php/enum', \sprintf('%s::%s', $value::class, $value->name));
|
||||
} elseif ($value instanceof AbstractArgument) {
|
||||
return new TaggedValue('abstract', $value->getText());
|
||||
} elseif (\is_object($value) || \is_resource($value)) {
|
||||
throw new RuntimeException(\sprintf('Unable to dump a service container if a parameter is an object or a resource, got "%s".', get_debug_type($value)));
|
||||
}
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($value);
|
||||
}
|
||||
|
||||
private function getServiceCall(string $id, ?Reference $reference = null): string
|
||||
{
|
||||
if (null !== $reference) {
|
||||
switch ($reference->getInvalidBehavior()) {
|
||||
case ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE: break;
|
||||
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);
|
||||
}
|
||||
|
||||
private function getParameterCall(string $id): string
|
||||
{
|
||||
return \sprintf('%%%s%%', $id);
|
||||
}
|
||||
|
||||
private function getExpressionCall(string $expression): string
|
||||
{
|
||||
return \sprintf('@=%s', $expression);
|
||||
}
|
||||
|
||||
private function prepareParameters(array $parameters, bool $escape = true): array
|
||||
{
|
||||
$filtered = [];
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (\is_array($value)) {
|
||||
$value = $this->prepareParameters($value, $escape);
|
||||
} elseif ($value instanceof Reference || \is_string($value) && str_starts_with($value, '@')) {
|
||||
$value = '@'.$value;
|
||||
}
|
||||
|
||||
$filtered[$key] = $value;
|
||||
}
|
||||
|
||||
return $escape ? $this->container->resolveEnvPlaceholders($this->escape($filtered)) : $filtered;
|
||||
}
|
||||
|
||||
private function escape(array $arguments): array
|
||||
{
|
||||
$args = [];
|
||||
foreach ($arguments as $k => $v) {
|
||||
if (\is_array($v)) {
|
||||
$args[$k] = $this->escape($v);
|
||||
} elseif (\is_string($v)) {
|
||||
$args[$k] = str_replace('%', '%%', $v);
|
||||
} else {
|
||||
$args[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user