예제 #1
0
 /**
  * Parse the contents of the file.
  *
  * Example:
  *
  *     ---
  *     title: Title
  *     date: 2016-07-29
  *     ---
  *     Lorem Ipsum.
  *
  * @throws \RuntimeException
  *
  * @return $this
  */
 public function parse()
 {
     if ($this->file->isFile()) {
         if (!$this->file->isReadable()) {
             throw new \RuntimeException('Cannot read file');
         }
         // parse front matter
         preg_match('/' . self::PATTERN . '/s', $this->file->getContents(), $matches);
         // if not front matter, set body only
         if (!$matches) {
             $this->body = $this->file->getContents();
             return $this;
         }
         $this->frontmatter = trim($matches[1]);
         $this->body = trim($matches[2]);
     }
     return $this;
 }
 /**
  * Todas las propiedades de un archivo o directorio
  * 
  * @param SplFileInfo $file Object of SplFileInfo
  * @param string $path Ruta de la carpeta o archivo
  * @return array|null Lista de propiedades o null si no es leible
  */
 public function fileInfo($file, $path)
 {
     if ($file->isReadable()) {
         $item = $this->fileDetails;
         $item["filename"] = $file->getFilename();
         $item["filetype"] = $file->getExtension();
         $item["lastmodified"] = $file->getMTime();
         $item["size"] = $file->getSize();
         if ($file->isDir()) {
             $item["filetype"] = '';
             $item["isdir"] = true;
             $item["urlfolder"] = $path . $item["filename"] . '/';
             $item['preview'] = '';
         } elseif ($file->isFile()) {
             $thumb = $this->createThumb($file, $path);
             if ($thumb) {
                 $item['preview'] = $this->config['url'] . $this->config['source'] . '/_thumbs' . $path . $thumb;
             }
             $item['previewfull'] = $this->config['url'] . $this->config['source'] . $path . $item["filename"];
         }
         return $item;
     } else {
         return;
     }
 }
 public function isReadable()
 {
     return $this->fileInfo->isReadable();
 }