src/Proxy/Generator/ProxyCodeGenerator.php
private function getAllUseStatementsMarkedAsAnnotation(\ReflectionClass $class): array
    {
        $tokens = \token_get_all(\file_get_contents($class->getFileName()));

        $uses = [];
        $buffer = '';
        $startUseParse = false;

        foreach ($tokens as $token) {
            if (\is_scalar($token)) {
                // Single element
                if ($token == ';' || $token = ',') {
                    if ($startUseParse) {
                        // Add "use" statement to collection
                        $uses[] = trim($buffer);
                        // Clear buffer
                        $buffer = ''; // Clear buffer

                        if ($token == ';') {
                            // Stop parse "use"
                            $startUseParse = false;
                        }
                    }
                }

                continue;
            }

            $type = $token[0];
            $value = $token[1];

            if (\in_array($type, [T_ABSTRACT, T_CLASS, T_INTERFACE, T_TRAIT])) {
                // Start class or interface or trait
                break;
            }

            if ($type == T_USE) {
                $startUseParse = true;
                continue;
            }

            if ($startUseParse) {
                $buffer .= $value;
            }
        }

        $useFiltering = function ($class, $searchChild = true) use (&$useFiltering) {
            if (!$class) {
                return false;
            }

            $parts = \explode(' as ', $class, 2);
            $class = $parts[0];

            try {
                $reflection = new \ReflectionClass($class);
            } catch (\ReflectionException $e) {
                if ($searchChild) {
                    foreach (\get_declared_classes() as $declaredClass) {
                        if (\strpos($declaredClass, $class) === 0) {
                            if (true === $useFiltering($declaredClass, false)) {
                                return true;
                            }
                        }
                    }
                }

                return false;
            }

            if ($reflection->getName() == Transactional::class) {
                return false;
            }

            return \strpos($reflection->getDocComment(), '@Annotation') !== false;
        };

        $uses = \array_filter($uses, $useFiltering);

        return $uses;
    }
private function getAllUseStatementsMarkedAsAnnotation(\ReflectionClass $class): array
    {
        $tokens = \token_get_all(\file_get_contents($class->getFileName()));

        $uses = [];
        $buffer = '';
        $startUseParse = false;

        foreach ($tokens as $token) {
            if (\is_scalar($token)) {
                // Single element
                if ($token == ';' || $token = ',') {
                    if ($startUseParse) {
                        // Add "use" statement to collection
                        $uses[] = trim($buffer);
                        // Clear buffer
                        $buffer = ''; // Clear buffer

                        if ($token == ';') {
                            // Stop parse "use"
                            $startUseParse = false;
                        }
                    }
                }

                continue;
            }

            $type = $token[0];
            $value = $token[1];

            if (\in_array($type, [T_ABSTRACT, T_CLASS, T_INTERFACE, T_TRAIT])) {
                // Start class or interface or trait
                break;
            }

            if ($type == T_USE) {
                $startUseParse = true;
                continue;
            }

            if ($startUseParse) {
                $buffer .= $value;
            }
        }

        $useFiltering = function ($class, $searchChild = true) use (&$useFiltering) {
            if (!$class) {
                return false;
            }

            $parts = \explode(' as ', $class, 2);
            $class = $parts[0];

            try {
                $reflection = new \ReflectionClass($class);
            } catch (\ReflectionException $e) {
                if ($searchChild) {
                    foreach (\get_declared_classes() as $declaredClass) {
                        if (\strpos($declaredClass, $class) === 0) {
                            if (true === $useFiltering($declaredClass, false)) {
                                return true;
                            }
                        }
                    }
                }

                return false;
            }

            if ($reflection->getName() == Transactional::class) {
                return false;
            }

            return \strpos($reflection->getDocComment(), '@Annotation') !== false;
        };

        $uses = \array_filter($uses, $useFiltering);

        return $uses;
    }
private function getAllUseStatementsMarkedAsAnnotation ( \ ReflectionClass $ class ) : array { $ tokens = \ token_get_all ( \ file_get_contents ( $ class -> getFileName ( ) ) ) ; $ uses = [ ] ; $ buffer = '' ; $ startUseParse = false ; foreach ( $ tokens as $ token ) { if ( \ is_scalar ( $ token ) ) { // Single element if ( $ token == ';' || $ token = ',' ) { if ( $ startUseParse ) { // Add "use" statement to collection $ uses [ ] = trim ( $ buffer ) ; // Clear buffer $ buffer = '' ; // Clear buffer if ( $ token == ';' ) { // Stop parse "use" $ startUseParse = false ; } } } continue ; } $ type = $ token [ 0 ] ; $ value = $ token [ 1 ] ; if ( \ in_array ( $ type , [ T_ABSTRACT , T_CLASS , T_INTERFACE , T_TRAIT ] ) ) { // Start class or interface or trait break ; } if ( $ type == T_USE ) { $ startUseParse = true ; continue ; } if ( $ startUseParse ) { $ buffer .= $ value ; } } $ useFiltering = function ( $ class , $ searchChild = true ) use ( & $ useFiltering ) { if ( ! $ class ) { return false ; } $ parts = \ explode ( ' as ' , $ class , 2 ) ; $ class = $ parts [ 0 ] ; try { $ reflection = new \ ReflectionClass ( $ class ) ; } catch ( \ ReflectionException $ e ) { if ( $ searchChild ) { foreach ( \ get_declared_classes ( ) as $ declaredClass ) { if ( \ strpos ( $ declaredClass , $ class ) === 0 ) { if ( true === $ useFiltering ( $ declaredClass , false ) ) { return true ; } } } } return false ; } if ( $ reflection -> getName ( ) == Transactional :: class ) { return false ; } return \ strpos ( $ reflection -> getDocComment ( ) , '@Annotation' ) !== false ; } ; $ uses = \ array_filter ( $ uses , $ useFiltering ) ; return $ uses ; }
Get all use statements from class

@param \ReflectionClass $class

@return array
Get all use statements from class