getFile() 공개 정적인 메소드

Locate a file in the tree. Returns the file if found or false
public static getFile ( Directory $tree, string $request ) : Todaymade\Daux\Tree\Content | Tree\Raw | false
$tree Todaymade\Daux\Tree\Directory
$request string
리턴 Todaymade\Daux\Tree\Content | Tree\Raw | false
예제 #1
0
 /**
  * @param string $url
  * @return Entry
  * @throws LinkNotFoundException
  */
 protected function resolveInternalFile($url)
 {
     $triedAbsolute = false;
     // Legacy absolute paths could start with
     // "!" In this case we will try to find
     // the file starting at the root
     if ($url[0] == '!' || $url[0] == '/') {
         $url = ltrim($url, '!/');
         if ($file = DauxHelper::getFile($this->daux['tree'], $url)) {
             return $file;
         }
         $triedAbsolute = true;
     }
     // Seems it's not an absolute path or not found,
     // so we'll continue with the current folder
     if ($file = DauxHelper::getFile($this->daux->getCurrentPage()->getParent(), $url)) {
         return $file;
     }
     // If we didn't already try it, we'll
     // do a pass starting at the root
     if (!$triedAbsolute && ($file = DauxHelper::getFile($this->daux['tree'], $url))) {
         return $file;
     }
     throw new LinkNotFoundException("Could not locate file '{$url}'");
 }
예제 #2
0
 /**
  * @dataProvider providerRenderLink
  */
 public function testRenderLink($expected, $string, $current)
 {
     $config = new Config();
     $config['base_url'] = '';
     $config['tree'] = $this->getTree($config);
     $config->setCurrentPage(DauxHelper::getFile($config['tree'], $current));
     $converter = new CommonMarkConverter(['daux' => $config]);
     $this->assertEquals("<p>{$expected}</p>", trim($converter->convertToHtml($string)));
 }
예제 #3
0
 /**
  * @param string $url
  * @return Entry
  * @throws Exception
  */
 protected function resolveInternalFile($url)
 {
     $file = DauxHelper::getFile($this->daux['tree'], $url);
     if ($file) {
         return $file;
     }
     $file = DauxHelper::getFile($this->daux['tree'], $url . '.html');
     if ($file) {
         return $file;
     }
     throw new Exception("Could not locate file '{$url}'");
 }
예제 #4
0
 private function findImage($src, $tag, Content $file, $callback)
 {
     //for protocol relative or http requests : keep the original one
     if (substr($src, 0, strlen('http')) === 'http' || substr($src, 0, strlen('//')) === '//') {
         return $src;
     }
     //Get the path to the file, relative to the root of the documentation
     $url = DauxHelper::getCleanPath(dirname($file->getUrl()) . '/' . $src);
     //Get any file corresponding to the right one
     $file = DauxHelper::getFile($this->tree, $url);
     if ($file === false) {
         return false;
     }
     $result = $callback($src, $this->getAttributes($tag), $file);
     return $result ?: $src;
 }
예제 #5
0
파일: Server.php 프로젝트: rlugojr/daux.io
 /**
  * @param string $request
  * @return \Todaymade\Daux\Format\Base\Page
  * @throws NotFoundException
  */
 private function getPage($request)
 {
     $file = DauxHelper::getFile($this->daux->tree, $request);
     if ($file === false) {
         throw new NotFoundException('The Page you requested is yet to be made. Try again later.');
     }
     $generator = $this->daux->getGenerator();
     if (!$generator instanceof LiveGenerator) {
         throw new \RuntimeException("The generator '" . get_class($generator) . "' does not implement the interface " . "'Todaymade\\Daux\\Format\\Base\\LiveGenerator' and thus doesn't support live rendering.");
     }
     return $this->daux->getGenerator()->generateOne($file, $this->params);
 }