This commit is contained in:
Sampanna Rimal
2024-09-04 12:22:04 +05:45
parent 53c0140f58
commit 82fab174dc
203 changed files with 4255 additions and 1343 deletions

View File

@ -25,7 +25,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",

View File

@ -25,7 +25,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",

View File

@ -48,7 +48,7 @@ final class WrappedListener
$this->callableRef .= '::'.$listener[1];
} elseif ($listener instanceof \Closure) {
$r = new \ReflectionFunction($listener);
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
$this->pretty = $this->name = 'closure';
} elseif ($class = $r->getClosureCalledClass()) {
$this->name = $class->name;

View File

@ -37,9 +37,9 @@ final class VcsIgnoredFilterIterator extends \FilterIterator
{
$this->baseDir = $this->normalizePath($baseDir);
foreach ($this->parentDirectoriesUpwards($this->baseDir) as $parentDirectory) {
if (@is_dir("{$parentDirectory}/.git")) {
$this->baseDir = $parentDirectory;
foreach ([$this->baseDir, ...$this->parentDirectoriesUpwards($this->baseDir)] as $directory) {
if (@is_dir("{$directory}/.git")) {
$this->baseDir = $directory;
break;
}
}

View File

@ -85,6 +85,7 @@ class RedirectResponse extends Response
</html>', htmlspecialchars($url, \ENT_QUOTES, 'UTF-8')));
$this->headers->set('Location', $url);
$this->headers->set('Content-Type', 'text/html; charset=utf-8');
return $this;
}

View File

@ -240,7 +240,7 @@ class ControllerResolver implements ControllerResolverInterface
$r = new \ReflectionFunction($controller);
$name = $r->name;
if (str_contains($name, '{closure}')) {
if (str_contains($name, '{closure')) {
$name = $class = \Closure::class;
} elseif ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
$class = $class->name;

View File

@ -63,9 +63,21 @@ abstract class DataCollector implements DataCollectorInterface
$casters = [
'*' => function ($v, array $a, Stub $s, $isNested) {
if (!$v instanceof Stub) {
$b = $a;
foreach ($a as $k => $v) {
if (\is_object($v) && !$v instanceof \DateTimeInterface && !$v instanceof Stub) {
$a[$k] = new CutStub($v);
if (!\is_object($v) || $v instanceof \DateTimeInterface || $v instanceof Stub) {
continue;
}
try {
$a[$k] = $s = new CutStub($v);
if ($b[$k] === $s) {
// we've hit a non-typed reference
$a[$k] = $v;
}
} catch (\TypeError $e) {
// we've hit a typed reference
}
}
}

View File

@ -505,7 +505,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
'line' => $r->getStartLine(),
];
if (str_contains($r->name, '{closure}')) {
if (str_contains($r->name, '{closure')) {
return $controller;
}
$controller['method'] = $r->name;

View File

@ -59,6 +59,7 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
foreach ($container->findTaggedServiceIds('controller.service_arguments', true) as $id => $tags) {
$def = $container->getDefinition($id);
$def->setPublic(true);
$def->setLazy(false);
$class = $def->getClass();
$autowire = $def->isAutowired();
$bindings = $def->getBindings();

View File

@ -98,7 +98,7 @@ final class ControllerEvent extends KernelEvent
} elseif (\is_string($this->controller) && false !== $i = strpos($this->controller, '::')) {
$class = new \ReflectionClass(substr($this->controller, 0, $i));
} else {
$class = str_contains($this->controllerReflector->name, '{closure}') ? null : (\PHP_VERSION_ID >= 80111 ? $this->controllerReflector->getClosureCalledClass() : $this->controllerReflector->getClosureScopeClass());
$class = str_contains($this->controllerReflector->name, '{closure') ? null : (\PHP_VERSION_ID >= 80111 ? $this->controllerReflector->getClosureCalledClass() : $this->controllerReflector->getClosureScopeClass());
}
$this->attributes = [];

View File

@ -76,11 +76,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
*/
private static array $freshCache = [];
public const VERSION = '6.4.6';
public const VERSION_ID = 60406;
public const VERSION = '6.4.7';
public const VERSION_ID = 60407;
public const MAJOR_VERSION = 6;
public const MINOR_VERSION = 4;
public const RELEASE_VERSION = 6;
public const RELEASE_VERSION = 7;
public const EXTRA_VERSION = '';
public const END_OF_MAINTENANCE = '11/2026';

View File

@ -44,6 +44,7 @@
"symfony/translation-contracts": "^2.5|^3",
"symfony/uid": "^5.4|^6.0|^7.0",
"symfony/validator": "^6.4|^7.0",
"symfony/var-dumper": "^5.4|^6.4|^7.0",
"symfony/var-exporter": "^6.2|^7.0",
"psr/cache": "^1.0|^2.0|^3.0",
"twig/twig": "^2.13|^3.0.4"

View File

@ -11,15 +11,15 @@
namespace Symfony\Contracts\Service\Attribute;
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
use Symfony\Contracts\Service\ServiceSubscriberTrait;
/**
* For use as the return value for {@see ServiceSubscriberInterface}.
*
* @example new SubscribedService('http_client', HttpClientInterface::class, false, new Target('githubApi'))
*
* Use with {@see ServiceSubscriberTrait} to mark a method's return type
* Use with {@see ServiceMethodsSubscriberTrait} to mark a method's return type
* as a subscribed service.
*
* @author Kevin Bond <kevinbond@gmail.com>

View File

@ -0,0 +1,26 @@
<?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\Contracts\Service;
/**
* A ServiceProviderInterface that is also countable and iterable.
*
* @author Kevin Bond <kevinbond@gmail.com>
*
* @template-covariant T of mixed
*
* @extends ServiceProviderInterface<T>
* @extends \IteratorAggregate<string, T>
*/
interface ServiceCollectionInterface extends ServiceProviderInterface, \Countable, \IteratorAggregate
{
}

View File

@ -0,0 +1,80 @@
<?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\Contracts\Service;
use Psr\Container\ContainerInterface;
use Symfony\Contracts\Service\Attribute\Required;
use Symfony\Contracts\Service\Attribute\SubscribedService;
/**
* Implementation of ServiceSubscriberInterface that determines subscribed services
* from methods that have the #[SubscribedService] attribute.
*
* Service ids are available as "ClassName::methodName" so that the implementation
* of subscriber methods can be just `return $this->container->get(__METHOD__);`.
*
* @author Kevin Bond <kevinbond@gmail.com>
*/
trait ServiceMethodsSubscriberTrait
{
protected ContainerInterface $container;
public static function getSubscribedServices(): array
{
$services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];
foreach ((new \ReflectionClass(self::class))->getMethods() as $method) {
if (self::class !== $method->getDeclaringClass()->name) {
continue;
}
if (!$attribute = $method->getAttributes(SubscribedService::class)[0] ?? null) {
continue;
}
if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) {
throw new \LogicException(sprintf('Cannot use "%s" on method "%s::%s()" (can only be used on non-static, non-abstract methods with no parameters).', SubscribedService::class, self::class, $method->name));
}
if (!$returnType = $method->getReturnType()) {
throw new \LogicException(sprintf('Cannot use "%s" on methods without a return type in "%s::%s()".', SubscribedService::class, $method->name, self::class));
}
/* @var SubscribedService $attribute */
$attribute = $attribute->newInstance();
$attribute->key ??= self::class.'::'.$method->name;
$attribute->type ??= $returnType instanceof \ReflectionNamedType ? $returnType->getName() : (string) $returnType;
$attribute->nullable = $returnType->allowsNull();
if ($attribute->attributes) {
$services[] = $attribute;
} else {
$services[$attribute->key] = ($attribute->nullable ? '?' : '').$attribute->type;
}
}
return $services;
}
#[Required]
public function setContainer(ContainerInterface $container): ?ContainerInterface
{
$ret = null;
if (method_exists(get_parent_class(self::class) ?: '', __FUNCTION__)) {
$ret = parent::setContainer($container);
}
$this->container = $container;
return $ret;
}
}

View File

@ -15,17 +15,23 @@ use Psr\Container\ContainerInterface;
use Symfony\Contracts\Service\Attribute\Required;
use Symfony\Contracts\Service\Attribute\SubscribedService;
trigger_deprecation('symfony/contracts', 'v3.5', '"%s" is deprecated, use "ServiceMethodsSubscriberTrait" instead.', ServiceSubscriberTrait::class);
/**
* Implementation of ServiceSubscriberInterface that determines subscribed services from
* method return types. Service ids are available as "ClassName::methodName".
* Implementation of ServiceSubscriberInterface that determines subscribed services
* from methods that have the #[SubscribedService] attribute.
*
* Service ids are available as "ClassName::methodName" so that the implementation
* of subscriber methods can be just `return $this->container->get(__METHOD__);`.
*
* @property ContainerInterface $container
*
* @author Kevin Bond <kevinbond@gmail.com>
*
* @deprecated since symfony/contracts v3.5, use ServiceMethodsSubscriberTrait instead
*/
trait ServiceSubscriberTrait
{
/** @var ContainerInterface */
protected $container;
public static function getSubscribedServices(): array
{
$services = method_exists(get_parent_class(self::class) ?: '', __FUNCTION__) ? parent::getSubscribedServices() : [];

View File

@ -12,7 +12,9 @@
namespace Symfony\Contracts\Service\Test;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Contracts\Service\ServiceLocatorTrait;
abstract class ServiceLocatorTestCase extends TestCase
@ -66,27 +68,29 @@ abstract class ServiceLocatorTestCase extends TestCase
public function testThrowsOnUndefinedInternalService()
{
if (!$this->getExpectedException()) {
$this->expectException(\Psr\Container\NotFoundExceptionInterface::class);
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
}
$locator = $this->getServiceLocator([
'foo' => function () use (&$locator) { return $locator->get('bar'); },
]);
if (!$this->getExpectedException()) {
$this->expectException(NotFoundExceptionInterface::class);
$this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.');
}
$locator->get('foo');
}
public function testThrowsOnCircularReference()
{
$this->expectException(\Psr\Container\ContainerExceptionInterface::class);
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
$locator = $this->getServiceLocator([
'foo' => function () use (&$locator) { return $locator->get('bar'); },
'bar' => function () use (&$locator) { return $locator->get('baz'); },
'baz' => function () use (&$locator) { return $locator->get('bar'); },
]);
$this->expectException(ContainerExceptionInterface::class);
$this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".');
$locator->get('foo');
}
}

View File

@ -17,7 +17,8 @@
],
"require": {
"php": ">=8.1",
"psr/container": "^1.1|^2.0"
"psr/container": "^1.1|^2.0",
"symfony/deprecation-contracts": "^2.5|^3"
},
"conflict": {
"ext-psr": "<1.1|>=2"
@ -31,7 +32,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",

View File

@ -129,7 +129,7 @@ class LazyString implements \Stringable, \JsonSerializable
} elseif ($callback instanceof \Closure) {
$r = new \ReflectionFunction($callback);
if (str_contains($r->name, '{closure}') || !$class = $r->getClosureCalledClass()) {
if (str_contains($r->name, '{closure') || !$class = $r->getClosureCalledClass()) {
return $r->name;
}

View File

@ -183,9 +183,10 @@ class TranslatorTest extends TestCase
*/
public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number)
{
$this->expectException(\InvalidArgumentException::class);
$translator = $this->getTranslator();
$this->expectException(\InvalidArgumentException::class);
$translator->trans($id, ['%count%' => $number]);
}

View File

@ -27,7 +27,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",

View File

@ -112,16 +112,20 @@ class XliffFileLoader implements LoaderInterface
continue;
}
if (isset($translation->target) && 'needs-translation' === (string) $translation->target->attributes()['state']) {
$source = (string) (isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source);
if (isset($translation->target)
&& 'needs-translation' === (string) $translation->target->attributes()['state']
&& \in_array((string) $translation->target, [$source, (string) $translation->source], true)
) {
continue;
}
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
$target = $this->utf8ToCharset((string) ($translation->target ?? $translation->source), $encoding);
$catalogue->set((string) $source, $target, $domain);
$catalogue->set($source, $target, $domain);
$metadata = [
'source' => (string) $translation->source,
@ -144,7 +148,7 @@ class XliffFileLoader implements LoaderInterface
$metadata['id'] = (string) $attributes['id'];
}
$catalogue->setMetadata((string) $source, $metadata, $domain);
$catalogue->setMetadata($source, $metadata, $domain);
}
}
}

View File

@ -34,9 +34,14 @@ class LocaleSwitcher implements LocaleAwareInterface
public function setLocale(string $locale): void
{
if (class_exists(\Locale::class)) {
\Locale::setDefault($locale);
// Silently ignore if the intl extension is not loaded
try {
if (class_exists(\Locale::class, false)) {
\Locale::setDefault($locale);
}
} catch (\Exception) {
}
$this->locale = $locale;
$this->requestContext?->setParameter('_locale', $locale);

View File

@ -162,11 +162,11 @@ function extractLocaleFromFilePath($filePath)
function extractTranslationKeys($filePath): array
{
$translationKeys = [];
$contents = new \SimpleXMLElement(file_get_contents($filePath));
$contents = new SimpleXMLElement(file_get_contents($filePath));
foreach ($contents->file->body->{'trans-unit'} as $translationKey) {
$translationId = (string) $translationKey['id'];
$translationKey = (string) $translationKey->source;
$translationKey = (string) ($translationKey['resname'] ?? $translationKey->source);
$translationKeys[$translationId] = $translationKey;
}

View File

@ -45,7 +45,7 @@ class ReflectionCaster
$a = static::castFunctionAbstract($c, $a, $stub, $isNested, $filter);
if (!str_contains($c->name, '{closure}')) {
if (!str_contains($c->name, '{closure')) {
$stub->class = isset($a[$prefix.'class']) ? $a[$prefix.'class']->value.'::'.$c->name : $c->name;
unset($a[$prefix.'class']);
}

View File

@ -633,12 +633,12 @@ class Parser
}
if ($this->isCurrentLineBlank()) {
$data[] = substr($this->currentLine, $newIndent);
$data[] = substr($this->currentLine, $newIndent ?? 0);
continue;
}
if ($indent >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
$data[] = substr($this->currentLine, $newIndent ?? 0);
} elseif ($this->isCurrentLineComment()) {
$data[] = $this->currentLine;
} elseif (0 == $indent) {