function testFindPath() { DocumentationService::register("DocumentationViewerTests", BASE_PATH . "/sapphiredocs/tests/docs/"); // file $path = DocumentationService::find_page('DocumentationViewerTests', array('test')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/test.md", $path); // the home page. The path finder should go to the index.md file in the default language $path = DocumentationService::find_page('DocumentationViewerTests', array('')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/index.md", $path); // second level $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subpage.md", $path); // subsubfolder has no index file. It should fail instead the viewer should pick up on this // and display the listing of the folder $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder')); $this->assertFalse($path); // third level $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path); // with trailing slash $path = DocumentationService::find_page('DocumentationViewerTests', array('subfolder', 'subsubfolder', 'subsubpage')); $this->assertEquals(BASE_PATH . "/sapphiredocs/tests/docs/en/subfolder/subsubfolder/subsubpage.md", $path); }
/** * Absolute path including version and lang folder. * * @throws InvalidArgumentException * * @param bool $defaultFile - If this is a folder and this is set to true then getPath * will return the path of the first file in the folder * @return string */ function getPath($defaultFile = false) { if ($this->entity) { $path = Controller::join_links($this->entity->getPath($this->getVersion(), $this->lang), $this->getRelativePath()); if (!is_dir($path)) { $path = realpath($path); } else { if ($defaultFile) { $file = DocumentationService::find_page($this->entity, explode('/', $this->getRelativePath())); if ($file) { $path = $file; } } } } else { $path = $this->getRelativePath(); } if (!file_exists($path)) { throw new InvalidArgumentException(sprintf('Path could not be found. Module path: %s, file path: %s', $this->entity->getPath(), $this->getRelativePath())); } return is_dir($path) ? rtrim($path, '/') . '/' : $path; }
/** * @return DocumentationPage */ function getPage() { $entity = $this->getEntity(); if (!$entity) { return false; } $version = $this->getVersion(); $lang = $this->getLang(); $absFilepath = DocumentationService::find_page($entity, $this->Remaining, $version, $lang); if ($absFilepath) { $relativeFilePath = str_replace($entity->getPath($version, $lang), '', $absFilepath); $page = new DocumentationPage(); $page->setRelativePath($relativeFilePath); $page->setEntity($entity); $page->setLang($lang); $page->setVersion($version); return $page; } return false; }