/** * Scan directory looking for files matching patterns. * * @method scan * @param string [$path=null] */ public function scan($path = null) { // If first call (no path provided). if ($path === null) { // Reset files tree. $this->files = []; // Set root path as first path to scan. $path = $this->path; } $includedFiles = []; $excludedFiles = []; $excludedDirectories = []; $files = []; // For each file/directory foreach (scandir($path, SCANDIR_SORT_NONE) as $file) { // Skip curent and parent directory. if (in_array($file, array('.', '..'))) { continue; } // Create {File} instance. $file = new File($this->path, $path, $file); // If matches exclude files pattern. if ($file->nameMatch($this->config->get('excludeFiles')) or $file->pathMatch($this->config->get('excludePaths'))) { // Add file to excluded files. if ($file->isDirectory()) { $excludedDirectories[$file->getRelativePath()] = $file; } else { $excludedFiles[$file->getRelativePath()] = $file; } // Go to next item. continue; } // If directory. if ($file->isDirectory()) { // Merge sub-files matching patterns with current tree. $files += $this->scan($file->getAbsolutePath()); // Go to next item. continue; } // If file type and matches one pattern. if ($file->nameMatch($this->config->get('includeFiles'))) { // Add file to found files. $includedFiles[$file->getRelativePath()] = $file; } } ksort($excludedFiles, SORT_NATURAL | SORT_FLAG_CASE); ksort($excludedDirectories, SORT_NATURAL | SORT_FLAG_CASE); ksort($includedFiles, SORT_NATURAL | SORT_FLAG_CASE); return $this->files = array_merge_recursive(compact('excludedFiles', 'excludedDirectories', 'includedFiles'), $files); }
/** * Parse a file. * * - Extract DocBlocks. * - Tokkenize DocBlocks. * * @protected * @method parseFile * @param \LADoc\Builder\Files\File $file */ protected function parseFile(File $file) { // Reset parser properties. $this->inDocBlock = false; $this->line = null; $this->docBlock = null; $this->docBlocks = []; // For each line. foreach ($file->getLines() as $num => $contents) { // Create/Set current line instance. $this->line = new Line($num, $contents, $this->inDocBlock); // If the line start a DocBlock. if ($this->line->isType('docBlockStart')) { // Set we are in a DocBlock. $this->inDocBlock = true; // Create new DocBlock instance. $this->docBlock = new DocBlock($file); // Set the line start number. $this->docBlock->setLineNumber('from', $num); // Go to next line. continue; } // If the line end a DocBlock. if ($this->line->isType('docBlockEnd')) { // Validate the DocBlock. // Set the line end number. $this->docBlock->setLineNumber('to', $num); // Register the DocBlock. $this->docBlocks[] = $this->docBlock; // Set we are not in a DocBlock. $this->inDocBlock = false; // Go to next line. continue; } // If the line is in a DocBlock. if ($this->line->isType('docBlockData')) { // Parse DocBlock line. // Go to next line. continue; } // If the line is a single line comment. if ($this->line->isType('singleLineComment')) { // Parse comment line. // Add the comment line to last DocBlock. // Go to next line. continue; } } }