Вход Регистрация
Файл: gapps/vendor/nikic/php-parser/lib/PhpParser/BuilderAbstract.php
Строк: 173
<?php

namespace PhpParser;

use 
PhpParserNodeName;
use 
PhpParserNodeExpr;
use 
PhpParserNodeStmt;
use 
PhpParserNodeScalar;
use 
PhpParserComment;

abstract class 
BuilderAbstract implements Builder {
    
/**
     * Normalizes a node: Converts builder objects to nodes.
     *
     * @param Node|Builder $node The node to normalize
     *
     * @return Node The normalized node
     */
    
protected function normalizeNode($node) {
        if (
$node instanceof Builder) {
            return 
$node->getNode();
        } elseif (
$node instanceof Node) {
            return 
$node;
        }

        throw new 
LogicException('Expected node or builder object');
    }

    
/**
     * Normalizes a name: Converts plain string names to PhpParserNodeName.
     *
     * @param Name|string $name The name to normalize
     *
     * @return Name The normalized name
     */
    
protected function normalizeName($name) {
        if (
$name instanceof Name) {
            return 
$name;
        } elseif (
is_string($name)) {
            if (!
$name) {
                throw new 
LogicException('Name cannot be empty');
            }

            if (
$name[0] == '\') {
                return new NameFullyQualified(substr($name, 1));
            } elseif (0 === strpos($name, '
namespace\')) {
                return new NameRelative(substr($name, strlen('
namespace\')));
            } else {
                return new Name($name);
            }
        }

        throw new LogicException('
Name must be a string or an instance of PhpParserNodeName');
    }

    /**
     * Normalizes a value: Converts nulls, booleans, integers,
     * floats, strings and arrays into their respective nodes
     *
     * @param mixed $value The value to normalize
     *
     * @return Expr The normalized value
     */
    protected function normalizeValue($value) {
        if ($value instanceof Node) {
            return $value;
        } elseif (is_null($value)) {
            return new ExprConstFetch(
                new Name('
null')
            );
        } elseif (is_bool($value)) {
            return new ExprConstFetch(
                new Name($value ? '
true' : 'false')
            );
        } elseif (is_int($value)) {
            return new ScalarLNumber($value);
        } elseif (is_float($value)) {
            return new ScalarDNumber($value);
        } elseif (is_string($value)) {
            return new ScalarString_($value);
        } elseif (is_array($value)) {
            $items = array();
            $lastKey = -1;
            foreach ($value as $itemKey => $itemValue) {
                // for consecutive, numeric keys don'
t generate keys
                
if (null !== $lastKey && ++$lastKey === $itemKey) {
                    
$items[] = new ExprArrayItem(
                        
$this->normalizeValue($itemValue)
                    );
                } else {
                    
$lastKey null;
                    
$items[] = new ExprArrayItem(
                        
$this->normalizeValue($itemValue),
                        
$this->normalizeValue($itemKey)
                    );
                }
            }

            return new 
ExprArray_($items);
        } else {
            throw new 
LogicException('Invalid value');
        }
    }

    
/**
     * Normalizes a doc comment: Converts plain strings to PhpParserCommentDoc.
     *
     * @param CommentDoc|string $docComment The doc comment to normalize
     *
     * @return CommentDoc The normalized doc comment
     */
    
protected function normalizeDocComment($docComment) {
        if (
$docComment instanceof CommentDoc) {
            return 
$docComment;
        } else if (
is_string($docComment)) {
            return new 
CommentDoc($docComment);
        } else {
            throw new 
LogicException('Doc comment must be a string or an instance of PhpParserCommentDoc');
        }
    }

    
/**
     * Sets a modifier in the $this->type property.
     *
     * @param int $modifier Modifier to set
     */
    
protected function setModifier($modifier) {
        
StmtClass_::verifyModifier($this->type$modifier);
        
$this->type |= $modifier;
    }
}
Онлайн: 1
Реклама