Ejemplo n.º 1
0
 public function load($slug, array $file = [])
 {
     if (!($post = Redis::hgetall(Key::post($slug, $this->language)))) {
         if (!$file) {
             $list = $this->loadList();
             $file = array_key_exists($slug, $list) ? $list[$slug] : null;
         }
         if (!$file) {
             return null;
         }
         $processed = self::process((new Filesystem())->get($file['path']));
         $post = array_merge($file, $processed);
         $post['published'] = $post['published']->format(\DateTime::ISO8601);
         $post['tags'] = json_encode($post['tags']);
         foreach ($post as $field => $value) {
             Redis::hsetnx(Key::post($slug, $this->language), $field, $value);
         }
     }
     $post['published'] = new \DateTime($post['published']);
     $post['tags'] = json_decode($post['tags']);
     return $post;
 }