function parseFile($filename) { $this->log('Starting to parse file: '.$filename); $this->debug('Starting to parse file: '.$filename); $this->resetTimer(); $result = null; try { $file = new DocBlox_Reflection_File($filename, $this->doValidation()); $file->setMarkers($this->getMarkers()); if (($this->existing_xml !== null) && (!$this->isForced())) { $xpath = new DOMXPath($this->existing_xml); /** @var DOMNodeList $qry */ $qry = $xpath->query('/project/file[@path=\''.ltrim($file->getName() , './').'\' and @hash=\''.$file->getHash().'\']'); if ($qry->length > 0) { $new_dom = new DOMDocument('1.0', 'utf-8'); $new_dom->appendChild($new_dom->importNode($qry->item(0), true)); $result = $new_dom->saveXML(); $this->log('>> File has not changed since last build, reusing the old definition'); } } if ($result === null) { $file->process(); $result = $file->__toXml(); } } catch(Exception $e) { $this->log('>> Unable to parse file, an error was detected: '.$e->getMessage(), Zend_Log::ALERT); $this->debug('Unable to parse file "'.$filename.'", an error was detected: '.$e->getMessage()); $result = false; } $this->debug('>> Memory after processing of file: '.number_format(memory_get_usage()).' bytes'); $this->debugTimer('>> Parsed file'); return $result; }
/** * Executes the transformation process. * * @throws Zend_Console_Getopt_Exception * * @return void */ public function execute() { $results = array(); $longest_name = 0; /** @var RecursiveDirectoryIterator $files */ $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/../')); while ($files->valid()) { // skip abstract files if (!$files->isFile() || $files->getBasename() == 'Abstract.php') { $files->next(); continue; } // convert the filename to a class $class_name = 'DocBlox_Task_' . str_replace(DIRECTORY_SEPARATOR, '_', $files->getSubPath()) . '_' . $files->getBasename('.php'); // check if the class exists, if so: add it to the list if (class_exists($class_name)) { $name = $files->getBasename('.php'); $longest_name = max(strlen($name), $longest_name); $results[strtolower($files->getSubPath())][strtolower($name)] = $files->getRealPath(); } $files->next(); } // echo the list of namespaces with their tasks ksort($results, SORT_STRING); foreach ($results as $namespace => $tasks) { echo $namespace . PHP_EOL; asort($tasks, SORT_STRING); foreach ($tasks as $task => $filename) { // get the short description by reflecting the file. $refl = new DocBlox_Reflection_File($filename, false); $refl->setLogLevel(DocBlox_Core_Log::QUIET); $refl->process(); /** @var DocBlox_Reflection_Class $class */ $class = current($refl->getClasses()); echo ' :' . str_pad($task, $longest_name + 2) . $class->getDocBlock()->getShortDescription() . PHP_EOL; } } echo PHP_EOL; }
/** * Tests the DocBlockWithInvalidShortDescription scenario. * * @return void */ public function testConstruct_DocBlockWithInvalidShortDescription() { /** @var DocBlox_Reflection_Class $class */ $class = $this->fixture->getClass('DocBlockTestFixture'); $this->assertInstanceOf('DocBlox_Reflection_Class', $class); /** @var DocBlox_Reflection_Method $method */ $method = $class->getMethod('DocBlockWithInvalidShortDescription'); $this->assertEquals("This docblock is invalid because the short description 'does not end'", $method->getDocBlock()->getShortDescription()); $this->assertEquals('', trim($method->getDocBlock()->getLongDescription()->getContents())); $this->assertInstanceOf('DocBlox_Reflection_DocBlock_Tag_Param', current($method->getDocBlock()->getTagsByName('param'))); $this->assertEquals('$object', current($method->getDocBlock()->getTagsByName('param'))->getVariableName()); $this->assertEquals('ArrayObject', current($method->getDocBlock()->getTagsByName('param'))->getType()); }
public function register($file) { if (!file_exists($file) || !is_readable($file)) { throw new Exception('The plugin file "' . $file . '" must exist and be readable'); } $reflection = new DocBlox_Reflection_File($file); $classes = $reflection->getClasses(); if (count($classes) > 1) { throw new Exception('Plugin file should only contain one class'); } /** @var DocBlox_Reflection_Class $listener_definition */ $listener_definition = reset($classes); // initialize the plugin / event listener include_once $file; $listener_name = $listener_definition->getName(); $listener = new $listener_name($this->event_dispatcher); // connect all events of the each method to the event_dispatcher foreach ($listener_definition->getMethods() as $method) { /** @var DocBlox_Reflection_Tag $event */ foreach ($method->getDocBlock()->getTagsByName('event') as $event) { $this->event_dispatcher->connect($event->getDescription(), array($listener, $method->getName())); } } }
/** * Runs a file through the static reflectors, generates an XML file element * and returns it. * * @param string $filename The filename to parse. * * @api * * @return string|bool The XML element or false if none could be made. */ public function parseFile($filename) { $this->log('Starting to parse file: ' . $filename); $this->debug('Starting to parse file: ' . $filename); $result = null; $dispatched = false; try { $file = new DocBlox_Reflection_File($filename, $this->doValidation()); $file->setDefaultPackageName($this->getDefaultPackageName()); if (self::$event_dispatcher !== null) { self::$event_dispatcher->connect('parser.log', array($file, 'addParserMarker')); } $dispatched = true; $file->setMarkers($this->getMarkers()); $file->setFilename($this->getRelativeFilename($filename)); $file->setName($this->getRelativeFilename($filename)); // if an existing structure exists; and we do not force re-generation; // re-use the old definition if the hash differs if ($this->getExistingXml() !== null && !$this->isForced()) { $xpath = new DOMXPath($this->getExistingXml()); // try to find the file with it's hash /** @var DOMNodeList $qry */ $qry = $xpath->query('/project/file[@path=\'' . ltrim($file->getName(), './') . '\' and @hash=\'' . $file->getHash() . '\']'); // if an existing entry who matches the file, then re-use if ($qry->length > 0) { $new_dom = new DOMDocument('1.0', 'utf-8'); $new_dom->appendChild($new_dom->importNode($qry->item(0), true)); $result = $new_dom->saveXML(); $this->log('>> File has not changed since last build, re-using the ' . 'old definition'); } } // if no result has been obtained; process the file if ($result === null) { $file->process(); $result = $file->__toXml(); } } catch (Exception $e) { $this->log('>> Unable to parse file, an error was detected: ' . $e->getMessage(), Zend_Log::ALERT); $this->debug('Unable to parse file "' . $filename . '", an error was detected: ' . $e->getMessage()); $result = false; } //disconnects the dispatcher here so if any error occured, it still removes the event if ($dispatched && self::$event_dispatcher !== null) { self::$event_dispatcher->disconnect('parser.log', array($file, 'addParserMarker')); } $this->debug('>> Memory after processing of file: ' . number_format(memory_get_usage()) . ' bytes'); $this->debug('>> Parsed file'); return $result; }
/** * Runs a file through the static reflectors, generates an XML file element * and returns it. * * @param string $filename The filename to parse. * * @return string|bool The XML element or false if none could be made. */ function parseFile($filename) { // check whether this file is ignored; we do this in two steps: // 1. Determine whether this is a relative or absolute path, if the // string does not start with *, ?, / or \ then we assume that it is // a relative path // 2. check whether the given pattern matches with the filename (or // relative filename in case of a relative comparison) foreach ($this->getIgnorePatterns() as $pattern) { if ($pattern[0] !== '*' && $pattern[0] !== '?' && $pattern[0] !== '/' && $pattern[0] !== '\\' && preg_match('/^' . $pattern . '$/', $this->getRelativeFilename($filename)) || preg_match('/^' . $pattern . '$/', $filename)) { $this->log('-- File "' . $filename . '" matches ignore pattern, skipping'); return false; } } $this->log('Starting to parse file: ' . $filename); $this->debug('Starting to parse file: ' . $filename); $this->resetTimer(); $result = null; try { $file = new DocBlox_Reflection_File($filename, $this->doValidation()); $file->setMarkers($this->getMarkers()); $file->setFilename($this->getRelativeFilename($filename)); $file->setName($this->getRelativeFilename($filename)); // if an existing structure exists; and we do not force re-generation; // re-use the old definition if the hash differs if ($this->getExistingXml() !== null && !$this->isForced()) { $xpath = new DOMXPath($this->getExistingXml()); // try to find the file with it's hash /** @var DOMNodeList $qry */ $qry = $xpath->query('/project/file[@path=\'' . ltrim($file->getName(), './') . '\' and @hash=\'' . $file->getHash() . '\']'); // if an existing entry who matches the file, then re-use if ($qry->length > 0) { $new_dom = new DOMDocument('1.0', 'utf-8'); $new_dom->appendChild($new_dom->importNode($qry->item(0), true)); $result = $new_dom->saveXML(); $this->log('>> File has not changed since last build, re-using the ' . 'old definition'); } } // if no result has been obtained; process the file if ($result === null) { $file->process(); $result = $file->__toXml(); } } catch (Exception $e) { $this->log('>> Unable to parse file, an error was detected: ' . $e->getMessage(), Zend_Log::ALERT); $this->debug('Unable to parse file "' . $filename . '", an error was detected: ' . $e->getMessage()); $result = false; } $this->debug('>> Memory after processing of file: ' . number_format(memory_get_usage()) . ' bytes'); $this->debugTimer('>> Parsed file'); return $result; }