diff --git a/library/Icinga/File/FileExtensionFilterIterator.php b/library/Icinga/File/FileExtensionFilterIterator.php deleted file mode 100644 index 41efce0ad..000000000 --- a/library/Icinga/File/FileExtensionFilterIterator.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - */ -class FileExtensionFilterIterator extends FilterIterator -{ - /** - * The extension to filter for - * - * @var string - */ - protected $extension; - - /** - * Create a new FileExtensionFilterIterator - * - * @param Iterator $iterator Apply filter to this iterator - * @param string $extension The file extension to filter for. The file extension may not contain the leading dot - */ - public function __construct(Iterator $iterator, $extension) - { - $this->extension = '.' . ltrim(strtolower((string) $extension), '.'); - parent::__construct($iterator); - } - - /** - * Accept files which match the file extension to filter for - * - * @return bool Whether the current element of the iterator is acceptable - * through this filter - */ - public function accept() - { - $current = $this->current(); - /** @var $current \SplFileInfo */ - if (! $current->isFile()) { - return false; - } - // SplFileInfo::getExtension() is only available since PHP 5 >= 5.3.6 - $filename = $current->getFilename(); - $sfx = substr($filename, -strlen($this->extension)); - return $sfx === false ? false : strtolower($sfx) === $this->extension; - } -} diff --git a/library/Icinga/File/NonEmptyFileIterator.php b/library/Icinga/File/NonEmptyFileIterator.php deleted file mode 100644 index 03756ccd2..000000000 --- a/library/Icinga/File/NonEmptyFileIterator.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - */ -class NonEmptyFileIterator extends FilterIterator -{ - /** - * Accept non-empty files - * - * @return bool Whether the current element of the iterator is acceptable - * through this filter - */ - public function accept() - { - $current = $this->current(); - /** @var $current \SplFileInfo */ - if (! $current->isFile() - || $current->getSize() === 0 - ) { - return false; - } - return true; - } -} diff --git a/modules/doc/library/Doc/DocIterator.php b/modules/doc/library/Doc/DocIterator.php deleted file mode 100644 index 430d25445..000000000 --- a/modules/doc/library/Doc/DocIterator.php +++ /dev/null @@ -1,63 +0,0 @@ -fileInfo = $fileInfo; - } - - /** - * {@inheritdoc} - */ - public function count() - { - return count($this->fileInfo); - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - return new ArrayIterator($this->fileInfo); - } -} diff --git a/modules/doc/library/Doc/DocParser.php b/modules/doc/library/Doc/DocParser.php index bffe86db0..87d09733c 100644 --- a/modules/doc/library/Doc/DocParser.php +++ b/modules/doc/library/Doc/DocParser.php @@ -4,11 +4,11 @@ namespace Icinga\Module\Doc; use CachingIterator; -use LogicException; +use SplFileObject; use SplStack; use Icinga\Data\Tree\SimpleTree; use Icinga\Exception\NotReadableError; -use Icinga\Module\Doc\Exception\DocEmptyException; +use Icinga\Util\DirectoryIterator; use Icinga\Module\Doc\Exception\DocException; /** @@ -40,7 +40,7 @@ class DocParser /** * Iterator over documentation files * - * @var DocIterator + * @var DirectoryIterator */ protected $docIterator; @@ -51,34 +51,17 @@ class DocParser * * @throws DocException If the documentation directory does not exist * @throws NotReadableError If the documentation directory is not readable - * @throws DocEmptyException If the documentation directory is empty */ public function __construct($path) { - if (! is_dir($path)) { + if (! DirectoryIterator::isReadable($path)) { throw new DocException( - sprintf(mt('doc', 'Documentation directory \'%s\' does not exist'), $path) - ); - } - if (! is_readable($path)) { - throw new DocException( - sprintf(mt('doc', 'Documentation directory \'%s\' is not readable'), $path) - ); - } - $docIterator = new DocIterator($path); - if ($docIterator->count() === 0) { - throw new DocEmptyException( - sprintf( - mt( - 'doc', - 'Documentation directory \'%s\' does not contain any non-empty Markdown file (\'.md\' suffix)' - ), - $path - ) + mt('doc', 'Documentation directory \'%s\' is not readable'), + $path ); } $this->path = $path; - $this->docIterator = $docIterator; + $this->docIterator = new DirectoryIterator($path, 'md'); } /** @@ -145,9 +128,8 @@ class DocParser public function getDocTree() { $tree = new SimpleTree(); - foreach ($this->docIterator as $fileInfo) { - /** @var $fileInfo \SplFileInfo */ - $file = $fileInfo->openFile(); + foreach ($this->docIterator as $filename) { + $file = new SplFileObject($filename); $lastLine = null; $stack = new SplStack(); $cachingIterator = new CachingIterator($file, CachingIterator::TOSTRING_USE_CURRENT); diff --git a/modules/doc/library/Doc/Exception/DocEmptyException.php b/modules/doc/library/Doc/Exception/DocEmptyException.php deleted file mode 100644 index 0ce563cf1..000000000 --- a/modules/doc/library/Doc/Exception/DocEmptyException.php +++ /dev/null @@ -1,11 +0,0 @@ -content)) { + return '

' . mt('doc', 'Documentation is empty.') . '

'; + } $view = $this->getView(); $zendUrlHelper = $view->getHelper('Url'); foreach ($this as $section) {