示例#1
0
 public function getNamespaces($requestedNamespace, $inputFolder, $exclude)
 {
     $broker = new Broker($backend = new Broker\Backend\Memory());
     $broker->processDirectory($inputFolder);
     $namespaces = $backend->getNamespaces();
     ksort($namespaces);
     $excludedNamespaces = $this->getExcludedNamespaces($exclude);
     $filteredNamespaces = $this->getFilteredNamespaces($requestedNamespace, $namespaces, $excludedNamespaces);
     return $filteredNamespaces;
 }
示例#2
0
文件: Generator.php 项目: dotink/sage
 /**
  * Runs the documentation generator
  *
  * @access public
  * @param string $input_path A relative or absolute directory to scan
  * @return void
  */
 public function run($input_path)
 {
     $this->setInputPath($input_path);
     for ($config_path = realpath($this->inputPath); $config_path != realpath($config_path . DIRECTORY_SEPARATOR . '..') && !is_readable($config_path . DIRECTORY_SEPARATOR . 'sage.config'); $config_path = realpath($config_path . DIRECTORY_SEPARATOR . '..')) {
     }
     $this->options = file_exists($config_path . DIRECTORY_SEPARATOR . 'sage.config') ? include $config_path . DIRECTORY_SEPARATOR . 'sage.config' : array();
     $reflections = $this->broker->processDirectory($this->inputPath, [], TRUE);
     $sort_by_type = !empty($this->options['sort_by_type']);
     $token_parsers = !empty($this->options['token_parsers']) ? $this->options['token_parsers'] : array();
     $this->configTokenParsers($token_parsers);
     $this->makeDocumentCollection($reflections, $sort_by_type);
     foreach ($reflections as $reflection) {
         foreach ($reflection->getNamespaces() as $namespace) {
             //
             // Add our class type structures
             //
             foreach ($namespace->getClasses() as $structure) {
                 $root =& $this->documents;
                 if ($sort_by_type) {
                     if ($structure->isTrait()) {
                         $root =& $this->documents['traits'];
                     } elseif ($structure->isInterface()) {
                         $root =& $this->documents['interfaces'];
                     } else {
                         $root =& $this->documents['classes'];
                     }
                 }
                 foreach (explode('\\', $namespace->getName()) as $segment) {
                     $root =& $root[$segment];
                 }
                 $root[] = new Document($structure, $this, $namespace);
             }
             //
             // Add our function type structures
             //
             foreach ($namespace->getFunctions() as $function) {
                 $root =& $this->documents;
                 if ($sort_by_type) {
                     $root =& $this->documents['functions'];
                 }
                 foreach (explode('\\', $namespace->getName()) as $segment) {
                     $root =& $root[$segment];
                 }
                 $root[] = new Document($function, $this, $namespace);
             }
         }
     }
     return $this->documents;
 }
 /**
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 public function setUp()
 {
     $this->backend = new Memory();
     $this->broker = new Broker($this->backend);
     $this->broker->processDirectory(__DIR__);
 }
示例#4
0
 /**
  * Will run an inspection for a certain file/directory and will return a version instance
  * resulting from the changes compared to former inspections
  *
  * @param string $srcPath Path to the file/directory to inspect
  *
  * @return \Herrera\Version\Builder
  *
  * @throws \Exception
  */
 public function runInspection($srcPath)
 {
     // check if we got something we can work with
     if (!is_readable($srcPath)) {
         throw new \Exception(sprintf('Cannot read from source path %s', $srcPath));
     }
     $broker = new Broker(new Memory());
     if (is_dir($srcPath)) {
         $broker->processDirectory($srcPath);
     } else {
         $broker->processFile($srcPath);
     }
     // iterate all php files and check for an API annotation
     $inspector = $this->getInspector();
     foreach ($broker->getClasses() as $classReflection) {
         // we can continue iteration if we did not get any valuable information from this file
         if (!$classReflection instanceof \TokenReflection\ReflectionClass) {
             continue;
         }
         // if we got the API annotation we have to work with it
         if ($classReflection->hasAnnotation(ApiAnnotation::ANNOTATION)) {
             $formerReflection = $this->cache->load($classReflection->getName());
             // check for possible changes
             $inspector->inspect($classReflection, $formerReflection);
             // save the current reflection object as a base for later comparison
             $this->cache->store($classReflection);
         }
     }
     // get the result and increment the version accordingly
     $result = $inspector->getResult();
     $incrementationMethod = 'increment' . ucfirst(strtolower($result->getIncrementVersion()));
     $version = $this->getBaseVersion();
     if (method_exists($version, $incrementationMethod)) {
         $version->{$incrementationMethod}();
     }
     return $version;
 }
