Update website
This commit is contained in:
parent
bb4b0f9be8
commit
011b183e28
4263 changed files with 3014 additions and 720369 deletions
|
@ -1,29 +0,0 @@
|
|||
<?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
|
||||
{
|
||||
protected $container;
|
||||
|
||||
public function __construct(ContainerBuilder $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?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.
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function dump(array $options = []);
|
||||
}
|
|
@ -1,251 +0,0 @@
|
|||
<?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 $nodes;
|
||||
private $edges;
|
||||
// All values should be strings
|
||||
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.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dump(array $options = [])
|
||||
{
|
||||
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 ('\\' === substr($class, 0, 1)) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
try {
|
||||
$class = $this->container->getParameterBag()->resolveValue($class);
|
||||
} catch (ParameterNotFoundException $e) {
|
||||
}
|
||||
|
||||
$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('\\', '\\\\', \get_class($container->get($id))), '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;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,131 +0,0 @@
|
|||
<?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 (0 === strpos($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();
|
||||
|
||||
if (\PHP_VERSION_ID >= 70400) {
|
||||
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 $e) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,395 +0,0 @@
|
|||
<?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\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
|
||||
{
|
||||
/**
|
||||
* @var \DOMDocument
|
||||
*/
|
||||
private $document;
|
||||
|
||||
/**
|
||||
* Dumps the service container as an XML string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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 https://symfony.com/schema/dic/services/services-1.0.xsd');
|
||||
|
||||
$this->addParameters($container);
|
||||
$this->addServices($container);
|
||||
|
||||
$this->document->appendChild($container);
|
||||
$xml = $this->document->saveXML();
|
||||
$this->document = null;
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($xml);
|
||||
}
|
||||
|
||||
private function addParameters(\DOMElement $parent)
|
||||
{
|
||||
$data = $this->container->getParameterBag()->all();
|
||||
if (!$data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->container->isCompiled()) {
|
||||
$data = $this->escape($data);
|
||||
}
|
||||
|
||||
$parameters = $this->document->createElement('parameters');
|
||||
$parent->appendChild($parameters);
|
||||
$this->convertParameters($data, 'parameter', $parameters);
|
||||
}
|
||||
|
||||
private function addMethodCalls(array $methodcalls, \DOMElement $parent)
|
||||
{
|
||||
foreach ($methodcalls as $methodcall) {
|
||||
$call = $this->document->createElement('call');
|
||||
$call->setAttribute('method', $methodcall[0]);
|
||||
if (\count($methodcall[1])) {
|
||||
$this->convertParameters($methodcall[1], 'argument', $call);
|
||||
}
|
||||
if ($methodcall[2] ?? false) {
|
||||
$call->setAttribute('returns-clone', 'true');
|
||||
}
|
||||
$parent->appendChild($call);
|
||||
}
|
||||
}
|
||||
|
||||
private function addService(Definition $definition, ?string $id, \DOMElement $parent)
|
||||
{
|
||||
$service = $this->document->createElement('service');
|
||||
if (null !== $id) {
|
||||
$service->setAttribute('id', $id);
|
||||
}
|
||||
if ($class = $definition->getClass()) {
|
||||
if ('\\' === substr($class, 0, 1)) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
$service->setAttribute('class', $class);
|
||||
}
|
||||
if (!$definition->isShared()) {
|
||||
$service->setAttribute('shared', 'false');
|
||||
}
|
||||
if ($definition->isPublic()) {
|
||||
$service->setAttribute('public', 'true');
|
||||
}
|
||||
if ($definition->isSynthetic()) {
|
||||
$service->setAttribute('synthetic', 'true');
|
||||
}
|
||||
if ($definition->isLazy()) {
|
||||
$service->setAttribute('lazy', 'true');
|
||||
}
|
||||
if (null !== $decoratedService = $definition->getDecoratedService()) {
|
||||
[$decorated, $renamedId, $priority] = $decoratedService;
|
||||
$service->setAttribute('decorates', $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';
|
||||
$service->setAttribute('decoration-on-invalid', $invalidBehavior);
|
||||
}
|
||||
if (null !== $renamedId) {
|
||||
$service->setAttribute('decoration-inner-name', $renamedId);
|
||||
}
|
||||
if (0 !== $priority) {
|
||||
$service->setAttribute('decoration-priority', $priority);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($definition->getTags() as $name => $tags) {
|
||||
foreach ($tags as $attributes) {
|
||||
$tag = $this->document->createElement('tag');
|
||||
if (!\array_key_exists('name', $attributes)) {
|
||||
$tag->setAttribute('name', $name);
|
||||
} else {
|
||||
$tag->appendChild($this->document->createTextNode($name));
|
||||
}
|
||||
foreach ($attributes as $key => $value) {
|
||||
$tag->setAttribute($key, $value ?? '');
|
||||
}
|
||||
$service->appendChild($tag);
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition->getFile()) {
|
||||
$file = $this->document->createElement('file');
|
||||
$file->appendChild($this->document->createTextNode($definition->getFile()));
|
||||
$service->appendChild($file);
|
||||
}
|
||||
|
||||
if ($parameters = $definition->getArguments()) {
|
||||
$this->convertParameters($parameters, 'argument', $service);
|
||||
}
|
||||
|
||||
if ($parameters = $definition->getProperties()) {
|
||||
$this->convertParameters($parameters, 'property', $service, 'name');
|
||||
}
|
||||
|
||||
$this->addMethodCalls($definition->getMethodCalls(), $service);
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
$factory = $this->document->createElement('factory');
|
||||
|
||||
if (\is_array($callable) && $callable[0] instanceof Definition) {
|
||||
$this->addService($callable[0], null, $factory);
|
||||
$factory->setAttribute('method', $callable[1]);
|
||||
} elseif (\is_array($callable)) {
|
||||
if (null !== $callable[0]) {
|
||||
$factory->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
|
||||
}
|
||||
$factory->setAttribute('method', $callable[1]);
|
||||
} else {
|
||||
$factory->setAttribute('function', $callable);
|
||||
}
|
||||
$service->appendChild($factory);
|
||||
}
|
||||
|
||||
if ($definition->isDeprecated()) {
|
||||
$deprecation = $definition->getDeprecation('%service_id%');
|
||||
$deprecated = $this->document->createElement('deprecated');
|
||||
$deprecated->appendChild($this->document->createTextNode($definition->getDeprecation('%service_id%')['message']));
|
||||
$deprecated->setAttribute('package', $deprecation['package']);
|
||||
$deprecated->setAttribute('version', $deprecation['version']);
|
||||
|
||||
$service->appendChild($deprecated);
|
||||
}
|
||||
|
||||
if ($definition->isAutowired()) {
|
||||
$service->setAttribute('autowire', 'true');
|
||||
}
|
||||
|
||||
if ($definition->isAutoconfigured()) {
|
||||
$service->setAttribute('autoconfigure', 'true');
|
||||
}
|
||||
|
||||
if ($definition->isAbstract()) {
|
||||
$service->setAttribute('abstract', 'true');
|
||||
}
|
||||
|
||||
if ($callable = $definition->getConfigurator()) {
|
||||
$configurator = $this->document->createElement('configurator');
|
||||
|
||||
if (\is_array($callable) && $callable[0] instanceof Definition) {
|
||||
$this->addService($callable[0], null, $configurator);
|
||||
$configurator->setAttribute('method', $callable[1]);
|
||||
} elseif (\is_array($callable)) {
|
||||
$configurator->setAttribute($callable[0] instanceof Reference ? 'service' : 'class', $callable[0]);
|
||||
$configurator->setAttribute('method', $callable[1]);
|
||||
} else {
|
||||
$configurator->setAttribute('function', $callable);
|
||||
}
|
||||
$service->appendChild($configurator);
|
||||
}
|
||||
|
||||
$parent->appendChild($service);
|
||||
}
|
||||
|
||||
private function addServiceAlias(string $alias, Alias $id, \DOMElement $parent)
|
||||
{
|
||||
$service = $this->document->createElement('service');
|
||||
$service->setAttribute('id', $alias);
|
||||
$service->setAttribute('alias', $id);
|
||||
if ($id->isPublic()) {
|
||||
$service->setAttribute('public', 'true');
|
||||
}
|
||||
|
||||
if ($id->isDeprecated()) {
|
||||
$deprecation = $id->getDeprecation('%alias_id%');
|
||||
$deprecated = $this->document->createElement('deprecated');
|
||||
$deprecated->appendChild($this->document->createTextNode($deprecation['message']));
|
||||
$deprecated->setAttribute('package', $deprecation['package']);
|
||||
$deprecated->setAttribute('version', $deprecation['version']);
|
||||
|
||||
$service->appendChild($deprecated);
|
||||
}
|
||||
|
||||
$parent->appendChild($service);
|
||||
}
|
||||
|
||||
private function addServices(\DOMElement $parent)
|
||||
{
|
||||
$definitions = $this->container->getDefinitions();
|
||||
if (!$definitions) {
|
||||
return;
|
||||
}
|
||||
|
||||
$services = $this->document->createElement('services');
|
||||
foreach ($definitions as $id => $definition) {
|
||||
$this->addService($definition, $id, $services);
|
||||
}
|
||||
|
||||
$aliases = $this->container->getAliases();
|
||||
foreach ($aliases as $alias => $id) {
|
||||
while (isset($aliases[(string) $id])) {
|
||||
$id = $aliases[(string) $id];
|
||||
}
|
||||
$this->addServiceAlias($alias, $id, $services);
|
||||
}
|
||||
$parent->appendChild($services);
|
||||
}
|
||||
|
||||
private function convertParameters(array $parameters, string $type, \DOMElement $parent, string $keyAttribute = 'key')
|
||||
{
|
||||
$withKeys = !array_is_list($parameters);
|
||||
foreach ($parameters as $key => $value) {
|
||||
$element = $this->document->createElement($type);
|
||||
if ($withKeys) {
|
||||
$element->setAttribute($keyAttribute, $key);
|
||||
}
|
||||
|
||||
if (\is_array($tag = $value)) {
|
||||
$element->setAttribute('type', 'collection');
|
||||
$this->convertParameters($value, $type, $element, 'key');
|
||||
} elseif ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
|
||||
$element->setAttribute('type', $value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator');
|
||||
$element->setAttribute('tag', $tag->getTag());
|
||||
|
||||
if (null !== $tag->getIndexAttribute()) {
|
||||
$element->setAttribute('index-by', $tag->getIndexAttribute());
|
||||
|
||||
if (null !== $tag->getDefaultIndexMethod()) {
|
||||
$element->setAttribute('default-index-method', $tag->getDefaultIndexMethod());
|
||||
}
|
||||
if (null !== $tag->getDefaultPriorityMethod()) {
|
||||
$element->setAttribute('default-priority-method', $tag->getDefaultPriorityMethod());
|
||||
}
|
||||
}
|
||||
} elseif ($value instanceof IteratorArgument) {
|
||||
$element->setAttribute('type', 'iterator');
|
||||
$this->convertParameters($value->getValues(), $type, $element, 'key');
|
||||
} elseif ($value instanceof ServiceLocatorArgument) {
|
||||
$element->setAttribute('type', 'service_locator');
|
||||
$this->convertParameters($value->getValues(), $type, $element, 'key');
|
||||
} elseif ($value instanceof Reference || $value instanceof ServiceClosureArgument) {
|
||||
$element->setAttribute('type', 'service');
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$element->setAttribute('type', 'service_closure');
|
||||
$value = $value->getValues()[0];
|
||||
}
|
||||
$element->setAttribute('id', (string) $value);
|
||||
$behavior = $value->getInvalidBehavior();
|
||||
if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behavior) {
|
||||
$element->setAttribute('on-invalid', 'null');
|
||||
} elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behavior) {
|
||||
$element->setAttribute('on-invalid', 'ignore');
|
||||
} elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behavior) {
|
||||
$element->setAttribute('on-invalid', 'ignore_uninitialized');
|
||||
}
|
||||
} elseif ($value instanceof Definition) {
|
||||
$element->setAttribute('type', 'service');
|
||||
$this->addService($value, null, $element);
|
||||
} elseif ($value instanceof Expression) {
|
||||
$element->setAttribute('type', 'expression');
|
||||
$text = $this->document->createTextNode(self::phpToXml((string) $value));
|
||||
$element->appendChild($text);
|
||||
} elseif (\is_string($value) && !preg_match('/^[^\x00-\x08\x0B\x0E-\x1A\x1C-\x1F\x7F]*+$/u', $value)) {
|
||||
$element->setAttribute('type', 'binary');
|
||||
$text = $this->document->createTextNode(self::phpToXml(base64_encode($value)));
|
||||
$element->appendChild($text);
|
||||
} elseif ($value instanceof \UnitEnum) {
|
||||
$element->setAttribute('type', 'constant');
|
||||
$element->appendChild($this->document->createTextNode(self::phpToXml($value)));
|
||||
} elseif ($value instanceof AbstractArgument) {
|
||||
$element->setAttribute('type', 'abstract');
|
||||
$text = $this->document->createTextNode(self::phpToXml($value->getText()));
|
||||
$element->appendChild($text);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
$parent->appendChild($element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes arguments.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts php types to xml types.
|
||||
*
|
||||
* @param mixed $value Value to convert
|
||||
*
|
||||
* @throws RuntimeException When trying to dump object or resource
|
||||
*/
|
||||
public static function phpToXml($value): string
|
||||
{
|
||||
switch (true) {
|
||||
case null === $value:
|
||||
return 'null';
|
||||
case true === $value:
|
||||
return 'true';
|
||||
case false === $value:
|
||||
return 'false';
|
||||
case $value instanceof Parameter:
|
||||
return '%'.$value.'%';
|
||||
case $value instanceof \UnitEnum:
|
||||
return sprintf('%s::%s', \get_class($value), $value->name);
|
||||
case \is_object($value) || \is_resource($value):
|
||||
throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
|
||||
default:
|
||||
return (string) $value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,375 +0,0 @@
|
|||
<?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 $dumper;
|
||||
|
||||
/**
|
||||
* Dumps the service container as an YAML string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dump(array $options = [])
|
||||
{
|
||||
if (!class_exists(\Symfony\Component\Yaml\Dumper::class)) {
|
||||
throw new LogicException('Unable to dump the container as the Symfony Yaml Component is not installed.');
|
||||
}
|
||||
|
||||
if (null === $this->dumper) {
|
||||
$this->dumper = new YmlDumper();
|
||||
}
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices());
|
||||
}
|
||||
|
||||
private function addService(string $id, Definition $definition): string
|
||||
{
|
||||
$code = " $id:\n";
|
||||
if ($class = $definition->getClass()) {
|
||||
if ('\\' === substr($class, 0, 1)) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
$code .= sprintf(" class: %s\n", $this->dumper->dump($class));
|
||||
}
|
||||
|
||||
if (!$definition->isPrivate()) {
|
||||
$code .= sprintf(" public: %s\n", $definition->isPublic() ? 'true' : 'false');
|
||||
}
|
||||
|
||||
$tagsCode = '';
|
||||
foreach ($definition->getTags() 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($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])) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE === $decorationOnInvalid ? 'null' : 'ignore';
|
||||
$code .= sprintf(" decoration_on_invalid: %s\n", $invalidBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
$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.
|
||||
*
|
||||
* @param mixed $callable
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function dumpCallable($callable)
|
||||
{
|
||||
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 $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the value to YAML format.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws RuntimeException When trying to dump object or resource
|
||||
*/
|
||||
private function dumpValue($value)
|
||||
{
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$value = $value->getValues()[0];
|
||||
|
||||
return new TaggedValue('service_closure', $this->getServiceCall((string) $value, $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();
|
||||
}
|
||||
}
|
||||
|
||||
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[$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/const', sprintf('%s::%s', \get_class($value), $value->name));
|
||||
} elseif ($value instanceof AbstractArgument) {
|
||||
return new TaggedValue('abstract', $value->getText());
|
||||
} 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.');
|
||||
}
|
||||
|
||||
return $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->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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue