Exakat\Tasks\Load::processUse PHP Method

processUse() private method

private processUse ( )
    private function processUse()
    {
        $useId = $this->addAtom('Use');
        $current = $this->id;
        $useType = 'class';
        $fullcode = array();
        // use const
        if ($this->tokens[$this->id + 1][0] === T_CONST) {
            ++$this->id;
            $this->processSingle('Identifier');
            $constId = $this->popExpression();
            $this->addLink($useId, $constId, 'CONST');
            $useType = 'const';
        }
        // use function
        if ($this->tokens[$this->id + 1][0] === T_FUNCTION) {
            ++$this->id;
            $this->processSingle('Identifier');
            $constId = $this->popExpression();
            $this->addLink($useId, $constId, 'FUNCTION');
            $useType = 'function';
        }
        --$this->id;
        do {
            ++$this->id;
            $namespaceId = $this->processOneNsname();
            // Default case : use A\B
            $aliasId = $namespaceId;
            $originId = $namespaceId;
            $fullnspath = $this->makeFullnspath($namespaceId);
            if ($this->tokens[$this->id + 1][0] === T_AS) {
                // use A\B as C
                ++$this->id;
                $this->setAtom($originId, array('fullnspath' => $this->makeFullnspath($originId)));
                $this->pushExpression($namespaceId);
                $this->processAs();
                $namespaceId = $this->popExpression();
                $aliasId = $namespaceId;
                $this->addLink($useId, $namespaceId, 'USE');
                if ($this->isContext(self::CONTEXT_CLASS) || $this->isContext(self::CONTEXT_TRAIT)) {
                    $this->addCall('class', $fullnspath, $namespaceId);
                }
                $fullcode[] = $this->atoms[$namespaceId]['fullcode'];
                $this->setAtom($namespaceId, array('fullnspath' => $fullnspath));
                if (!$this->isContext(self::CONTEXT_CLASS) && !$this->isContext(self::CONTEXT_TRAIT)) {
                    $alias = $this->addNamespaceUse($originId, $aliasId, $useType);
                    $this->setAtom($namespaceId, array('alias' => $alias, 'origin' => $fullnspath));
                }
            } elseif ($this->tokens[$this->id + 1][0] === T_OPEN_CURLY) {
                //use A\B{} // Group
                $blockId = $this->processFollowingBlock(array(T_CLOSE_CURLY));
                $this->popExpression();
                $this->addLink($useId, $blockId, 'BLOCK');
                $fullcode[] = $this->atoms[$namespaceId]['fullcode'] . ' ' . $this->atoms[$blockId]['fullcode'];
                // Several namespaces ? This has to be recalculated inside the block!!
                $fullnspath = $this->makeFullnspath($namespaceId);
                $this->addLink($useId, $namespaceId, 'USE');
            } elseif ($this->tokens[$this->id + 1][0] === T_NS_SEPARATOR) {
                //use A\B\ {} // Prefixes, within a Class/Trait
                $this->addLink($useId, $namespaceId, 'GROUPUSE');
                $prefix = $this->makeFullnspath($namespaceId);
                if ($prefix[0] !== '\\') {
                    $prefix = '\\' . $prefix;
                }
                $prefix .= '\\';
                ++$this->id;
                // Skip \
                $useTypeGeneric = $useType;
                $useTypeId = 0;
                do {
                    ++$this->id;
                    // Skip {
                    $useType = $useTypeGeneric;
                    $useTypeId = 0;
                    if ($this->tokens[$this->id + 1][0] === T_CONST) {
                        // use const
                        ++$this->id;
                        $this->processSingle('Identifier');
                        $useTypeId = $this->popExpression();
                        $useType = 'const';
                    }
                    if ($this->tokens[$this->id + 1][0] === T_FUNCTION) {
                        // use function
                        ++$this->id;
                        $this->processSingle('Identifier');
                        $useTypeId = $this->popExpression();
                        $useType = 'function';
                    }
                    $id = $this->processOneNsname();
                    if ($useTypeId !== 0) {
                        $this->addLink($id, $useTypeId, strtoupper($useType));
                    }
                    if ($this->tokens[$this->id + 1][0] === T_AS) {
                        // A\B as C
                        ++$this->id;
                        $this->pushExpression($id);
                        $this->processAs();
                        $aliasId = $this->popExpression();
                        $this->setAtom($id, array('fullnspath' => $prefix . strtolower($this->atoms[$id]['fullcode']), 'origin' => $prefix . strtolower($this->atoms[$id]['fullcode'])));
                        $this->setAtom($aliasId, array('fullnspath' => $prefix . strtolower($this->atoms[$id]['fullcode']), 'origin' => $prefix . strtolower($this->atoms[$id]['fullcode'])));
                        $alias = $this->addNamespaceUse($id, $aliasId, $useType);
                        $this->setAtom($aliasId, array('alias' => $alias));
                        $this->addLink($useId, $aliasId, 'USE');
                    } else {
                        $this->addLink($useId, $id, 'USE');
                        $this->setAtom($id, array('fullnspath' => $prefix . strtolower($this->atoms[$id]['fullcode']), 'origin' => $prefix . strtolower($this->atoms[$id]['fullcode'])));
                        $alias = $this->addNamespaceUse($id, $id, $useType);
                        $this->setAtom($id, array('alias' => $alias));
                    }
                } while (in_array($this->tokens[$this->id + 1][0], array(T_COMMA)));
                $fullcode[] = $this->atoms[$namespaceId]['fullcode'] . self::FULLCODE_BLOCK;
                ++$this->id;
                // Skip }
            } else {
                $this->addLink($useId, $namespaceId, 'USE');
                if ($this->isContext(self::CONTEXT_CLASS) || $this->isContext(self::CONTEXT_TRAIT)) {
                    $fullnspath = $this->getFullnspath($namespaceId);
                    $this->setAtom($namespaceId, array('fullnspath' => $fullnspath));
                    $this->addCall('class', $fullnspath, $namespaceId);
                }
                $fullcode[] = $this->atoms[$namespaceId]['fullcode'];
                $this->setAtom($namespaceId, array('fullnspath' => $fullnspath));
                if (!$this->isContext(self::CONTEXT_CLASS) && !$this->isContext(self::CONTEXT_TRAIT)) {
                    $alias = $this->addNamespaceUse($aliasId, $aliasId, $useType);
                    $this->setAtom($namespaceId, array('alias' => $alias, 'origin' => $fullnspath));
                }
            }
            // No Else. Default will be dealt with by while() condition
        } while ($this->tokens[$this->id + 1][0] === T_COMMA);
        $x = array('code' => $this->tokens[$current][1], 'fullcode' => $this->tokens[$current][1] . (isset($constId) ? ' ' . $this->atoms[$constId]['code'] : '') . ' ' . implode(", ", $fullcode), 'line' => $this->tokens[$current][2], 'token' => $this->getToken($this->tokens[$current][0]));
        $this->setAtom($useId, $x);
        $this->pushExpression($useId);
        if ($this->tokens[$this->id + 1][0] !== T_SEMICOLON) {
            $this->processSemicolon();
        }
        return $useId;
    }
Load