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; }
/** * 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; }