classes/ModelFileParser.php
public function extractModelInfoFromSource($fileContents)
    {
        $stream = new PhpSourceStream($fileContents);

        $result = [];

        while ($stream->forward()) {
            $tokenCode = $stream->getCurrentCode();

            if ($tokenCode == T_NAMESPACE) {
                $namespace = $this->extractNamespace($stream);
                if ($namespace === null) {
                    return null;
                }

                $result['namespace'] = $namespace;
            }

            if ($tokenCode == T_CLASS && !isset($result['class'])) {
                $className = $this->extractClassName($stream);
                if ($className === null) {
                    return null;
                }

                $result['class'] = $className;
            }

            if ($tokenCode == T_PUBLIC || $tokenCode == T_PROTECTED) {
                $tableName = $this->extractTableName($stream);
                if ($tableName === false) {
                    continue;
                }

                if ($tableName === null) {
                    return null;
                }

                $result['table'] = $tableName;
            }
        }

        if (!$result) {
            return null;
        }

        return $result;
    }
public function extractModelInfoFromSource($fileContents)
    {
        $stream = new PhpSourceStream($fileContents);

        $result = [];

        while ($stream->forward()) {
            $tokenCode = $stream->getCurrentCode();

            if ($tokenCode == T_NAMESPACE) {
                $namespace = $this->extractNamespace($stream);
                if ($namespace === null) {
                    return null;
                }

                $result['namespace'] = $namespace;
            }

            if ($tokenCode == T_CLASS && !isset($result['class'])) {
                $className = $this->extractClassName($stream);
                if ($className === null) {
                    return null;
                }

                $result['class'] = $className;
            }

            if ($tokenCode == T_PUBLIC || $tokenCode == T_PROTECTED) {
                $tableName = $this->extractTableName($stream);
                if ($tableName === false) {
                    continue;
                }

                if ($tableName === null) {
                    return null;
                }

                $result['table'] = $tableName;
            }
        }

        if (!$result) {
            return null;
        }

        return $result;
    }
public function extractModelInfoFromSource ( $ fileContents ) { $ stream = new PhpSourceStream ( $ fileContents ) ; $ result = [ ] ; while ( $ stream -> forward ( ) ) { $ tokenCode = $ stream -> getCurrentCode ( ) ; if ( $ tokenCode == T_NAMESPACE ) { $ namespace = $ this -> extractNamespace ( $ stream ) ; if ( $ namespace === null ) { return null ; } $ result [ 'namespace' ] = $ namespace ; } if ( $ tokenCode == T_CLASS && ! isset ( $ result [ 'class' ] ) ) { $ className = $ this -> extractClassName ( $ stream ) ; if ( $ className === null ) { return null ; } $ result [ 'class' ] = $ className ; } if ( $ tokenCode == T_PUBLIC || $ tokenCode == T_PROTECTED ) { $ tableName = $ this -> extractTableName ( $ stream ) ; if ( $ tableName === false ) { continue ; } if ( $ tableName === null ) { return null ; } $ result [ 'table' ] = $ tableName ; } } if ( ! $ result ) { return null ; } return $ result ; }
Returns the model namespace, class name and table name.
@param string $fileContents Specifies the file contents.
@return array|null Returns an array with keys 'namespace', 'class' and 'table'
Returns null if the parsing fails.
Returns the model namespace class name and table name .