mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -11,13 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\Config\Resource;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class ReflectionClassResource implements SelfCheckingResourceInterface, \Serializable
|
||||
class ReflectionClassResource implements SelfCheckingResourceInterface
|
||||
{
|
||||
private $files = [];
|
||||
private $className;
|
||||
@@ -25,14 +28,17 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
private $excludedVendors = [];
|
||||
private $hash;
|
||||
|
||||
public function __construct(\ReflectionClass $classReflector, $excludedVendors = [])
|
||||
public function __construct(\ReflectionClass $classReflector, array $excludedVendors = [])
|
||||
{
|
||||
$this->className = $classReflector->name;
|
||||
$this->classReflector = $classReflector;
|
||||
$this->excludedVendors = $excludedVendors;
|
||||
}
|
||||
|
||||
public function isFresh($timestamp)
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFresh(int $timestamp): bool
|
||||
{
|
||||
if (null === $this->hash) {
|
||||
$this->hash = $this->computeHash();
|
||||
@@ -52,7 +58,7 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'reflection.'.$this->className;
|
||||
}
|
||||
@@ -60,22 +66,14 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function serialize()
|
||||
public function __sleep(): array
|
||||
{
|
||||
if (null === $this->hash) {
|
||||
$this->hash = $this->computeHash();
|
||||
$this->loadFiles($this->classReflector);
|
||||
}
|
||||
|
||||
return serialize([$this->files, $this->className, $this->hash]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
list($this->files, $this->className, $this->hash) = unserialize($serialized);
|
||||
return ['files', 'className', 'hash'];
|
||||
}
|
||||
|
||||
private function loadFiles(\ReflectionClass $class)
|
||||
@@ -85,9 +83,9 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
}
|
||||
do {
|
||||
$file = $class->getFileName();
|
||||
if (false !== $file && file_exists($file)) {
|
||||
if (false !== $file && is_file($file)) {
|
||||
foreach ($this->excludedVendors as $vendor) {
|
||||
if (0 === strpos($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
|
||||
if (str_starts_with($file, $vendor) && false !== strpbrk(substr($file, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
|
||||
$file = false;
|
||||
break;
|
||||
}
|
||||
@@ -102,7 +100,7 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
} while ($class = $class->getParentClass());
|
||||
}
|
||||
|
||||
private function computeHash()
|
||||
private function computeHash(): string
|
||||
{
|
||||
if (null === $this->classReflector) {
|
||||
try {
|
||||
@@ -121,8 +119,17 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
return hash_final($hash);
|
||||
}
|
||||
|
||||
private function generateSignature(\ReflectionClass $class)
|
||||
private function generateSignature(\ReflectionClass $class): iterable
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
$attributes = [];
|
||||
foreach ($class->getAttributes() as $a) {
|
||||
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
|
||||
}
|
||||
yield print_r($attributes, true);
|
||||
$attributes = [];
|
||||
}
|
||||
|
||||
yield $class->getDocComment();
|
||||
yield (int) $class->isFinal();
|
||||
yield (int) $class->isAbstract();
|
||||
@@ -139,6 +146,14 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
$defaults = $class->getDefaultProperties();
|
||||
|
||||
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
foreach ($p->getAttributes() as $a) {
|
||||
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
|
||||
}
|
||||
yield print_r($attributes, true);
|
||||
$attributes = [];
|
||||
}
|
||||
|
||||
yield $p->getDocComment();
|
||||
yield $p->isDefault() ? '<default>' : '';
|
||||
yield $p->isPublic() ? 'public' : 'protected';
|
||||
@@ -148,67 +163,84 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
}
|
||||
}
|
||||
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
|
||||
// workaround HHVM bug with variadics, see https://github.com/facebook/hhvm/issues/5762
|
||||
yield preg_replace('/^ @@.*/m', '', new ReflectionMethodHhvmWrapper($m->class, $m->name));
|
||||
$defined = \Closure::bind(static function ($c) { return \defined($c); }, null, $class->name);
|
||||
|
||||
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
foreach ($m->getAttributes() as $a) {
|
||||
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
|
||||
}
|
||||
yield print_r($attributes, true);
|
||||
$attributes = [];
|
||||
}
|
||||
} else {
|
||||
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
|
||||
$defaults = [];
|
||||
$parametersWithUndefinedConstants = [];
|
||||
|
||||
$defaults = [];
|
||||
$parametersWithUndefinedConstants = [];
|
||||
foreach ($m->getParameters() as $p) {
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
foreach ($p->getAttributes() as $a) {
|
||||
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
|
||||
}
|
||||
yield print_r($attributes, true);
|
||||
$attributes = [];
|
||||
}
|
||||
|
||||
if (!$p->isDefaultValueAvailable()) {
|
||||
$defaults[$p->name] = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (\PHP_VERSION_ID >= 80100) {
|
||||
$defaults[$p->name] = (string) $p;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$p->isDefaultValueConstant() || $defined($p->getDefaultValueConstantName())) {
|
||||
$defaults[$p->name] = $p->getDefaultValue();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$defaults[$p->name] = $p->getDefaultValueConstantName();
|
||||
$parametersWithUndefinedConstants[$p->name] = true;
|
||||
}
|
||||
|
||||
if (!$parametersWithUndefinedConstants) {
|
||||
yield preg_replace('/^ @@.*/m', '', $m);
|
||||
} else {
|
||||
$t = $m->getReturnType();
|
||||
$stack = [
|
||||
$m->getDocComment(),
|
||||
$m->getName(),
|
||||
$m->isAbstract(),
|
||||
$m->isFinal(),
|
||||
$m->isStatic(),
|
||||
$m->isPublic(),
|
||||
$m->isPrivate(),
|
||||
$m->isProtected(),
|
||||
$m->returnsReference(),
|
||||
$t instanceof \ReflectionNamedType ? ((string) $t->allowsNull()).$t->getName() : (string) $t,
|
||||
];
|
||||
|
||||
foreach ($m->getParameters() as $p) {
|
||||
if (!$p->isDefaultValueAvailable()) {
|
||||
$defaults[$p->name] = null;
|
||||
|
||||
continue;
|
||||
if (!isset($parametersWithUndefinedConstants[$p->name])) {
|
||||
$stack[] = (string) $p;
|
||||
} else {
|
||||
$t = $p->getType();
|
||||
$stack[] = $p->isOptional();
|
||||
$stack[] = $t instanceof \ReflectionNamedType ? ((string) $t->allowsNull()).$t->getName() : (string) $t;
|
||||
$stack[] = $p->isPassedByReference();
|
||||
$stack[] = $p->isVariadic();
|
||||
$stack[] = $p->getName();
|
||||
}
|
||||
|
||||
if (!$p->isDefaultValueConstant() || \defined($p->getDefaultValueConstantName())) {
|
||||
$defaults[$p->name] = $p->getDefaultValue();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$defaults[$p->name] = $p->getDefaultValueConstantName();
|
||||
$parametersWithUndefinedConstants[$p->name] = true;
|
||||
}
|
||||
|
||||
if (!$parametersWithUndefinedConstants) {
|
||||
yield preg_replace('/^ @@.*/m', '', $m);
|
||||
} else {
|
||||
$t = \PHP_VERSION_ID >= 70000 ? $m->getReturnType() : '';
|
||||
$stack = [
|
||||
$m->getDocComment(),
|
||||
$m->getName(),
|
||||
$m->isAbstract(),
|
||||
$m->isFinal(),
|
||||
$m->isStatic(),
|
||||
$m->isPublic(),
|
||||
$m->isPrivate(),
|
||||
$m->isProtected(),
|
||||
$m->returnsReference(),
|
||||
$t instanceof \ReflectionNamedType ? ((string) $t->allowsNull()).$t->getName() : (string) $t,
|
||||
];
|
||||
|
||||
foreach ($m->getParameters() as $p) {
|
||||
if (!isset($parametersWithUndefinedConstants[$p->name])) {
|
||||
$stack[] = (string) $p;
|
||||
} else {
|
||||
$t = \PHP_VERSION_ID >= 70000 ? $p->getType() : '';
|
||||
$stack[] = $p->isOptional();
|
||||
$stack[] = $t instanceof \ReflectionNamedType ? ((string) $t->allowsNull()).$t->getName() : (string) $t;
|
||||
$stack[] = $p->isPassedByReference();
|
||||
$stack[] = \PHP_VERSION_ID >= 50600 ? $p->isVariadic() : '';
|
||||
$stack[] = $p->getName();
|
||||
}
|
||||
}
|
||||
|
||||
yield implode(',', $stack);
|
||||
}
|
||||
|
||||
yield print_r($defaults, true);
|
||||
yield implode(',', $stack);
|
||||
}
|
||||
|
||||
yield print_r($defaults, true);
|
||||
}
|
||||
|
||||
if ($class->isAbstract() || $class->isInterface() || $class->isTrait()) {
|
||||
@@ -217,40 +249,19 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali
|
||||
|
||||
if (interface_exists(EventSubscriberInterface::class, false) && $class->isSubclassOf(EventSubscriberInterface::class)) {
|
||||
yield EventSubscriberInterface::class;
|
||||
yield print_r(\call_user_func([$class->name, 'getSubscribedEvents']), true);
|
||||
yield print_r($class->name::getSubscribedEvents(), true);
|
||||
}
|
||||
|
||||
if (interface_exists(MessageSubscriberInterface::class, false) && $class->isSubclassOf(MessageSubscriberInterface::class)) {
|
||||
yield MessageSubscriberInterface::class;
|
||||
foreach ($class->name::getHandledMessages() as $key => $value) {
|
||||
yield $key.print_r($value, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (interface_exists(ServiceSubscriberInterface::class, false) && $class->isSubclassOf(ServiceSubscriberInterface::class)) {
|
||||
yield ServiceSubscriberInterface::class;
|
||||
yield print_r(\call_user_func([$class->name, 'getSubscribedServices']), true);
|
||||
yield print_r($class->name::getSubscribedServices(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ReflectionMethodHhvmWrapper extends \ReflectionMethod
|
||||
{
|
||||
public function getParameters()
|
||||
{
|
||||
$params = [];
|
||||
|
||||
foreach (parent::getParameters() as $i => $p) {
|
||||
$params[] = new ReflectionParameterHhvmWrapper([$this->class, $this->name], $i);
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class ReflectionParameterHhvmWrapper extends \ReflectionParameter
|
||||
{
|
||||
public function getDefaultValue()
|
||||
{
|
||||
return [$this->isVariadic(), $this->isDefaultValueAvailable() ? parent::getDefaultValue() : null];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user