public function resolve($arg) { if (is_dir($arg)) { echo "FOLDER\n"; $classes = array(); foreach (new \RecursiveIteratorIterator(new RecursiveDirectoryIterator($arg)) as $file) { /* @var $file \SplFileInfo */ if (!$file->isFile()) { continue; } if (strpos($file->getRealPath(), '.svn')) { continue; } $tok = new Cogen\Tokenize($file->getRealPath()); $className = $tok->getSingleNamespacedClass(); if (!$className) { continue; } $classes[] = $className; } var_dump($classes); die("Stopped at " . __FILE__ . ':' . __LINE__); } elseif (is_file($arg)) { $tok = new Cogen\Tokenize($arg); $ns = $tok->getNamespace(); $namespaceName = $this->getRootNamespace($this->moduleMainFolder, $ns) . '\\Tests'; $className = $tok->getSingleNamespacedClass(); $destinationFile = str_replace($this->moduleMainFolder, $this->testsFolder, realpath($arg)); $destinationFile = str_replace('.php', 'Test.php', $destinationFile); $destFolder = dirname($destinationFile); if (!file_exists($destFolder)) { mkdir($destFolder, 0755, true); echo "Making folder {$destFolder}\n"; } $contents = "<?php \n" . $this->forClass($className)->setNamespaceName($namespaceName); if (is_file($destinationFile)) { echo "File {$destinationFile} exists\n"; return; } //$destinationFile = "php://stdout"; $bytes = file_put_contents($destinationFile, $contents); echo "Writing {$bytes} bytes to " . str_replace($this->moduleMainFolder . '/', '', $destinationFile) . "\n"; } else { echo $this->forClass($arg); } }
/** * @param type $path * @return DependencyIndex */ public function buildIdex($path) { $debug = false; $index = new DependencyIndex(); $tokenizers = Helper::getMethodsStartingWith(new \ReflectionClass(__CLASS__), 'tokenize'); foreach ($this->getDirectoryFiles($path) as $relpath => $filename) { $tokenize = new Tokenize($filename); #echo $tokenize->dumpAllTokens(array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT)); /** * Get namespace for a file, as if it was PSR0 */ $namespace = $tokenize->getNamespace(); /** * Get all classes and prepend a namespace */ foreach ($tokenize->getAllClasses() as $className) { $index->addClass($relpath, $namespace, $className); } /** * Classes and interfaces fit the same array */ foreach ($tokenize->getAllInterfaces() as $interfaceName) { $index->addClass($relpath, $namespace, $interfaceName); } /** * This option could be configurable, as we may want to process * files like bootstraps or smth. But later. */ if (!$index->hasClasses($relpath)) { continue; } if ($debug) { echo "Processing {$relpath}", PHP_EOL; } if ($debug) { echo "Classes found: ", join(', ', $index->getClasses($relpath)), PHP_EOL; } $uses = $tokenize->getUses(); foreach ($uses as $alias => $className) { $index->addAliasedDependency($relpath, $alias, $className); } foreach (Helper::reduceMethodGroupResultToArray($tokenizers, $this, $tokenize) as $alias) { //echo "ALIAS: $relpath: $alias\n"; $index->addNamespacedDependency($relpath, $namespace, $alias); } if ($index->hasDependencies($relpath)) { if ($debug) { echo "Dependencies found: ", join(', ', $index->getDependencies($relpath)), PHP_EOL; } } } return $index; }