Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EnumFunction.php

class EnumFunction

Hierarchy

  • class \Twig\Node\Node implements \Twig\Node\Countable, \Twig\Node\IteratorAggregate
    • class \Twig\Node\Expression\AbstractExpression extends \Twig\Node\Node
      • class \Twig\Node\Expression\CallExpression extends \Twig\Node\Expression\AbstractExpression
        • class \Twig\Node\Expression\FunctionExpression extends \Twig\Node\Expression\CallExpression
          • class \Twig\Node\Expression\FunctionNode\EnumFunction extends \Twig\Node\Expression\FunctionExpression

Expanded class hierarchy of EnumFunction

1 file declares its use of EnumFunction
CoreExtension.php in vendor/twig/twig/src/Extension/CoreExtension.php

File

vendor/twig/twig/src/Node/Expression/FunctionNode/EnumFunction.php, line 10

Namespace

Twig\Node\Expression\FunctionNode
View source
class EnumFunction extends FunctionExpression {
    public function compile(Compiler $compiler) : void {
        $arguments = $this->getNode('arguments');
        if ($arguments->hasNode('enum')) {
            $firstArgument = $arguments->getNode('enum');
        }
        elseif ($arguments->hasNode('0')) {
            $firstArgument = $arguments->getNode('0');
        }
        else {
            $firstArgument = null;
        }
        if (!$firstArgument instanceof ConstantExpression || 1 !== \count($arguments)) {
            parent::compile($compiler);
            return;
        }
        $value = $firstArgument->getAttribute('value');
        if (!\is_string($value)) {
            throw new SyntaxError('The first argument of the "enum" function must be a string.', $this->getTemplateLine(), $this->getSourceContext());
        }
        if (!enum_exists($value)) {
            throw new SyntaxError(\sprintf('The first argument of the "enum" function must be the name of an enum, "%s" given.', $value), $this->getTemplateLine(), $this->getSourceContext());
        }
        if (!($cases = $value::cases())) {
            throw new SyntaxError(\sprintf('The first argument of the "enum" function must be a non-empty enum, "%s" given.', $value), $this->getTemplateLine(), $this->getSourceContext());
        }
        $compiler->raw(\sprintf('%s::%s', $value, $cases[0]->name));
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
AbstractExpression::hasExplicitParentheses public function
AbstractExpression::isGenerator public function
AbstractExpression::setExplicitParentheses public function
CallExpression::$reflector private property
CallExpression::compileArguments protected function
CallExpression::compileCallable protected function
CallExpression::getArguments Deprecated protected function
CallExpression::getCallableParameters private function
CallExpression::getTwigCallable private function Overrides the Twig callable based on attributes (as potentially, attributes changed between the creation and the compilation of the node).
CallExpression::normalizeName Deprecated protected function
CallExpression::reflectCallable private function
EnumFunction::compile public function Overrides FunctionExpression::compile
FunctionExpression::__construct public function Overrides Node::__construct
Node::$attributeNameDeprecations private property @var array<string, NameDeprecation>
Node::$attributes protected property
Node::$lineno protected property
Node::$nodeNameDeprecations private property @var array<string, NameDeprecation>
Node::$nodes protected property
Node::$sourceContext private property
Node::$tag protected property
Node::count public function
Node::deprecateAttribute public function
Node::deprecateNode public function
Node::getAttribute public function
Node::getIterator public function
Node::getNode public function
Node::getNodeTag public function
Node::getSourceContext public function
Node::getTemplateLine public function
Node::getTemplateName public function
Node::hasAttribute public function
Node::hasNode public function
Node::removeAttribute public function
Node::removeNode public function
Node::setAttribute public function
Node::setNode public function 1
Node::setNodeTag public function @internal
Node::setSourceContext public function
Node::__toString public function
RSS feed
Powered by Drupal