junk() static public méthode

static public junk ( )
Exemple #1
0
function parseUseDeclaration(Source $s, $pos, array &$aliases, $prefix = '', $type = 'class')
{
    $lastPart = null;
    $whole = $prefix;
    while (true) {
        switch ($s->tokens[$pos][Source::TYPE_OFFSET]) {
            case T_FUNCTION:
                $type = 'function';
                break;
            case T_CONST:
                $type = 'const';
                break;
            case T_NS_SEPARATOR:
                if (!empty($whole)) {
                    $whole .= '\\';
                }
                break;
            case T_STRING:
                $lastPart = $s->tokens[$pos][Source::STRING_OFFSET];
                $whole .= $lastPart;
                break;
            case T_AS:
                $pos = $s->skip(Source::junk(), $pos);
                $aliases[$type][$s->tokens[$pos][Source::STRING_OFFSET]] = $whole;
                $lastPart = null;
                $whole = $prefix;
                break;
            case ',':
                if ($lastPart !== null) {
                    $aliases[$type][$lastPart] = $whole;
                }
                $lastPart = null;
                $whole = $prefix;
                $type = 'class';
                break;
            case Generic\LEFT_CURLY:
                parseUseDeclaration($s, $pos, $aliases, $prefix . '\\', $type);
                break;
            case T_WHITESPACE:
            case T_COMMENT:
            case T_DOC_COMMENT:
                break;
            default:
                if ($lastPart !== null) {
                    $aliases[$type][$whole] = $lastPart;
                }
                return;
        }
        $pos++;
    }
}
function spliceNamedCallsWithin(Source $s, $begin, $end, array $names, array $aliases)
{
    foreach ($s->within(T_STRING, $begin, $end) as $string) {
        $original = strtolower($s->read($string));
        if (isset($names[$original]) || isset($aliases[$original])) {
            $previous = $s->skipBack(Source::junk(), $string);
            $hadBackslash = false;
            if ($s->is(T_NS_SEPARATOR, $previous)) {
                if (!isset($names[$original])) {
                    # use-aliased name cannot have a leading backslash
                    continue;
                }
                $s->splice('', $previous, 1);
                $previous = $s->skipBack(Source::junk(), $previous);
                $hadBackslash = true;
            }
            if ($s->is([T_FUNCTION, T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_STRING, T_NEW], $previous)) {
                continue;
            }
            $next = $s->skip(Source::junk(), $string);
            if (!$s->is(Generic\LEFT_ROUND, $next)) {
                continue;
            }
            if (isset($aliases[$original])) {
                $original = $aliases[$original];
            }
            $secondNext = $s->skip(Source::junk(), $next);
            $splice = '\\' . CallRerouting\INTERNAL_REDEFINITION_NAMESPACE . '\\';
            $splice .= $original . Generic\LEFT_ROUND;
            # prepend a namespace-of-origin argument to handle cases like Acme\time() vs time()
            $splice .= !$hadBackslash ? '__NAMESPACE__' : '""';
            if (!$s->is(Generic\RIGHT_ROUND, $secondNext)) {
                # right parenthesis doesn't follow immediately => there are arguments
                $splice .= ', ';
            }
            $s->splice($splice, $string, $secondNext - $string);
        }
    }
}