Esempio n. 1
0
 /**
  * Create a new NullNode.
  *
  * @param string $name
  *   Parameter is ignored.
  *
  * @return NullNode
  */
 public static function create($name = 'null')
 {
     $is_upper = FormatterFactory::getDefaultFormatter()->getConfig('boolean_null_upper');
     $node = new NullNode();
     $node->addChild(NameNode::create($is_upper ? 'NULL' : 'null'), 'constantName');
     return $node;
 }
    /**
     * {@inheritdoc}
     */
    public function convert(TargetInterface $target)
    {
        $indexer = $target->getIndexer('function');
        $hooks = array_filter($this->pluginDefinition['hook'], [$indexer, 'has']);
        foreach ($hooks as $hook) {
            /** @var \Pharborist\Functions\FunctionDeclarationNode $function */
            $function = $indexer->get($hook);
            // The $edit parameter is defunct in Drupal 8, but we'll leave it in
            // there as an empty array to prevent errors, and move it to the back
            // of the line.
            /** @var \Pharborist\Functions\ParameterNode $edit */
            $edit = $function->getParameterList()->shift()->setReference(FALSE)->setValue(NullNode::create());
            $function->appendParameter($edit);
            // Slap a FIXME on the hook implementation, informing the developer that
            // $edit and $category are dead.
            $comment = $function->getDocComment();
            $comment_text = $comment ? $comment->getCommentText() : '';
            if ($comment_text) {
                $comment_text .= "\n\n";
            }
            $comment_text .= <<<'END'
@FIXME
The $edit and $category parameters are gone in Drupal 8. They have been left
here in order to prevent 'undefined variable' errors, but they will never
actually be passed to this hook. You'll need to modify this function and
remove every reference to them.
END;
            $function->setDocComment(DocCommentNode::create($comment_text));
            $this->rewriteFunction($this->rewriter, $function->getParameterAtIndex(0), $target);
            $target->save($function);
        }
    }
Esempio n. 3
0
 /**
  * Creates a Node from a php value.
  *
  * @param string|integer|float|boolean|array|null $value
  *  The value to create a node for.
  *
  * @return FloatNode|IntegerNode|StringNode|BooleanNode|NullNode|ArrayNode
  *
  * @throws \InvalidArgumentException if $value is not a scalar.
  */
 public static function fromValue($value)
 {
     if (is_array($value)) {
         $elements = [];
         foreach ($value as $k => $v) {
             $elements[] = ArrayPairNode::create(static::fromValue($k), static::fromValue($v));
         }
         return ArrayNode::create($elements);
     } elseif (is_string($value)) {
         return StringNode::create(var_export($value, TRUE));
     } elseif (is_integer($value)) {
         return new IntegerNode(T_LNUMBER, $value);
     } elseif (is_float($value)) {
         return new FloatNode(T_DNUMBER, $value);
     } elseif (is_bool($value)) {
         return BooleanNode::create($value);
     } elseif (is_null($value)) {
         return NullNode::create('NULL');
     } else {
         throw new \InvalidArgumentException();
     }
 }