|
@@ -13,8 +13,10 @@
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
|
-class CommandLine {
|
|
|
|
- public static function getOptions() {
|
|
|
|
|
|
+class CommandLine
|
|
|
|
+{
|
|
|
|
+ public static function getOptions()
|
|
|
|
+ {
|
|
$parameters = array(
|
|
$parameters = array(
|
|
's:' => 'source:',
|
|
's:' => 'source:',
|
|
'o:' => 'output:',
|
|
'o:' => 'output:',
|
|
@@ -23,6 +25,7 @@ class CommandLine {
|
|
);
|
|
);
|
|
|
|
|
|
$getops = getopt(implode(array_keys($parameters)), $parameters);
|
|
$getops = getopt(implode(array_keys($parameters)), $parameters);
|
|
|
|
+
|
|
$options = array(
|
|
$options = array(
|
|
'source' => __DIR__ . "/../lib/",
|
|
'source' => __DIR__ . "/../lib/",
|
|
'output' => PredisFile::NS_ROOT . '.php',
|
|
'output' => PredisFile::NS_ROOT . '.php',
|
|
@@ -35,14 +38,17 @@ class CommandLine {
|
|
case 'source':
|
|
case 'source':
|
|
$options['source'] = $value;
|
|
$options['source'] = $value;
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case 'o':
|
|
case 'o':
|
|
case 'output':
|
|
case 'output':
|
|
$options['output'] = $value;
|
|
$options['output'] = $value;
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case 'E':
|
|
case 'E':
|
|
case 'exclude-classes':
|
|
case 'exclude-classes':
|
|
$options['exclude'] = @file($value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: $value;
|
|
$options['exclude'] = @file($value, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: $value;
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case 'e':
|
|
case 'e':
|
|
case 'exclude':
|
|
case 'exclude':
|
|
$options['exclude'] = is_array($value) ? $value : array($value);
|
|
$options['exclude'] = is_array($value) ? $value : array($value);
|
|
@@ -54,120 +60,151 @@ class CommandLine {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class PredisFile {
|
|
|
|
|
|
+class PredisFile
|
|
|
|
+{
|
|
const NS_ROOT = 'Predis';
|
|
const NS_ROOT = 'Predis';
|
|
|
|
+
|
|
private $_namespaces;
|
|
private $_namespaces;
|
|
|
|
|
|
- public function __construct() {
|
|
|
|
|
|
+ public function __construct()
|
|
|
|
+ {
|
|
$this->_namespaces = array();
|
|
$this->_namespaces = array();
|
|
}
|
|
}
|
|
|
|
|
|
- public static function from($libraryPath, Array $exclude = array()) {
|
|
|
|
|
|
+ public static function from($libraryPath, Array $exclude = array())
|
|
|
|
+ {
|
|
$nsroot = self::NS_ROOT;
|
|
$nsroot = self::NS_ROOT;
|
|
$predisFile = new PredisFile();
|
|
$predisFile = new PredisFile();
|
|
$libIterator = new RecursiveDirectoryIterator("$libraryPath$nsroot");
|
|
$libIterator = new RecursiveDirectoryIterator("$libraryPath$nsroot");
|
|
|
|
|
|
- foreach (new RecursiveIteratorIterator($libIterator) as $classFile) {
|
|
|
|
|
|
+ foreach (new RecursiveIteratorIterator($libIterator) as $classFile)
|
|
|
|
+ {
|
|
if (!$classFile->isFile()) {
|
|
if (!$classFile->isFile()) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
$namespace = strtr(str_replace($libraryPath, '', $classFile->getPath()), '/', '\\');
|
|
$namespace = strtr(str_replace($libraryPath, '', $classFile->getPath()), '/', '\\');
|
|
|
|
+
|
|
if (in_array(sprintf('%s\\%s', $namespace, $classFile->getBasename('.php')), $exclude)) {
|
|
if (in_array(sprintf('%s\\%s', $namespace, $classFile->getBasename('.php')), $exclude)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
$phpNamespace = $predisFile->getNamespace($namespace);
|
|
$phpNamespace = $predisFile->getNamespace($namespace);
|
|
|
|
+
|
|
if ($phpNamespace === false) {
|
|
if ($phpNamespace === false) {
|
|
$phpNamespace = new PhpNamespace($namespace);
|
|
$phpNamespace = new PhpNamespace($namespace);
|
|
$predisFile->addNamespace($phpNamespace);
|
|
$predisFile->addNamespace($phpNamespace);
|
|
}
|
|
}
|
|
|
|
+
|
|
$phpClass = new PhpClass($phpNamespace, $classFile);
|
|
$phpClass = new PhpClass($phpNamespace, $classFile);
|
|
}
|
|
}
|
|
|
|
+
|
|
return $predisFile;
|
|
return $predisFile;
|
|
}
|
|
}
|
|
|
|
|
|
- public function addNamespace(PhpNamespace $namespace) {
|
|
|
|
|
|
+ public function addNamespace(PhpNamespace $namespace)
|
|
|
|
+ {
|
|
if (isset($this->_namespaces[(string)$namespace])) {
|
|
if (isset($this->_namespaces[(string)$namespace])) {
|
|
throw new InvalidArgumentException("Duplicated namespace");
|
|
throw new InvalidArgumentException("Duplicated namespace");
|
|
}
|
|
}
|
|
$this->_namespaces[(string)$namespace] = $namespace;
|
|
$this->_namespaces[(string)$namespace] = $namespace;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getNamespaces() {
|
|
|
|
|
|
+ public function getNamespaces()
|
|
|
|
+ {
|
|
return $this->_namespaces;
|
|
return $this->_namespaces;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getNamespace($namespace) {
|
|
|
|
|
|
+ public function getNamespace($namespace)
|
|
|
|
+ {
|
|
if (!isset($this->_namespaces[$namespace])) {
|
|
if (!isset($this->_namespaces[$namespace])) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
return $this->_namespaces[$namespace];
|
|
return $this->_namespaces[$namespace];
|
|
}
|
|
}
|
|
|
|
|
|
- public function getClassByFQN($classFqn) {
|
|
|
|
|
|
+ public function getClassByFQN($classFqn)
|
|
|
|
+ {
|
|
if (($nsLastPos = strrpos($classFqn, '\\')) !== false) {
|
|
if (($nsLastPos = strrpos($classFqn, '\\')) !== false) {
|
|
$namespace = $this->getNamespace(substr($classFqn, 0, $nsLastPos));
|
|
$namespace = $this->getNamespace(substr($classFqn, 0, $nsLastPos));
|
|
if ($namespace === false) {
|
|
if ($namespace === false) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
$className = substr($classFqn, $nsLastPos + 1);
|
|
$className = substr($classFqn, $nsLastPos + 1);
|
|
|
|
+
|
|
return $namespace->getClass($className);
|
|
return $namespace->getClass($className);
|
|
}
|
|
}
|
|
|
|
+
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- private function calculateDependencyScores(&$classes, $fqn) {
|
|
|
|
|
|
+ private function calculateDependencyScores(&$classes, $fqn)
|
|
|
|
+ {
|
|
if (!isset($classes[$fqn])) {
|
|
if (!isset($classes[$fqn])) {
|
|
$classes[$fqn] = 0;
|
|
$classes[$fqn] = 0;
|
|
}
|
|
}
|
|
|
|
+
|
|
$classes[$fqn] += 1;
|
|
$classes[$fqn] += 1;
|
|
|
|
+
|
|
if (($phpClass = $this->getClassByFQN($fqn)) === null) {
|
|
if (($phpClass = $this->getClassByFQN($fqn)) === null) {
|
|
- throw new RuntimeException("Cannot found the class $fqn which is required by other subclasses. Are you missing a file?");
|
|
|
|
|
|
+ throw new RuntimeException(
|
|
|
|
+ "Cannot found the class $fqn which is required by other subclasses. Are you missing a file?"
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
+
|
|
foreach ($phpClass->getDependencies() as $fqn) {
|
|
foreach ($phpClass->getDependencies() as $fqn) {
|
|
$this->calculateDependencyScores($classes, $fqn);
|
|
$this->calculateDependencyScores($classes, $fqn);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private function getDependencyScores() {
|
|
|
|
|
|
+ private function getDependencyScores()
|
|
|
|
+ {
|
|
$classes = array();
|
|
$classes = array();
|
|
|
|
+
|
|
foreach ($this->getNamespaces() as $phpNamespace) {
|
|
foreach ($this->getNamespaces() as $phpNamespace) {
|
|
foreach ($phpNamespace->getClasses() as $phpClass) {
|
|
foreach ($phpNamespace->getClasses() as $phpClass) {
|
|
$this->calculateDependencyScores($classes, $phpClass->getFQN());
|
|
$this->calculateDependencyScores($classes, $phpClass->getFQN());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
return $classes;
|
|
return $classes;
|
|
}
|
|
}
|
|
|
|
|
|
- private function getOrderedNamespaces($dependencyScores) {
|
|
|
|
|
|
+ private function getOrderedNamespaces($dependencyScores)
|
|
|
|
+ {
|
|
$namespaces = array_fill_keys(array_unique(
|
|
$namespaces = array_fill_keys(array_unique(
|
|
array_map(
|
|
array_map(
|
|
function($fqn) { return PhpNamespace::extractName($fqn); },
|
|
function($fqn) { return PhpNamespace::extractName($fqn); },
|
|
array_keys($dependencyScores)
|
|
array_keys($dependencyScores)
|
|
)
|
|
)
|
|
), 0);
|
|
), 0);
|
|
|
|
+
|
|
foreach ($dependencyScores as $classFqn => $score) {
|
|
foreach ($dependencyScores as $classFqn => $score) {
|
|
$namespaces[PhpNamespace::extractName($classFqn)] += $score;
|
|
$namespaces[PhpNamespace::extractName($classFqn)] += $score;
|
|
}
|
|
}
|
|
|
|
+
|
|
arsort($namespaces);
|
|
arsort($namespaces);
|
|
|
|
+
|
|
return array_keys($namespaces);
|
|
return array_keys($namespaces);
|
|
}
|
|
}
|
|
|
|
|
|
- private function getOrderedClasses(PhpNamespace $phpNamespace, $classes) {
|
|
|
|
- $nsClassesFQNs = array_map(
|
|
|
|
- function($cl) { return $cl->getFQN(); },
|
|
|
|
- $phpNamespace->getClasses()
|
|
|
|
- );
|
|
|
|
|
|
+ private function getOrderedClasses(PhpNamespace $phpNamespace, $classes)
|
|
|
|
+ {
|
|
|
|
+ $nsClassesFQNs = array_map(function($cl) { return $cl->getFQN(); }, $phpNamespace->getClasses());
|
|
$nsOrderedClasses = array();
|
|
$nsOrderedClasses = array();
|
|
|
|
+
|
|
foreach ($nsClassesFQNs as $nsClassFQN) {
|
|
foreach ($nsClassesFQNs as $nsClassFQN) {
|
|
$nsOrderedClasses[$nsClassFQN] = $classes[$nsClassFQN];
|
|
$nsOrderedClasses[$nsClassFQN] = $classes[$nsClassFQN];
|
|
}
|
|
}
|
|
|
|
+
|
|
arsort($nsOrderedClasses);
|
|
arsort($nsOrderedClasses);
|
|
|
|
+
|
|
return array_keys($nsOrderedClasses);
|
|
return array_keys($nsOrderedClasses);
|
|
}
|
|
}
|
|
|
|
|
|
- public function getPhpCode() {
|
|
|
|
|
|
+ public function getPhpCode()
|
|
|
|
+ {
|
|
$buffer = array("<?php\n\n");
|
|
$buffer = array("<?php\n\n");
|
|
$classes = $this->getDependencyScores();
|
|
$classes = $this->getDependencyScores();
|
|
$namespaces = $this->getOrderedNamespaces($classes);
|
|
$namespaces = $this->getOrderedNamespaces($classes);
|
|
@@ -196,10 +233,12 @@ class PredisFile {
|
|
$buffer[] = "/* " . str_repeat("-", 75) . " */";
|
|
$buffer[] = "/* " . str_repeat("-", 75) . " */";
|
|
$buffer[] = "\n\n";
|
|
$buffer[] = "\n\n";
|
|
}
|
|
}
|
|
|
|
+
|
|
return implode($buffer);
|
|
return implode($buffer);
|
|
}
|
|
}
|
|
|
|
|
|
- public function saveTo($outputFile) {
|
|
|
|
|
|
+ public function saveTo($outputFile)
|
|
|
|
+ {
|
|
// TODO: add more sanity checks
|
|
// TODO: add more sanity checks
|
|
if ($outputFile === null || $outputFile === '') {
|
|
if ($outputFile === null || $outputFile === '') {
|
|
throw new InvalidArgumentException('You must specify a valid output file');
|
|
throw new InvalidArgumentException('You must specify a valid output file');
|
|
@@ -208,127 +247,167 @@ class PredisFile {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class PhpNamespace implements IteratorAggregate {
|
|
|
|
- private $_namespace, $_classes;
|
|
|
|
|
|
+class PhpNamespace implements IteratorAggregate
|
|
|
|
+{
|
|
|
|
+ private $_namespace;
|
|
|
|
+ private $_classes;
|
|
|
|
|
|
- public function __construct($namespace) {
|
|
|
|
|
|
+ public function __construct($namespace)
|
|
|
|
+ {
|
|
$this->_namespace = $namespace;
|
|
$this->_namespace = $namespace;
|
|
$this->_classes = array();
|
|
$this->_classes = array();
|
|
$this->_useDirectives = new PhpUseDirectives($this);
|
|
$this->_useDirectives = new PhpUseDirectives($this);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function extractName($fqn) {
|
|
|
|
|
|
+ public static function extractName($fqn)
|
|
|
|
+ {
|
|
$nsSepLast = strrpos($fqn, '\\');
|
|
$nsSepLast = strrpos($fqn, '\\');
|
|
if ($nsSepLast === false) {
|
|
if ($nsSepLast === false) {
|
|
return $fqn;
|
|
return $fqn;
|
|
}
|
|
}
|
|
$ns = substr($fqn, 0, $nsSepLast);
|
|
$ns = substr($fqn, 0, $nsSepLast);
|
|
|
|
+
|
|
return $ns !== '' ? $ns : null;
|
|
return $ns !== '' ? $ns : null;
|
|
}
|
|
}
|
|
|
|
|
|
- public function addClass(PhpClass $class) {
|
|
|
|
|
|
+ public function addClass(PhpClass $class)
|
|
|
|
+ {
|
|
$this->_classes[$class->getName()] = $class;
|
|
$this->_classes[$class->getName()] = $class;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getClass($className) {
|
|
|
|
|
|
+ public function getClass($className)
|
|
|
|
+ {
|
|
if (isset($this->_classes[$className])) {
|
|
if (isset($this->_classes[$className])) {
|
|
return $this->_classes[$className];
|
|
return $this->_classes[$className];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public function getClasses() {
|
|
|
|
|
|
+ public function getClasses()
|
|
|
|
+ {
|
|
return array_values($this->_classes);
|
|
return array_values($this->_classes);
|
|
}
|
|
}
|
|
|
|
|
|
- public function getIterator() {
|
|
|
|
|
|
+ public function getIterator()
|
|
|
|
+ {
|
|
return new \ArrayIterator($this->getClasses());
|
|
return new \ArrayIterator($this->getClasses());
|
|
}
|
|
}
|
|
|
|
|
|
- public function getUseDirectives() {
|
|
|
|
|
|
+ public function getUseDirectives()
|
|
|
|
+ {
|
|
return $this->_useDirectives;
|
|
return $this->_useDirectives;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getPhpCode() {
|
|
|
|
|
|
+ public function getPhpCode()
|
|
|
|
+ {
|
|
return "namespace $this->_namespace;\n";
|
|
return "namespace $this->_namespace;\n";
|
|
}
|
|
}
|
|
|
|
|
|
- public function __toString() {
|
|
|
|
|
|
+ public function __toString()
|
|
|
|
+ {
|
|
return $this->_namespace;
|
|
return $this->_namespace;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class PhpUseDirectives implements Countable, IteratorAggregate {
|
|
|
|
- private $_use, $_aliases, $_namespace;
|
|
|
|
|
|
+class PhpUseDirectives implements Countable, IteratorAggregate
|
|
|
|
+{
|
|
|
|
+ private $_use;
|
|
|
|
+ private $_aliases;
|
|
|
|
+ private $_namespace;
|
|
|
|
|
|
- public function __construct(PhpNamespace $namespace) {
|
|
|
|
|
|
+ public function __construct(PhpNamespace $namespace)
|
|
|
|
+ {
|
|
$this->_use = array();
|
|
$this->_use = array();
|
|
$this->_aliases = array();
|
|
$this->_aliases = array();
|
|
$this->_namespace = $namespace;
|
|
$this->_namespace = $namespace;
|
|
}
|
|
}
|
|
|
|
|
|
- public function add($use, $as = null) {
|
|
|
|
- if (!in_array($use, $this->_use)) {
|
|
|
|
- $this->_use[] = $use;
|
|
|
|
- $this->_aliases[$as ?: PhpClass::extractName($use)] = $use;
|
|
|
|
|
|
+ public function add($use, $as = null)
|
|
|
|
+ {
|
|
|
|
+ if (in_array($use, $this->_use)) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ $this->_use[] = $use;
|
|
|
|
+ $this->_aliases[$as ?: PhpClass::extractName($use)] = $use;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getList() {
|
|
|
|
|
|
+ public function getList()
|
|
|
|
+ {
|
|
return $this->_use;
|
|
return $this->_use;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getIterator() {
|
|
|
|
|
|
+ public function getIterator()
|
|
|
|
+ {
|
|
return new \ArrayIterator($this->getList());
|
|
return new \ArrayIterator($this->getList());
|
|
}
|
|
}
|
|
|
|
|
|
- public function getPhpCode() {
|
|
|
|
|
|
+ public function getPhpCode()
|
|
|
|
+ {
|
|
$reducer = function($str, $use) { return $str .= "use $use;\n"; };
|
|
$reducer = function($str, $use) { return $str .= "use $use;\n"; };
|
|
|
|
+
|
|
return array_reduce($this->getList(), $reducer, '');
|
|
return array_reduce($this->getList(), $reducer, '');
|
|
}
|
|
}
|
|
|
|
|
|
- public function getNamespace() {
|
|
|
|
|
|
+ public function getNamespace()
|
|
|
|
+ {
|
|
return $this->_namespace;
|
|
return $this->_namespace;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getFQN($className) {
|
|
|
|
|
|
+ public function getFQN($className)
|
|
|
|
+ {
|
|
if (($nsSepFirst = strpos($className, '\\')) === false) {
|
|
if (($nsSepFirst = strpos($className, '\\')) === false) {
|
|
if (isset($this->_aliases[$className])) {
|
|
if (isset($this->_aliases[$className])) {
|
|
return $this->_aliases[$className];
|
|
return $this->_aliases[$className];
|
|
}
|
|
}
|
|
|
|
+
|
|
return (string)$this->getNamespace() . "\\$className";
|
|
return (string)$this->getNamespace() . "\\$className";
|
|
}
|
|
}
|
|
|
|
+
|
|
if ($nsSepFirst != 0) {
|
|
if ($nsSepFirst != 0) {
|
|
throw new InvalidArgumentException("Partially qualified names are not supported");
|
|
throw new InvalidArgumentException("Partially qualified names are not supported");
|
|
}
|
|
}
|
|
|
|
+
|
|
return $className;
|
|
return $className;
|
|
}
|
|
}
|
|
|
|
|
|
- public function count() {
|
|
|
|
|
|
+ public function count()
|
|
|
|
+ {
|
|
return count($this->_use);
|
|
return count($this->_use);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class PhpClass {
|
|
|
|
- private $_namespace, $_file, $_body, $_implements, $_extends, $_name;
|
|
|
|
-
|
|
|
|
- public function __construct(PhpNamespace $namespace, SplFileInfo $classFile) {
|
|
|
|
|
|
+class PhpClass
|
|
|
|
+{
|
|
|
|
+ private $_namespace;
|
|
|
|
+ private $_file;
|
|
|
|
+ private $_body;
|
|
|
|
+ private $_implements;
|
|
|
|
+ private $_extends;
|
|
|
|
+ private $_name;
|
|
|
|
+
|
|
|
|
+ public function __construct(PhpNamespace $namespace, SplFileInfo $classFile)
|
|
|
|
+ {
|
|
$this->_namespace = $namespace;
|
|
$this->_namespace = $namespace;
|
|
$this->_file = $classFile;
|
|
$this->_file = $classFile;
|
|
$this->_implements = array();
|
|
$this->_implements = array();
|
|
$this->_extends = array();
|
|
$this->_extends = array();
|
|
|
|
+
|
|
$this->extractData();
|
|
$this->extractData();
|
|
$namespace->addClass($this);
|
|
$namespace->addClass($this);
|
|
}
|
|
}
|
|
|
|
|
|
- public static function extractName($fqn) {
|
|
|
|
|
|
+ public static function extractName($fqn)
|
|
|
|
+ {
|
|
$nsSepLast = strrpos($fqn, '\\');
|
|
$nsSepLast = strrpos($fqn, '\\');
|
|
if ($nsSepLast === false) {
|
|
if ($nsSepLast === false) {
|
|
return $fqn;
|
|
return $fqn;
|
|
}
|
|
}
|
|
|
|
+
|
|
return substr($fqn, $nsSepLast + 1);
|
|
return substr($fqn, $nsSepLast + 1);
|
|
}
|
|
}
|
|
|
|
|
|
- private function extractData() {
|
|
|
|
|
|
+ private function extractData()
|
|
|
|
+ {
|
|
$useDirectives = $this->getNamespace()->getUseDirectives();
|
|
$useDirectives = $this->getNamespace()->getUseDirectives();
|
|
|
|
|
|
$useExtractor = function($m) use($useDirectives) {
|
|
$useExtractor = function($m) use($useDirectives) {
|
|
@@ -347,15 +426,18 @@ class PhpClass {
|
|
$this->extractHierarchy();
|
|
$this->extractHierarchy();
|
|
}
|
|
}
|
|
|
|
|
|
- private function extractHierarchy() {
|
|
|
|
|
|
+ private function extractHierarchy()
|
|
|
|
+ {
|
|
$implements = array();
|
|
$implements = array();
|
|
$extends = array();
|
|
$extends = array();
|
|
|
|
|
|
$extractor = function($iterator, $callback) {
|
|
$extractor = function($iterator, $callback) {
|
|
$className = '';
|
|
$className = '';
|
|
$iterator->seek($iterator->key() + 1);
|
|
$iterator->seek($iterator->key() + 1);
|
|
|
|
+
|
|
while ($iterator->valid()) {
|
|
while ($iterator->valid()) {
|
|
$token = $iterator->current();
|
|
$token = $iterator->current();
|
|
|
|
+
|
|
if (is_string($token)) {
|
|
if (is_string($token)) {
|
|
if (preg_match('/\s?,\s?/', $token)) {
|
|
if (preg_match('/\s?,\s?/', $token)) {
|
|
$callback(trim($className));
|
|
$callback(trim($className));
|
|
@@ -366,26 +448,30 @@ class PhpClass {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
switch ($token[0]) {
|
|
switch ($token[0]) {
|
|
case T_NS_SEPARATOR:
|
|
case T_NS_SEPARATOR:
|
|
$className .= '\\';
|
|
$className .= '\\';
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case T_STRING:
|
|
case T_STRING:
|
|
$className .= $token[1];
|
|
$className .= $token[1];
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case T_IMPLEMENTS:
|
|
case T_IMPLEMENTS:
|
|
case T_EXTENDS:
|
|
case T_EXTENDS:
|
|
$callback(trim($className));
|
|
$callback(trim($className));
|
|
$iterator->seek($iterator->key() - 1);
|
|
$iterator->seek($iterator->key() - 1);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
$iterator->next();
|
|
$iterator->next();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
$tokens = token_get_all("<?php\n" . trim($this->getPhpCode()));
|
|
$tokens = token_get_all("<?php\n" . trim($this->getPhpCode()));
|
|
-
|
|
|
|
$iterator = new ArrayIterator($tokens);
|
|
$iterator = new ArrayIterator($tokens);
|
|
|
|
+
|
|
while ($iterator->valid()) {
|
|
while ($iterator->valid()) {
|
|
$token = $iterator->current();
|
|
$token = $iterator->current();
|
|
if (is_string($token)) {
|
|
if (is_string($token)) {
|
|
@@ -400,17 +486,20 @@ class PhpClass {
|
|
$tk = $iterator->current();
|
|
$tk = $iterator->current();
|
|
$this->_name = $tk[1];
|
|
$this->_name = $tk[1];
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case T_IMPLEMENTS:
|
|
case T_IMPLEMENTS:
|
|
$extractor($iterator, function($fqn) use (&$implements) {
|
|
$extractor($iterator, function($fqn) use (&$implements) {
|
|
$implements[] = $fqn;
|
|
$implements[] = $fqn;
|
|
});
|
|
});
|
|
break;
|
|
break;
|
|
|
|
+
|
|
case T_EXTENDS:
|
|
case T_EXTENDS:
|
|
$extractor($iterator, function($fqn) use (&$extends) {
|
|
$extractor($iterator, function($fqn) use (&$extends) {
|
|
$extends[] = $fqn;
|
|
$extends[] = $fqn;
|
|
});
|
|
});
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+
|
|
$iterator->next();
|
|
$iterator->next();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -418,63 +507,71 @@ class PhpClass {
|
|
$this->_extends = $this->guessFQN($extends);
|
|
$this->_extends = $this->guessFQN($extends);
|
|
}
|
|
}
|
|
|
|
|
|
- public function guessFQN($classes) {
|
|
|
|
|
|
+ public function guessFQN($classes)
|
|
|
|
+ {
|
|
$useDirectives = $this->getNamespace()->getUseDirectives();
|
|
$useDirectives = $this->getNamespace()->getUseDirectives();
|
|
return array_map(array($useDirectives, 'getFQN'), $classes);
|
|
return array_map(array($useDirectives, 'getFQN'), $classes);
|
|
}
|
|
}
|
|
|
|
|
|
- public function getImplementedInterfaces($all = false) {
|
|
|
|
|
|
+ public function getImplementedInterfaces($all = false)
|
|
|
|
+ {
|
|
if ($all) {
|
|
if ($all) {
|
|
return $this->_implements;
|
|
return $this->_implements;
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- return array_filter(
|
|
|
|
- $this->_implements,
|
|
|
|
- function ($cn) { return strpos($cn, 'Predis\\') === 0; }
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ return array_filter(
|
|
|
|
+ $this->_implements,
|
|
|
|
+ function ($cn) { return strpos($cn, 'Predis\\') === 0; }
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
- public function getExtendedClasses($all = false) {
|
|
|
|
|
|
+ public function getExtendedClasses($all = false)
|
|
|
|
+ {
|
|
if ($all) {
|
|
if ($all) {
|
|
return $this->_extemds;
|
|
return $this->_extemds;
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- return array_filter(
|
|
|
|
- $this->_extends,
|
|
|
|
- function ($cn) { return strpos($cn, 'Predis\\') === 0; }
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ return array_filter(
|
|
|
|
+ $this->_extends,
|
|
|
|
+ function ($cn) { return strpos($cn, 'Predis\\') === 0; }
|
|
|
|
+ );
|
|
}
|
|
}
|
|
|
|
|
|
- public function getDependencies($all = false) {
|
|
|
|
|
|
+ public function getDependencies($all = false)
|
|
|
|
+ {
|
|
return array_merge(
|
|
return array_merge(
|
|
$this->getImplementedInterfaces($all),
|
|
$this->getImplementedInterfaces($all),
|
|
$this->getExtendedClasses($all)
|
|
$this->getExtendedClasses($all)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- public function getNamespace() {
|
|
|
|
|
|
+ public function getNamespace()
|
|
|
|
+ {
|
|
return $this->_namespace;
|
|
return $this->_namespace;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getFile() {
|
|
|
|
|
|
+ public function getFile()
|
|
|
|
+ {
|
|
return $this->_file;
|
|
return $this->_file;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getName() {
|
|
|
|
|
|
+ public function getName()
|
|
|
|
+ {
|
|
return $this->_name;
|
|
return $this->_name;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getFQN() {
|
|
|
|
|
|
+ public function getFQN()
|
|
|
|
+ {
|
|
return (string)$this->getNamespace() . '\\' . $this->_name;
|
|
return (string)$this->getNamespace() . '\\' . $this->_name;
|
|
}
|
|
}
|
|
|
|
|
|
- public function getPhpCode() {
|
|
|
|
|
|
+ public function getPhpCode()
|
|
|
|
+ {
|
|
return $this->_body;
|
|
return $this->_body;
|
|
}
|
|
}
|
|
|
|
|
|
- public function __toString() {
|
|
|
|
|
|
+ public function __toString()
|
|
|
|
+ {
|
|
return "class " . $this->getName() . '{ ... }';
|
|
return "class " . $this->getName() . '{ ... }';
|
|
}
|
|
}
|
|
}
|
|
}
|