mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +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:
@@ -27,27 +27,21 @@ use Symfony\Component\CssSelector\XPath\XPathExpr;
|
||||
*/
|
||||
class NodeExtension extends AbstractExtension
|
||||
{
|
||||
const ELEMENT_NAME_IN_LOWER_CASE = 1;
|
||||
const ATTRIBUTE_NAME_IN_LOWER_CASE = 2;
|
||||
const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4;
|
||||
public const ELEMENT_NAME_IN_LOWER_CASE = 1;
|
||||
public const ATTRIBUTE_NAME_IN_LOWER_CASE = 2;
|
||||
public const ATTRIBUTE_VALUE_IN_LOWER_CASE = 4;
|
||||
|
||||
private $flags;
|
||||
|
||||
/**
|
||||
* @param int $flags
|
||||
*/
|
||||
public function __construct($flags = 0)
|
||||
public function __construct(int $flags = 0)
|
||||
{
|
||||
$this->flags = $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $flag
|
||||
* @param bool $on
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFlag($flag, $on)
|
||||
public function setFlag(int $flag, bool $on): self
|
||||
{
|
||||
if ($on && !$this->hasFlag($flag)) {
|
||||
$this->flags += $flag;
|
||||
@@ -60,12 +54,7 @@ class NodeExtension extends AbstractExtension
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFlag($flag)
|
||||
public function hasFlag(int $flag): bool
|
||||
{
|
||||
return (bool) ($this->flags & $flag);
|
||||
}
|
||||
@@ -73,7 +62,7 @@ class NodeExtension extends AbstractExtension
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNodeTranslators()
|
||||
public function getNodeTranslators(): array
|
||||
{
|
||||
return [
|
||||
'Selector' => [$this, 'translateSelector'],
|
||||
@@ -88,26 +77,17 @@ class NodeExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateSelector(Node\SelectorNode $node, Translator $translator)
|
||||
public function translateSelector(Node\SelectorNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
return $translator->nodeToXPath($node->getTree());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateCombinedSelector(Node\CombinedSelectorNode $node, Translator $translator)
|
||||
public function translateCombinedSelector(Node\CombinedSelectorNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
return $translator->addCombination($node->getCombinator(), $node->getSelector(), $node->getSubSelector());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateNegation(Node\NegationNode $node, Translator $translator)
|
||||
public function translateNegation(Node\NegationNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||
$subXpath = $translator->nodeToXPath($node->getSubSelector());
|
||||
@@ -120,30 +100,21 @@ class NodeExtension extends AbstractExtension
|
||||
return $xpath->addCondition('0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateFunction(Node\FunctionNode $node, Translator $translator)
|
||||
public function translateFunction(Node\FunctionNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||
|
||||
return $translator->addFunction($xpath, $node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translatePseudo(Node\PseudoNode $node, Translator $translator)
|
||||
public function translatePseudo(Node\PseudoNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||
|
||||
return $translator->addPseudoClass($xpath, $node->getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateAttribute(Node\AttributeNode $node, Translator $translator)
|
||||
public function translateAttribute(Node\AttributeNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
$name = $node->getAttribute();
|
||||
$safe = $this->isSafeName($name);
|
||||
@@ -168,34 +139,25 @@ class NodeExtension extends AbstractExtension
|
||||
return $translator->addAttributeMatching($xpath, $node->getOperator(), $attribute, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateClass(Node\ClassNode $node, Translator $translator)
|
||||
public function translateClass(Node\ClassNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||
|
||||
return $translator->addAttributeMatching($xpath, '~=', '@class', $node->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateHash(Node\HashNode $node, Translator $translator)
|
||||
public function translateHash(Node\HashNode $node, Translator $translator): XPathExpr
|
||||
{
|
||||
$xpath = $translator->nodeToXPath($node->getSelector());
|
||||
|
||||
return $translator->addAttributeMatching($xpath, '=', '@id', $node->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return XPathExpr
|
||||
*/
|
||||
public function translateElement(Node\ElementNode $node)
|
||||
public function translateElement(Node\ElementNode $node): XPathExpr
|
||||
{
|
||||
$element = $node->getElement();
|
||||
|
||||
if ($this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
|
||||
if ($element && $this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
|
||||
$element = strtolower($element);
|
||||
}
|
||||
|
||||
@@ -223,19 +185,12 @@ class NodeExtension extends AbstractExtension
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return 'node';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if given name is safe.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isSafeName($name)
|
||||
private function isSafeName(string $name): bool
|
||||
{
|
||||
return 0 < preg_match('~^[a-zA-Z_][a-zA-Z0-9_.-]*$~', $name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user