/** * @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; }
/** * Front matter date or filemtime * * @return DateTime */ public function getDate() { if (false === $this->frontMatter->has('date')) { # Defaults to last modified return (new DateTime())->setTimestamp($this->file->getMTime()); } $date = $this->frontMatter->getDate(); if ($date instanceof DateTime) { return $date; } return (new DateTime())->setTimestamp($date); }
public function updateContent(SplFileInfo $fileInfo) { $pathname = $this->getAttribute('pathname'); $process = new Process("diff {$pathname} {$fileInfo->getPathname()}", storage_path('pigeon')); $process->run(); $output = $process->getOutput(); preg_match_all('/^>\\s*(.*)/mix', $output, $matches); if ($matches) { $newText = implode("\n", $matches[1]); app('files')->append(storage_path('pigeon') . '/' . $pathname, "\n" . $newText); $this->setAttribute('modified_at', $fileInfo->getMTime()); } }
/** * Get ID3 info from a file. * * @param SplFileInfo $file * * @return array|null */ public function getInfo(SplFileInfo $file) { $info = $this->getID3->analyze($file->getPathname()); if (isset($info['error'])) { return; } // Copy the available tags over to comment. // This is a helper from getID3, though it doesn't really work well. // We'll still prefer getting ID3v2 tags directly later. // Read on. getid3_lib::CopyTagsToComments($info); $props = ['artist' => '', 'album' => '', 'title' => '', 'length' => $info['playtime_seconds'], 'lyrics' => '', 'cover' => array_get($info, 'comments.picture', [null])[0], 'path' => $file->getPathname(), 'mtime' => $file->getMTime()]; if (!($comments = array_get($info, 'comments_html'))) { return $props; } // We prefer id3v2 tags over others. if (!($artist = array_get($info, 'tags.id3v2.artist', [null])[0])) { $artist = array_get($comments, 'artist', [''])[0]; } if (!($album = array_get($info, 'tags.id3v2.album', [null])[0])) { $album = array_get($comments, 'album', [''])[0]; } if (!($title = array_get($info, 'tags.id3v2.title', [null])[0])) { $title = array_get($comments, 'title', [''])[0]; } if (!($lyrics = array_get($info, 'tags.id3v2.unsynchronised_lyric', [null])[0])) { $lyrics = array_get($comments, 'unsynchronised_lyric', [''])[0]; } $props['artist'] = trim($artist); $props['album'] = trim($album); $props['title'] = trim($title); $props['lyrics'] = trim($lyrics); return $props; }
function it_should_filter_by_date(SplFileInfo $file1, SplFileInfo $file2) { $file1->isFile()->willReturn(true); $file2->isFile()->willReturn(true); $file1->getRealPath()->willReturn($this->tempFile); $file2->getRealPath()->willReturn($this->tempFile); $file1->getMTime()->willReturn(strtotime('-4 hours')); $file2->getMTime()->willReturn(strtotime('-5 days')); $result = $this->date('since yesterday'); $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection'); $result->count()->shouldBe(1); $files = $result->toArray(); $files[0]->shouldBe($file1); }
private function getModifiedTime(SplFileInfo $file) { $dt = new \DateTime(); $dt->setTimestamp($file->getMTime()); return $dt->format(\DateTime::ISO8601); }
/** * 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; } }
/** * Extract all strings from a given file. * * @param SplFileInfo $file * * @return string[] */ protected function extractStringTokens(SplFileInfo $file) { // Fetch tokens from cache if available $hash = 'janitor.tokens.' . md5($file->getPathname()) . '-' . $file->getMTime(); return $this->cache->rememberForever($hash, function () use($file) { $contents = $file->getContents(); // See if we have an available Tokenizer // and use it to extract the contents switch ($file->getExtension()) { case 'php': $tokenizer = strpos($file->getBasename(), 'blade.php') !== false ? new BladeTokenizer() : new PhpTokenizer(); break; case 'twig': $tokenizer = new TwigTokenizer(); break; case 'json': $tokenizer = new JsonTokenizer(); break; case 'yml': case 'yaml': $tokenizer = new YamlTokenizer(); break; case 'xml': $tokenizer = new XmlTokenizer(); break; default: $tokenizer = new DefaultTokenizer(); break; } return $tokenizer->tokenize($contents); }); }
public function getMTime() { return $this->fileInfo->getMTime(); }