/** * Returns the migration namespace and class name. * @param string $fileContents Specifies the file contents. * @return array|null Returns an array with keys 'class', 'namespace'. * Returns null if the parsing fails. */ public function extractMigrationInfoFromSource($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) { $className = $this->extractClassName($stream); if ($className === null) { return null; } $result['class'] = $className; } } if (!$result) { return null; } return $result; }
/** * Extracts names and types of model relations. * @param string $fileContents Specifies the file contents. * @return array|null Returns an array with keys matching the relation types and values containing relation names as array. * Returns null if the parsing fails. */ public function extractModelRelationsFromSource($fileContents) { $result = []; $stream = new PhpSourceStream($fileContents); while ($stream->forward()) { $tokenCode = $stream->getCurrentCode(); if ($tokenCode == T_PUBLIC) { $relations = $this->extractRelations($stream); if ($relations === false) { continue; } } } if (!$result) { return null; } return $result; }