Exemplo n.º 1
1
 /**
  * @param      $string
  * @param null $path
  * @return string
  */
 public function parse($string, $path = null)
 {
     $headers = [];
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3);
     if (count($parts) == 3) {
         $string = $parts[0] . "\n" . $parts[2];
         $headers = $this->yaml->parse($parts[1]);
     }
     $file = new SplFileInfo($path, '', '');
     $date = Carbon::createFromTimestamp($file->getMTime());
     $dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia');
     $headers['date_modified'] = $date->toDateTimeString();
     if (isset($headers['date'])) {
         try {
             $headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString();
         } catch (\InvalidArgumentException $e) {
             $headers['date'] = $headers['date_modified'];
             //dd($e->getMessage());
         }
     } else {
         $headers['date'] = $headers['date_modified'];
     }
     $this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers));
     $viewPath = PageHelper::filePathToViewPath($path);
     $cacheKey = "{$viewPath}.headers";
     $this->cache->put($cacheKey, $headers);
     return $string;
 }