Esempio n. 1
0
 /**
  * @param $collection
  * @return bool
  */
 private function storeCollection($collection)
 {
     if (is_null($this->cache)) {
         return false;
     }
     $collection->fromCache = true;
     return $this->cache->set(__CLASS__, $collection);
 }
Esempio n. 2
0
 /**
  * @param string $path
  * @return Collection
  */
 public function build($path = null)
 {
     if (is_null($path)) {
         $path = $this->path;
     }
     $collection = $this->cache->get(__CLASS__);
     if ($collection === false) {
         $realpath = realpath($path);
         $collection = new Collection($this->blogRoute);
         if (is_readable($realpath)) {
             $loader = new FrontMatterLoader();
             foreach (scandir($realpath, 1) as $filename) {
                 if (in_array(substr($filename, 0, 1), ['.', '_'])) {
                     continue;
                 }
                 $pathinfo = pathinfo($filename);
                 if (!in_array($pathinfo['extension'], $this->extensions)) {
                     continue;
                 }
                 $data = $loader->load($realpath . '/' . $filename);
                 if (empty($data['modified'])) {
                     $data['modified'] = date('c', filemtime($realpath . '/' . $filename));
                 }
                 if (empty($data['date'])) {
                     $data['date'] = $this->extractDateFromPath($filename);
                 }
                 $data['path'] = '@post/' . $filename;
                 $data['blogRoute'] = $this->blogRoute;
                 $item = new Item($data);
                 $collection->addItem($item);
             }
         }
         $this->cache->set(__CLASS__, $collection);
     }
     #echo"<pre>";print_r($collection);echo"</pre>";
     return $collection;
 }