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;
 }
 /**
  * @param LoadPageHeadersCommand $command
  * @return \Anomaly\FizlPages\Page\Contract\Page
  */
 public function handle(LoadPageHeadersCommand $command)
 {
     $page = $command->getPage();
     if ($view = $page->getView() and !$page->isMissing()) {
         $view->render();
     }
     $cacheKey = $page->getPath() . '.headers';
     $headers = $this->cache->get($cacheKey) ?: [];
     foreach ($headers as $key => $value) {
         $headers[$key] = new Header($key, $value);
     }
     $page->setHeaders(new HeaderCollection($headers));
     //$this->execute(new PushHeadersIntoCollectionCommand($headers, $page->getHeaders()));
     $page->raise(new PageHeadersLoaded($page));
     return $page;
 }