This commit is contained in:
Hanson.xyz Dev
2026-01-04 17:50:08 -06:00
parent 7e45ce0756
commit acc8ac87a0
4131 changed files with 232562 additions and 250244 deletions
@@ -25,12 +25,12 @@ class RewindableGenerator implements \IteratorAggregate, \Countable
$this->generator = $generator;
$this->count = $count;
}
public function getIterator()
public function getIterator() : \Traversable
{
$g = $this->generator;
return $g();
}
public function count()
public function count() : int
{
if (\is_callable($count = $this->count)) {
$this->count = $count();
@@ -0,0 +1,49 @@
<?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 YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ServiceLocator as BaseServiceLocator;
/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class ServiceLocator extends \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ServiceLocator
{
private $factory;
private $serviceMap;
private $serviceTypes;
public function __construct(\Closure $factory, array $serviceMap, ?array $serviceTypes = null)
{
$this->factory = $factory;
$this->serviceMap = $serviceMap;
$this->serviceTypes = $serviceTypes;
parent::__construct($serviceMap);
}
/**
* {@inheritdoc}
*
* @return mixed
*/
public function get(string $id)
{
return isset($this->serviceMap[$id]) ? ($this->factory)(...$this->serviceMap[$id]) : parent::get($id);
}
/**
* {@inheritdoc}
*/
public function getProvidedServices() : array
{
return $this->serviceTypes ?? ($this->serviceTypes = \array_map(function () {
return '?';
}, $this->serviceMap));
}
}
@@ -0,0 +1,39 @@
<?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 YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Reference;
/**
* Represents a closure acting as a service locator.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class ServiceLocatorArgument implements \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\ArgumentInterface
{
use ReferenceSetArgumentTrait;
private $taggedIteratorArgument;
/**
* @param Reference[]|TaggedIteratorArgument $values
*/
public function __construct($values = [])
{
if ($values instanceof \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument) {
$this->taggedIteratorArgument = $values;
$this->values = [];
} else {
$this->setValues($values);
}
}
public function getTaggedIteratorArgument() : ?\YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument
{
return $this->taggedIteratorArgument;
}
}
@@ -10,14 +10,21 @@
*/
namespace YoastSEO_Vendor\Symfony\Component\DependencyInjection;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\ServiceLocator as ArgumentServiceLocator;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use YoastSEO_Vendor\Symfony\Contracts\Service\ResetInterface;
// Help opcache.preload discover always-needed symbols
\class_exists(\YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\RewindableGenerator::class);
\class_exists(\YoastSEO_Vendor\Symfony\Component\DependencyInjection\Argument\ServiceLocator::class);
/**
* Container is a dependency injection container.
*
@@ -26,40 +33,34 @@ use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\Parameter
* The container can have four possible behaviors when a service
* does not exist (or is not initialized for the last case):
*
* * EXCEPTION_ON_INVALID_REFERENCE: Throws an exception (the default)
* * EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at compilation time (the default)
* * NULL_ON_INVALID_REFERENCE: Returns null
* * IGNORE_ON_INVALID_REFERENCE: Ignores the wrapping command asking for the reference
* (for instance, ignore a setter if the service does not exist)
* * IGNORE_ON_UNINITIALIZED_REFERENCE: Ignores/returns null for uninitialized services or invalid references
* * RUNTIME_EXCEPTION_ON_INVALID_REFERENCE: Throws an exception at runtime
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ResettableContainerInterface
class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface, \YoastSEO_Vendor\Symfony\Contracts\Service\ResetInterface
{
protected $parameterBag;
protected $services = [];
protected $privates = [];
protected $fileMap = [];
protected $methodMap = [];
protected $factories = [];
protected $aliases = [];
protected $loading = [];
protected $resolving = [];
protected $syntheticIds = [];
/**
* @internal
*/
protected $privates = [];
/**
* @internal
*/
protected $normalizedIds = [];
private $underscoreMap = ['_' => '', '.' => '_', '\\' => '_'];
private $envCache = [];
private $compiled = \false;
private $getEnv;
public function __construct(\YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag = null)
public function __construct(?\YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface $parameterBag = null)
{
$this->parameterBag = $parameterBag ?: new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag();
$this->parameterBag = $parameterBag ?? new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag();
}
/**
* Compiles the container.
@@ -84,22 +85,10 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
{
return $this->compiled;
}
/**
* Returns true if the container parameter bag are frozen.
*
* @deprecated since version 3.3, to be removed in 4.0.
*
* @return bool true if the container parameter bag are frozen, false otherwise
*/
public function isFrozen()
{
@\trigger_error(\sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->parameterBag instanceof \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
}
/**
* Gets the service container parameter bag.
*
* @return ParameterBagInterface A ParameterBagInterface instance
* @return ParameterBagInterface
*/
public function getParameterBag()
{
@@ -108,34 +97,28 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
/**
* Gets a parameter.
*
* @param string $name The parameter name
*
* @return mixed The parameter value
* @return array|bool|string|int|float|\UnitEnum|null
*
* @throws InvalidArgumentException if the parameter is not defined
*/
public function getParameter($name)
public function getParameter(string $name)
{
return $this->parameterBag->get($name);
}
/**
* Checks if a parameter exists.
*
* @param string $name The parameter name
*
* @return bool The presence of parameter in container
* @return bool
*/
public function hasParameter($name)
public function hasParameter(string $name)
{
return $this->parameterBag->has($name);
}
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param string $name The parameter name
* @param array|bool|string|int|float|\UnitEnum|null $value The parameter value
*/
public function setParameter($name, $value)
public function setParameter(string $name, $value)
{
$this->parameterBag->set($name, $value);
}
@@ -144,11 +127,8 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
*
* Setting a synthetic service to null resets it: has() returns false and get()
* behaves in the same way as if the service was never created.
*
* @param string $id The service identifier
* @param object|null $service The service instance
*/
public function set($id, $service)
public function set(string $id, ?object $service)
{
// Runs the internal initializer; used by the dumped container to include always-needed files
if (isset($this->privates['service_container']) && $this->privates['service_container'] instanceof \Closure) {
@@ -156,25 +136,19 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
unset($this->privates['service_container']);
$initialize();
}
$id = $this->normalizeId($id);
if ('service_container' === $id) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('You cannot set service "service_container".');
}
if (isset($this->privates[$id]) || !(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
if (!isset($this->privates[$id]) && !isset($this->getRemovedIds()[$id])) {
if (!(isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
if (isset($this->syntheticIds[$id]) || !isset($this->getRemovedIds()[$id])) {
// no-op
} elseif (null === $service) {
@\trigger_error(\sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), \E_USER_DEPRECATED);
unset($this->privates[$id]);
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('The "%s" service is private, you cannot unset it.', $id));
} else {
@\trigger_error(\sprintf('The "%s" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), \E_USER_DEPRECATED);
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('The "%s" service is private, you cannot replace it.', $id));
}
} elseif (isset($this->services[$id])) {
if (null === $service) {
@\trigger_error(\sprintf('The "%s" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), \E_USER_DEPRECATED);
} else {
@\trigger_error(\sprintf('The "%s" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), \E_USER_DEPRECATED);
}
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('The "%s" service is already initialized, you cannot replace it.', $id));
}
if (isset($this->aliases[$id])) {
unset($this->aliases[$id]);
@@ -190,49 +164,25 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
*
* @param string $id The service identifier
*
* @return bool true if the service is defined, false otherwise
* @return bool
*/
public function has($id)
public function has(string $id)
{
for ($i = 2;;) {
if (isset($this->privates[$id])) {
@\trigger_error(\sprintf('The "%s" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.', $id), \E_USER_DEPRECATED);
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (isset($this->services[$id])) {
return \true;
}
if ('service_container' === $id) {
return \true;
}
if (isset($this->fileMap[$id]) || isset($this->methodMap[$id])) {
return \true;
}
if (--$i && $id !== ($normalizedId = $this->normalizeId($id))) {
$id = $normalizedId;
continue;
}
// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
if (!$this->methodMap && !$this instanceof \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerBuilder && __CLASS__ !== static::class && \method_exists($this, 'get' . \strtr($id, $this->underscoreMap) . 'Service')) {
@\trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', \E_USER_DEPRECATED);
return \true;
}
return \false;
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
if (isset($this->services[$id])) {
return \true;
}
if ('service_container' === $id) {
return \true;
}
return isset($this->fileMap[$id]) || isset($this->methodMap[$id]);
}
/**
* Gets a service.
*
* If a service is defined both through a set() method and
* with a get{$id}Service() method, the former has always precedence.
*
* @param string $id The service identifier
* @param int $invalidBehavior The behavior when the service does not exist
*
* @return object|null The associated service
* @return object|null
*
* @throws ServiceCircularReferenceException When a circular reference is detected
* @throws ServiceNotFoundException When the service is not defined
@@ -240,52 +190,32 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
*
* @see Reference
*/
public function get($id, $invalidBehavior = 1)
public function get(string $id, int $invalidBehavior = 1)
{
// Attempt to retrieve the service by checking first aliases then
// available services. Service IDs are case insensitive, however since
// this method can be called thousands of times during a request, avoid
// calling $this->normalizeId($id) unless necessary.
for ($i = 2;;) {
if (isset($this->privates[$id])) {
@\trigger_error(\sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.', $id), \E_USER_DEPRECATED);
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
// Re-use shared service instance if it exists.
if (isset($this->services[$id])) {
return $this->services[$id];
}
if ('service_container' === $id) {
return $this;
}
if (isset($this->loading[$id])) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException($id, \array_merge(\array_keys($this->loading), [$id]));
}
$this->loading[$id] = \true;
try {
if (isset($this->fileMap[$id])) {
return 4 === $invalidBehavior ? null : $this->load($this->fileMap[$id]);
} elseif (isset($this->methodMap[$id])) {
return 4 === $invalidBehavior ? null : $this->{$this->methodMap[$id]}();
} elseif (--$i && $id !== ($normalizedId = $this->normalizeId($id))) {
unset($this->loading[$id]);
$id = $normalizedId;
continue;
} elseif (!$this->methodMap && !$this instanceof \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerBuilder && __CLASS__ !== static::class && \method_exists($this, $method = 'get' . \strtr($id, $this->underscoreMap) . 'Service')) {
// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
@\trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', \E_USER_DEPRECATED);
return 4 === $invalidBehavior ? null : $this->{$method}();
}
break;
} catch (\Exception $e) {
unset($this->services[$id]);
throw $e;
} finally {
unset($this->loading[$id]);
return $this->services[$id] ?? $this->services[$id = $this->aliases[$id] ?? $id] ?? ('service_container' === $id ? $this : ($this->factories[$id] ?? [$this, 'make'])($id, $invalidBehavior));
}
/**
* Creates a service.
*
* As a separate method to allow "get()" to use the really fast `??` operator.
*/
private function make(string $id, int $invalidBehavior)
{
if (isset($this->loading[$id])) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException($id, \array_merge(\array_keys($this->loading), [$id]));
}
$this->loading[$id] = \true;
try {
if (isset($this->fileMap[$id])) {
return 4 === $invalidBehavior ? null : $this->load($this->fileMap[$id]);
} elseif (isset($this->methodMap[$id])) {
return 4 === $invalidBehavior ? null : $this->{$this->methodMap[$id]}();
}
} catch (\Exception $e) {
unset($this->services[$id]);
throw $e;
} finally {
unset($this->loading[$id]);
}
if (1 === $invalidBehavior) {
if (!$id) {
@@ -299,27 +229,25 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
}
$alternatives = [];
foreach ($this->getServiceIds() as $knownId) {
if ('' === $knownId || '.' === $knownId[0]) {
continue;
}
$lev = \levenshtein($id, $knownId);
if ($lev <= \strlen($id) / 3 || \false !== \strpos($knownId, $id)) {
if ($lev <= \strlen($id) / 3 || \str_contains($knownId, $id)) {
$alternatives[] = $knownId;
}
}
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id, null, null, $alternatives);
}
return null;
}
/**
* Returns true if the given service has actually been initialized.
*
* @param string $id The service identifier
*
* @return bool true if service has already been initialized, false otherwise
* @return bool
*/
public function initialized($id)
public function initialized(string $id)
{
$id = $this->normalizeId($id);
if (isset($this->privates[$id])) {
@\trigger_error(\sprintf('Checking for the initialization of the "%s" private service is deprecated since Symfony 3.4 and won\'t be supported anymore in Symfony 4.0.', $id), \E_USER_DEPRECATED);
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
@@ -333,28 +261,26 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
*/
public function reset()
{
$this->services = [];
$services = $this->services + $this->privates;
foreach ($services as $service) {
try {
if ($service instanceof \YoastSEO_Vendor\Symfony\Contracts\Service\ResetInterface) {
$service->reset();
}
} catch (\Throwable $e) {
continue;
}
}
$this->services = $this->factories = $this->privates = [];
}
/**
* Gets all service ids.
*
* @return string[] An array of all defined service ids
* @return string[]
*/
public function getServiceIds()
{
$ids = [];
if (!$this->methodMap && !$this instanceof \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerBuilder && __CLASS__ !== static::class) {
// We only check the convention-based factory in a compiled container (i.e. a child class other than a ContainerBuilder,
// and only when the dumper has not generated the method map (otherwise the method map is considered to be fully populated by the dumper)
@\trigger_error('Generating a dumped container without populating the method map is deprecated since Symfony 3.2 and will be unsupported in 4.0. Update your dumper to generate the method map.', \E_USER_DEPRECATED);
foreach (\get_class_methods($this) as $method) {
if (\preg_match('/^get(.+)Service$/', $method, $match)) {
$ids[] = self::underscore($match[1]);
}
}
}
$ids[] = 'service_container';
return \array_map('strval', \array_unique(\array_merge($ids, \array_keys($this->methodMap), \array_keys($this->fileMap), \array_keys($this->aliases), \array_keys($this->services))));
return \array_map('strval', \array_unique(\array_merge(['service_container'], \array_keys($this->fileMap), \array_keys($this->methodMap), \array_keys($this->aliases), \array_keys($this->services))));
}
/**
* Gets service ids that existed at compile time.
@@ -368,42 +294,36 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
/**
* Camelizes a string.
*
* @param string $id A string to camelize
*
* @return string The camelized string
* @return string
*/
public static function camelize($id)
public static function camelize(string $id)
{
return \strtr(\ucwords(\strtr($id, ['_' => ' ', '.' => '_ ', '\\' => '_ '])), [' ' => '']);
}
/**
* A string to underscore.
*
* @param string $id The string to underscore
*
* @return string The underscored string
* @return string
*/
public static function underscore($id)
public static function underscore(string $id)
{
return \strtolower(\preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], \str_replace('_', '.', $id)));
}
/**
* Creates a service by requiring its factory file.
*/
protected function load($file)
protected function load(string $file)
{
return require $file;
}
/**
* Fetches a variable from the environment.
*
* @param string $name The name of the environment variable
*
* @return mixed The value to use for the provided environment variable name
* @return mixed
*
* @throws EnvNotFoundException When the environment variable is not found and has no default value
*/
protected function getEnv($name)
protected function getEnv(string $name)
{
if (isset($this->resolving[$envName = "env({$name})"])) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException(\array_keys($this->resolving));
@@ -415,9 +335,7 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
$this->set($id, new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ServiceLocator([]));
}
if (!$this->getEnv) {
$this->getEnv = new \ReflectionMethod($this, __FUNCTION__);
$this->getEnv->setAccessible(\true);
$this->getEnv = $this->getEnv->getClosure($this);
$this->getEnv = \Closure::fromCallable([$this, 'getEnv']);
}
$processors = $this->get($id);
if (\false !== ($i = \strpos($name, ':'))) {
@@ -428,6 +346,9 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
$localName = $name;
}
$processor = $processors->has($prefix) ? $processors->get($prefix) : new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\EnvVarProcessor($this);
if (\false === $i) {
$prefix = '';
}
$this->resolving[$envName] = \true;
try {
return $this->envCache[$name] = $processor->getEnv($prefix, $localName, $this->getEnv);
@@ -436,28 +357,31 @@ class Container implements \YoastSEO_Vendor\Symfony\Component\DependencyInjectio
}
}
/**
* Returns the case sensitive id used at registration time.
* @param string|false $registry
* @param string|bool $load
*
* @param string $id
*
* @return string
* @return mixed
*
* @internal
*/
public function normalizeId($id)
protected final function getService($registry, string $id, ?string $method, $load)
{
if (!\is_string($id)) {
$id = (string) $id;
if ('service_container' === $id) {
return $this;
}
if (isset($this->normalizedIds[$normalizedId = \strtolower($id)])) {
$normalizedId = $this->normalizedIds[$normalizedId];
if ($id !== $normalizedId) {
@\trigger_error(\sprintf('Service identifiers will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since Symfony 3.3.', $id, $normalizedId), \E_USER_DEPRECATED);
}
} else {
$normalizedId = $this->normalizedIds[$normalizedId] = $id;
if (\is_string($load)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException($load);
}
return $normalizedId;
if (null === $method) {
return \false !== $registry ? $this->{$registry}[$id] ?? null : null;
}
if (\false !== $registry) {
return $this->{$registry}[$id] ?? ($this->{$registry}[$id] = $load ? $this->load($method) : $this->{$method}());
}
if (!$load) {
return $this->{$method}();
}
return ($factory = $this->factories[$id] ?? $this->factories['service_container'][$id] ?? null) ? $factory() : $this->load($method);
}
private function __clone()
{
@@ -22,70 +22,54 @@ use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFo
*/
interface ContainerInterface extends \YoastSEO_Vendor\Psr\Container\ContainerInterface
{
const EXCEPTION_ON_INVALID_REFERENCE = 1;
const NULL_ON_INVALID_REFERENCE = 2;
const IGNORE_ON_INVALID_REFERENCE = 3;
const IGNORE_ON_UNINITIALIZED_REFERENCE = 4;
public const RUNTIME_EXCEPTION_ON_INVALID_REFERENCE = 0;
public const EXCEPTION_ON_INVALID_REFERENCE = 1;
public const NULL_ON_INVALID_REFERENCE = 2;
public const IGNORE_ON_INVALID_REFERENCE = 3;
public const IGNORE_ON_UNINITIALIZED_REFERENCE = 4;
/**
* Sets a service.
*
* @param string $id The service identifier
* @param object|null $service The service instance
*/
public function set($id, $service);
public function set(string $id, ?object $service);
/**
* Gets a service.
*
* @param string $id The service identifier
* @param int $invalidBehavior The behavior when the service does not exist
*
* @return object|null The associated service
* @return object|null
*
* @throws ServiceCircularReferenceException When a circular reference is detected
* @throws ServiceNotFoundException When the service is not defined
*
* @see Reference
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
/**
* Returns true if the given service is defined.
*
* @param string $id The service identifier
*
* @return bool true if the service is defined, false otherwise
* @return bool
*/
public function has($id);
public function has(string $id);
/**
* Check for whether or not a service has been initialized.
*
* @param string $id
*
* @return bool true if the service has been initialized, false otherwise
* @return bool
*/
public function initialized($id);
public function initialized(string $id);
/**
* Gets a parameter.
*
* @param string $name The parameter name
*
* @return mixed The parameter value
* @return array|bool|string|int|float|\UnitEnum|null
*
* @throws InvalidArgumentException if the parameter is not defined
*/
public function getParameter($name);
public function getParameter(string $name);
/**
* Checks if a parameter exists.
*
* @param string $name The parameter name
*
* @return bool The presence of parameter in container
* @return bool
*/
public function hasParameter($name);
public function hasParameter(string $name);
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param string $name The parameter name
* @param array|bool|string|int|float|\UnitEnum|null $value The parameter value
*/
public function setParameter($name, $value);
public function setParameter(string $name, $value);
}
@@ -17,8 +17,4 @@ namespace YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception;
*/
class EnvNotFoundException extends \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
{
public function __construct($name)
{
parent::__construct(\sprintf('Environment variable not found: "%s".', $name));
}
}
@@ -17,6 +17,6 @@ use YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface;
* @author Fabien Potencier <fabien@symfony.com>
* @author Bulat Shakirzyanov <bulat@theopenskyproject.com>
*/
interface ExceptionInterface extends \YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface
interface ExceptionInterface extends \YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface, \Throwable
{
}
@@ -18,7 +18,7 @@ namespace YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception;
class ParameterCircularReferenceException extends \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException
{
private $parameters;
public function __construct($parameters, \Exception $previous = null)
public function __construct(array $parameters, ?\Throwable $previous = null)
{
parent::__construct(\sprintf('Circular reference detected for parameter "%s" ("%s" > "%s").', $parameters[0], \implode('" > "', $parameters), $parameters[0]), 0, $previous);
$this->parameters = $parameters;
@@ -19,7 +19,7 @@ class ServiceCircularReferenceException extends \YoastSEO_Vendor\Symfony\Compone
{
private $serviceId;
private $path;
public function __construct($serviceId, array $path, \Exception $previous = null)
public function __construct(string $serviceId, array $path, ?\Throwable $previous = null)
{
parent::__construct(\sprintf('Circular reference detected for service "%s", path: "%s".', $serviceId, \implode(' -> ', $path)), 0, $previous);
$this->serviceId = $serviceId;
@@ -21,7 +21,7 @@ class ServiceNotFoundException extends \YoastSEO_Vendor\Symfony\Component\Depend
private $id;
private $sourceId;
private $alternatives;
public function __construct($id, $sourceId = null, \Exception $previous = null, array $alternatives = [], $msg = null)
public function __construct(string $id, ?string $sourceId = null, ?\Throwable $previous = null, array $alternatives = [], ?string $msg = null)
{
if (null !== $msg) {
// no-op
@@ -17,14 +17,17 @@ use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeExcep
*/
class EnvPlaceholderParameterBag extends \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag
{
private $envPlaceholderUniquePrefix;
private $envPlaceholders = [];
private $unusedEnvPlaceholders = [];
private $providedTypes = [];
private static $counter = 0;
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
if (0 === \strpos($name, 'env(') && ')' === \substr($name, -1) && 'env()' !== $name) {
if (\str_starts_with($name, 'env(') && \str_ends_with($name, ')') && 'env()' !== $name) {
$env = \substr($name, 4, -1);
if (isset($this->envPlaceholders[$env])) {
foreach ($this->envPlaceholders[$env] as $placeholder) {
@@ -32,22 +35,39 @@ class EnvPlaceholderParameterBag extends \YoastSEO_Vendor\Symfony\Component\Depe
// return first result
}
}
if (!\preg_match('/^(?:\\w++:)*+\\w++$/', $env)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Invalid "%s" name: only "word" characters are allowed.', $name));
}
if ($this->has($name)) {
$defaultValue = parent::get($name);
if (null !== $defaultValue && !\is_scalar($defaultValue)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', \gettype($defaultValue), $name));
if (isset($this->unusedEnvPlaceholders[$env])) {
foreach ($this->unusedEnvPlaceholders[$env] as $placeholder) {
return $placeholder;
// return first result
}
}
$uniqueName = \md5($name . \uniqid(\mt_rand(), \true));
$placeholder = \sprintf('env_%s_%s', \str_replace(':', '_', $env), $uniqueName);
if (!\preg_match('/^(?:[-.\\w]*+:)*+\\w++$/', $env)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Invalid %s name: only "word" characters are allowed.', $name));
}
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', \get_debug_type($defaultValue), $name));
}
$uniqueName = \md5($name . '_' . self::$counter++);
$placeholder = \sprintf('%s_%s_%s', $this->getEnvPlaceholderUniquePrefix(), \strtr($env, ':-.', '___'), $uniqueName);
$this->envPlaceholders[$env][$placeholder] = $placeholder;
return $placeholder;
}
return parent::get($name);
}
/**
* Gets the common env placeholder prefix for env vars created by this bag.
*/
public function getEnvPlaceholderUniquePrefix() : string
{
if (null === $this->envPlaceholderUniquePrefix) {
$reproducibleEntropy = \unserialize(\serialize($this->parameters));
\array_walk_recursive($reproducibleEntropy, function (&$v) {
$v = null;
});
$this->envPlaceholderUniquePrefix = 'env_' . \substr(\md5(\serialize($reproducibleEntropy)), -16);
}
return $this->envPlaceholderUniquePrefix;
}
/**
* Returns the map of env vars used in the resolved parameter values to their placeholders.
*
@@ -57,6 +77,14 @@ class EnvPlaceholderParameterBag extends \YoastSEO_Vendor\Symfony\Component\Depe
{
return $this->envPlaceholders;
}
public function getUnusedEnvPlaceholders() : array
{
return $this->unusedEnvPlaceholders;
}
public function clearUnusedEnvPlaceholders()
{
$this->unusedEnvPlaceholders = [];
}
/**
* Merges the env placeholders of another EnvPlaceholderParameterBag.
*/
@@ -68,6 +96,12 @@ class EnvPlaceholderParameterBag extends \YoastSEO_Vendor\Symfony\Component\Depe
$this->envPlaceholders[$env] += $placeholders;
}
}
if ($newUnusedPlaceholders = $bag->getUnusedEnvPlaceholders()) {
$this->unusedEnvPlaceholders += $newUnusedPlaceholders;
foreach ($newUnusedPlaceholders as $env => $placeholders) {
$this->unusedEnvPlaceholders[$env] += $placeholders;
}
}
}
/**
* Maps env prefixes to their corresponding PHP types.
@@ -95,13 +129,8 @@ class EnvPlaceholderParameterBag extends \YoastSEO_Vendor\Symfony\Component\Depe
}
parent::resolve();
foreach ($this->envPlaceholders as $env => $placeholders) {
if (!$this->has($name = "env({$env})")) {
continue;
}
if (\is_numeric($default = $this->parameters[$name])) {
$this->parameters[$name] = (string) $default;
} elseif (null !== $default && !\is_scalar($default)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('The default value of env parameter "%s" must be scalar or null, "%s" given.', $env, \gettype($default)));
if ($this->has($name = "env({$env})") && null !== ($default = $this->parameters[$name]) && !\is_string($default)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('The default value of env parameter "%s" must be a string or null, "%s" given.', $env, \get_debug_type($default)));
}
}
}
@@ -48,14 +48,14 @@ class FrozenParameterBag extends \YoastSEO_Vendor\Symfony\Component\DependencyIn
/**
* {@inheritdoc}
*/
public function set($name, $value)
public function set(string $name, $value)
{
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\LogicException('Impossible to call set() on a frozen ParameterBag.');
}
/**
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\LogicException('Impossible to call remove() on a frozen ParameterBag.');
}
@@ -22,25 +22,19 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
{
protected $parameters = [];
protected $resolved = \false;
private $normalizedNames = [];
/**
* @param array $parameters An array of parameters
*/
public function __construct(array $parameters = [])
{
$this->add($parameters);
}
/**
* Clears all parameters.
* {@inheritdoc}
*/
public function clear()
{
$this->parameters = [];
}
/**
* Adds parameters to the service container parameters.
*
* @param array $parameters An array of parameters
* {@inheritdoc}
*/
public function add(array $parameters)
{
@@ -58,9 +52,8 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
$name = $this->normalizeName($name);
if (!\array_key_exists($name, $this->parameters)) {
if (!$name) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException($name);
@@ -68,12 +61,12 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
$alternatives = [];
foreach ($this->parameters as $key => $parameterValue) {
$lev = \levenshtein($name, $key);
if ($lev <= \strlen($name) / 3 || \false !== \strpos($key, $name)) {
if ($lev <= \strlen($name) / 3 || \str_contains($key, $name)) {
$alternatives[] = $key;
}
}
$nonNestedAlternative = null;
if (!\count($alternatives) && \false !== \strpos($name, '.')) {
if (!\count($alternatives) && \str_contains($name, '.')) {
$namePartsLength = \array_map('strlen', \explode('.', $name));
$key = \substr($name, 0, -1 * (1 + \array_pop($namePartsLength)));
while (\count($namePartsLength)) {
@@ -91,30 +84,25 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
return $this->parameters[$name];
}
/**
* Sets a service container parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* {@inheritdoc}
*/
public function set($name, $value)
public function set(string $name, $value)
{
$this->parameters[$this->normalizeName($name)] = $value;
$this->parameters[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return \array_key_exists($this->normalizeName($name), $this->parameters);
return \array_key_exists($name, $this->parameters);
}
/**
* Removes a parameter.
*
* @param string $name The parameter name
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
unset($this->parameters[$this->normalizeName($name)]);
unset($this->parameters[$name]);
}
/**
* {@inheritdoc}
@@ -143,7 +131,7 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
* @param mixed $value A value
* @param array $resolving An array of keys that are being resolved (used internally to detect circular references)
*
* @return mixed The resolved value
* @return mixed
*
* @throws ParameterNotFoundException if a placeholder references a parameter that does not exist
* @throws ParameterCircularReferenceException if a circular reference if detected
@@ -166,28 +154,25 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
/**
* Resolves parameters inside a string.
*
* @param string $value The string to resolve
* @param array $resolving An array of keys that are being resolved (used internally to detect circular references)
* @param array $resolving An array of keys that are being resolved (used internally to detect circular references)
*
* @return mixed The resolved string
* @return mixed
*
* @throws ParameterNotFoundException if a placeholder references a parameter that does not exist
* @throws ParameterCircularReferenceException if a circular reference if detected
* @throws RuntimeException when a given parameter has a type problem
*/
public function resolveString($value, array $resolving = [])
public function resolveString(string $value, array $resolving = [])
{
// we do this to deal with non string values (Boolean, integer, ...)
// as the preg_replace_callback throw an exception when trying
// a non-string in a parameter value
if (\preg_match('/^%([^%\\s]+)%$/', $value, $match)) {
$key = $match[1];
$lcKey = \strtolower($key);
// strtolower() to be removed in 4.0
if (isset($resolving[$lcKey])) {
if (isset($resolving[$key])) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException(\array_keys($resolving));
}
$resolving[$lcKey] = \true;
$resolving[$key] = \true;
return $this->resolved ? $this->get($key) : $this->resolveValue($this->get($key), $resolving);
}
return \preg_replace_callback('/%%|%([^%\\s]+)%/', function ($match) use($resolving, $value) {
@@ -196,17 +181,15 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
return '%%';
}
$key = $match[1];
$lcKey = \strtolower($key);
// strtolower() to be removed in 4.0
if (isset($resolving[$lcKey])) {
if (isset($resolving[$key])) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException(\array_keys($resolving));
}
$resolved = $this->get($key);
if (!\is_string($resolved) && !\is_numeric($resolved)) {
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type "%s" inside string value "%s".', $key, \gettype($resolved), $value));
throw new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('A string value must be composed of strings and/or numbers, but found parameter "%s" of type "%s" inside string value "%s".', $key, \get_debug_type($resolved), $value));
}
$resolved = (string) $resolved;
$resolving[$lcKey] = \true;
$resolving[$key] = \true;
return $this->isResolved() ? $resolved : $this->resolveString($resolved, $resolving);
}, $value);
}
@@ -248,16 +231,4 @@ class ParameterBag implements \YoastSEO_Vendor\Symfony\Component\DependencyInjec
}
return $value;
}
private function normalizeName($name)
{
if (isset($this->normalizedNames[$normalizedName = \strtolower($name)])) {
$normalizedName = $this->normalizedNames[$normalizedName];
if ((string) $name !== $normalizedName) {
@\trigger_error(\sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since Symfony 3.4.', $name, $normalizedName), \E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
}
@@ -13,7 +13,7 @@ namespace YoastSEO_Vendor\Symfony\Component\DependencyInjection\ParameterBag;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\LogicException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
/**
* ParameterBagInterface.
* ParameterBagInterface is the interface implemented by objects that manage service container parameters.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
@@ -22,56 +22,47 @@ interface ParameterBagInterface
/**
* Clears all parameters.
*
* @throws LogicException if the ParameterBagInterface can not be cleared
* @throws LogicException if the ParameterBagInterface cannot be cleared
*/
public function clear();
/**
* Adds parameters to the service container parameters.
*
* @param array $parameters An array of parameters
*
* @throws LogicException if the parameter can not be added
* @throws LogicException if the parameter cannot be added
*/
public function add(array $parameters);
/**
* Gets the service container parameters.
*
* @return array An array of parameters
* @return array
*/
public function all();
/**
* Gets a service container parameter.
*
* @param string $name The parameter name
*
* @return mixed The parameter value
* @return array|bool|string|int|float|\UnitEnum|null
*
* @throws ParameterNotFoundException if the parameter is not defined
*/
public function get($name);
public function get(string $name);
/**
* Removes a parameter.
*
* @param string $name The parameter name
*/
public function remove($name);
public function remove(string $name);
/**
* Sets a service container parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* @param array|bool|string|int|float|\UnitEnum|null $value The parameter value
*
* @throws LogicException if the parameter can not be set
* @throws LogicException if the parameter cannot be set
*/
public function set($name, $value);
public function set(string $name, $value);
/**
* Returns true if a parameter name is defined.
*
* @param string $name The parameter name
*
* @return bool true if the parameter name is defined, false otherwise
* @return bool
*/
public function has($name);
public function has(string $name);
/**
* Replaces parameter placeholders (%name%) by their values for all parameters.
*/
@@ -1,30 +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 YoastSEO_Vendor\Symfony\Component\DependencyInjection;
/**
* ResettableContainerInterface defines additional resetting functionality
* for containers, allowing to release shared services when the container is
* not needed anymore.
*
* @author Christophe Coevoet <stof@notk.org>
*/
interface ResettableContainerInterface extends \YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface
{
/**
* Resets shared services from the container.
*
* The container is not intended to be used again after being reset in a normal workflow. This method is
* meant as a way to release references for ref-counting.
* A subsequent call to ContainerInterface::get will recreate a new instance of the shared service.
*/
public function reset();
}
@@ -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 YoastSEO_Vendor\Symfony\Component\DependencyInjection;
use YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface;
use YoastSEO_Vendor\Psr\Container\NotFoundExceptionInterface;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use YoastSEO_Vendor\Symfony\Contracts\Service\ServiceLocatorTrait;
use YoastSEO_Vendor\Symfony\Contracts\Service\ServiceProviderInterface;
use YoastSEO_Vendor\Symfony\Contracts\Service\ServiceSubscriberInterface;
/**
* @author Robin Chalas <robin.chalas@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*/
class ServiceLocator implements \YoastSEO_Vendor\Symfony\Contracts\Service\ServiceProviderInterface
{
use ServiceLocatorTrait {
get as private doGet;
}
private $externalId;
private $container;
/**
* {@inheritdoc}
*
* @return mixed
*/
public function get(string $id)
{
if (!$this->externalId) {
return $this->doGet($id);
}
try {
return $this->doGet($id);
} catch (\YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\RuntimeException $e) {
$what = \sprintf('service "%s" required by "%s"', $id, $this->externalId);
$message = \preg_replace('/service "\\.service_locator\\.[^"]++"/', $what, $e->getMessage());
if ($e->getMessage() === $message) {
$message = \sprintf('Cannot resolve %s: %s', $what, $message);
}
$r = new \ReflectionProperty($e, 'message');
$r->setAccessible(\true);
$r->setValue($e, $message);
throw $e;
}
}
public function __invoke(string $id)
{
return isset($this->factories[$id]) ? $this->get($id) : null;
}
/**
* @internal
*
* @return static
*/
public function withContext(string $externalId, \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Container $container) : self
{
$locator = clone $this;
$locator->externalId = $externalId;
$locator->container = $container;
return $locator;
}
private function createNotFoundException(string $id) : \YoastSEO_Vendor\Psr\Container\NotFoundExceptionInterface
{
if ($this->loading) {
$msg = \sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', \end($this->loading), $id, $this->formatAlternatives());
return new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id, \end($this->loading) ?: null, null, [], $msg);
}
$class = \debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 4);
$class = isset($class[3]['object']) ? \get_class($class[3]['object']) : null;
$externalId = $this->externalId ?: $class;
$msg = [];
$msg[] = \sprintf('Service "%s" not found:', $id);
if (!$this->container) {
$class = null;
} elseif ($this->container->has($id) || isset($this->container->getRemovedIds()[$id])) {
$msg[] = 'even though it exists in the app\'s container,';
} else {
try {
$this->container->get($id);
$class = null;
} catch (\YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException $e) {
if ($e->getAlternatives()) {
$msg[] = \sprintf('did you mean %s? Anyway,', $this->formatAlternatives($e->getAlternatives(), 'or'));
} else {
$class = null;
}
}
}
if ($externalId) {
$msg[] = \sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives());
} else {
$msg[] = \sprintf('the current service locator %s', $this->formatAlternatives());
}
if (!$class) {
// no-op
} elseif (\is_subclass_of($class, \YoastSEO_Vendor\Symfony\Contracts\Service\ServiceSubscriberInterface::class)) {
$msg[] = \sprintf('Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', \preg_replace('/([^\\\\]++\\\\)++/', '', $class));
} else {
$msg[] = 'Try using dependency injection instead.';
}
return new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException($id, \end($this->loading) ?: null, null, [], \implode(' ', $msg));
}
private function createCircularReferenceException(string $id, array $path) : \YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface
{
return new \YoastSEO_Vendor\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException($id, $path);
}
private function formatAlternatives(?array $alternatives = null, string $separator = 'and') : string
{
$format = '"%s"%s';
if (null === $alternatives) {
if (!($alternatives = \array_keys($this->factories))) {
return 'is empty...';
}
$format = \sprintf('only knows about the %s service%s.', $format, 1 < \count($alternatives) ? 's' : '');
}
$last = \array_pop($alternatives);
return \sprintf($format, $alternatives ? \implode('", "', $alternatives) : $last, $alternatives ? \sprintf(' %s "%s"', $separator, $last) : '');
}
}
@@ -0,0 +1,29 @@
<?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 YoastSEO_Vendor\Symfony\Contracts\Service;
/**
* Provides a way to reset an object to its initial state.
*
* When calling the "reset()" method on an object, it should be put back to its
* initial state. This usually means clearing any internal buffers and forwarding
* the call to internal dependencies. All properties of the object should be put
* back to the same state it had when it was first ready to use.
*
* This method could be called, for example, to recycle objects that are used as
* services, so that they can be used to handle several requests in the same
* process loop (note that we advise making your services stateless instead of
* implementing this interface when possible.)
*/
interface ResetInterface
{
public function reset();
}
@@ -0,0 +1,113 @@
<?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 YoastSEO_Vendor\Symfony\Contracts\Service;
use YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface;
use YoastSEO_Vendor\Psr\Container\NotFoundExceptionInterface;
// Help opcache.preload discover always-needed symbols
\class_exists(\YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface::class);
\class_exists(\YoastSEO_Vendor\Psr\Container\NotFoundExceptionInterface::class);
/**
* A trait to help implement ServiceProviderInterface.
*
* @author Robin Chalas <robin.chalas@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*/
trait ServiceLocatorTrait
{
private $factories;
private $loading = [];
private $providedTypes;
/**
* @param callable[] $factories
*/
public function __construct(array $factories)
{
$this->factories = $factories;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function has(string $id)
{
return isset($this->factories[$id]);
}
/**
* {@inheritdoc}
*
* @return mixed
*/
public function get(string $id)
{
if (!isset($this->factories[$id])) {
throw $this->createNotFoundException($id);
}
if (isset($this->loading[$id])) {
$ids = \array_values($this->loading);
$ids = \array_slice($this->loading, \array_search($id, $ids));
$ids[] = $id;
throw $this->createCircularReferenceException($id, $ids);
}
$this->loading[$id] = $id;
try {
return $this->factories[$id]($this);
} finally {
unset($this->loading[$id]);
}
}
/**
* {@inheritdoc}
*/
public function getProvidedServices() : array
{
if (null === $this->providedTypes) {
$this->providedTypes = [];
foreach ($this->factories as $name => $factory) {
if (!\is_callable($factory)) {
$this->providedTypes[$name] = '?';
} else {
$type = (new \ReflectionFunction($factory))->getReturnType();
$this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '') . ($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?';
}
}
}
return $this->providedTypes;
}
private function createNotFoundException(string $id) : \YoastSEO_Vendor\Psr\Container\NotFoundExceptionInterface
{
if (!($alternatives = \array_keys($this->factories))) {
$message = 'is empty...';
} else {
$last = \array_pop($alternatives);
if ($alternatives) {
$message = \sprintf('only knows about the "%s" and "%s" services.', \implode('", "', $alternatives), $last);
} else {
$message = \sprintf('only knows about the "%s" service.', $last);
}
}
if ($this->loading) {
$message = \sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', \end($this->loading), $id, $message);
} else {
$message = \sprintf('Service "%s" not found: the current service locator %s', $id, $message);
}
return new class($message) extends \InvalidArgumentException implements \YoastSEO_Vendor\Psr\Container\NotFoundExceptionInterface
{
};
}
private function createCircularReferenceException(string $id, array $path) : \YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface
{
return new class(\sprintf('Circular reference detected for service "%s", path: "%s".', $id, \implode(' -> ', $path))) extends \RuntimeException implements \YoastSEO_Vendor\Psr\Container\ContainerExceptionInterface
{
};
}
}
@@ -0,0 +1,34 @@
<?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 YoastSEO_Vendor\Symfony\Contracts\Service;
use YoastSEO_Vendor\Psr\Container\ContainerInterface;
/**
* A ServiceProviderInterface exposes the identifiers and the types of services provided by a container.
*
* @author Nicolas Grekas <p@tchwork.com>
* @author Mateusz Sip <mateusz.sip@gmail.com>
*/
interface ServiceProviderInterface extends \YoastSEO_Vendor\Psr\Container\ContainerInterface
{
/**
* Returns an associative array of service types keyed by the identifiers provided by the current container.
*
* Examples:
*
* * ['logger' => 'Psr\Log\LoggerInterface'] means the object provides a service named "logger" that implements Psr\Log\LoggerInterface
* * ['foo' => '?'] means the container provides service name "foo" of unspecified type
* * ['bar' => '?Bar\Baz'] means the container provides a service "bar" of type Bar\Baz|null
*
* @return string[] The provided service types, keyed by service names
*/
public function getProvidedServices() : array;
}