示例#5
0
 /**
  * @see Symfony\Component\Console\Command.Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $namespace = $input->getArgument('namespace');
     $path = $input->getArgument('path');
     $out = realpath($input->getOption('output'));
     $output->writeln(sprintf('<comment>Processing code from namespace %s</comment>', $namespace));
     $output->writeln(sprintf('<comment>Processing files from %s</comment>', $path));
     $output->writeln(sprintf('<comment>Outputting to %s</comment>', $out));
     $output_files = array();
     $filters = array();
     if ($filtersArgument = trim($input->getOption('filters'))) {
         $filters = explode(';', $filtersArgument);
         foreach ($filters as $filter) {
             $output->writeln(sprintf('<comment>Applying filter %s</comment>', $filter));
         }
     }
     $broker = new Broker($backend = new Memory());
     $broker->processDirectory($path, $filters);
     $namespaces = $backend->getNamespaces();
     ksort($namespaces);
     $excludes = array();
     if ($exclude = trim($input->getOption('exclude'))) {
         $excludes = explode(';', $exclude);
         foreach ($excludes as $exclude) {
             $output->writeln(sprintf('<comment>Excluding code from %s</comment>', $exclude));
         }
     }
     $filtered = array();
     foreach ($namespaces as $n => $reflection) {
         if (substr($n, 0, strlen($namespace)) != $namespace) {
             continue;
         }
         foreach ($excludes as $exclude) {
             if (strncmp($n, $exclude, strlen($exclude)) == 0) {
                 continue 2;
             }
         }
         $filtered[$n] = $reflection;
     }
     unset($namespaces);
     $elements = array();
     foreach ($filtered as $n => $reflection) {
         $output->writeln(sprintf('<info>Processing %s</info>', $n));
         $element = new NamespaceElement($reflection);
         $element->buildClasses($out, $output);
         $elements[$n] = $element;
     }
     unset($filtered);
     foreach ($elements as $n => $element) {
         $output->writeln(sprintf('<info>Building index for %s</info>', $n));
         $options = array();
         if ($n == $namespace && $input->getOption('title')) {
             $options = array('title' => $input->getOption('title'));
         }
         $element->buildIndex($out, $output, $options);
     }
 }
 /**
  * Data preparer.
  *
  * Returns pairs of TokenReflection\Broker where one parses a directory of given type
  * and the second one parses a PHAR archive that was created from the same directory.
  *
  * @param integer $format Archive format
  * @param integer $compression Archive compression
  * @param boolean $wholeArchive Use compression for the whole archive
  * @return array
  */
 private function prepareData($format = Phar::PHAR, $compression = Phar::NONE, $wholeArchive = true)
 {
     $dirName = $this->prepareTemporaryStorage();
     $directory = realpath(__DIR__ . '/../data/');
     $iterator = new \DirectoryIterator($directory);
     static $skip = array('broker' => true, 'parseerror' => true, 'duplicities' => true);
     $data = array();
     foreach ($iterator as $item) {
         if (isset($skip[$item->getFileName()])) {
             continue;
         }
         if ($item->isDir() && !$item->isDot()) {
             $ext = '.phar';
             $fileName = $dirName . DIRECTORY_SEPARATOR . uniqid($format . $compression);
             $phar = new Phar($fileName . $ext);
             $phar->buildFromDirectory($item->getPathName());
             if ($format !== Phar::PHAR) {
                 if ($format === Phar::TAR) {
                     $ext .= '.tar';
                 } elseif ($format === Phar::ZIP) {
                     $ext .= '.zip';
                 }
                 $phar->convertToExecutable($format, $wholeArchive ? $compression : Phar::NONE, $ext);
             }
             if ($compression !== Phar::NONE && !$wholeArchive) {
                 $phar->compressFiles($compression);
             }
             unset($phar);
             $dataItem = array(array('format' => $format, 'compression' => $compression, 'wholeArchive' => $wholeArchive));
             $broker = new Broker(new Broker\Backend\Memory(), 0);
             $broker->processDirectory($item->getPathName());
             $dataItem[] = $broker;
             $broker2 = new Broker(new Broker\Backend\Memory(), 0);
             $broker2->process($fileName . $ext);
             $dataItem[] = $broker2;
             $data[] = $dataItem;
         }
     }
     $this->cleanUpTemporaryStorage($dirName);
     return $data;
 }
示例#7
0
 /**
  * Parse and display the Pocco documentation for the given directory and
  * all contained PHP files. You may also specify the default file to show
  * if none has been requested.
  *
  * @param string $directory
  * @param string $file
  * @return boolean
  */
 public function saveHTML($directory, $default = NULL, $requested = NULL)
 {
     $this->broker = $broker = new Broker(new Broker\Backend\Memory());
     //Reflection File
     $rDir = $broker->processDirectory($directory, "*.php", true);
     $files = array_keys($rDir);
     array_walk($files, function (&$value, $key) use($directory) {
         //echo $directory;
         $value = substr($value, strlen($directory));
     });
     //sort files into namespaces
     $this->saveMode = true;
     $this->savePath = dirname($directory) . "/docs";
     foreach ($files as $file) {
         //Wee need this to fix links
         if (!$this->isIndex) {
             $_segments = explode("/", $file);
             $_levels = count($_segments);
             //if not saving index
             for ($_i = 0; $_i < $_levels - 1; $_i++) {
                 $this->saveHierarchy .= "../";
             }
         }
         //$source = file_get_contents($directory . $file);
         $sections = $this->parseSource($rDir[$directory . $file], $file, $directory);
         $this->renderSave($sections, $file, $files, dirname($directory) . "/docs");
         //reset this heierarchy
         $this->saveHierarchy = "";
     }
     //create the index file which should be the first in files;
     $this->isIndex = true;
     $this->renderSave($this->parseSource($rDir[$directory . $files[0]], $files[0], $directory), $file, $files, $this->savePath, "index.html");
     //copy assets into docs directory;
     $this->xcopy(BUDKIT_DOCS_PATH . "/assets", $this->savePath . "/assets", 0777);
     return true;
 }