firstLine() public static method

Quickest way for getting first file line
public static firstLine ( string $filepath ) : string
$filepath string
return string
コード例 #1
0
ファイル: LessHelper.php プロジェクト: UnionCMS/Core
 /**
  * Less process file.
  *
  * @param string $source ("Example: MyPlugin.path/to/file.less")
  * @param bool|false $force
  * @throws \JBZoo\Less\Exception
  * @return string
  */
 public function process($source, $force = false)
 {
     $file = $this->_path->isVirtual($source) ? $this->_path->get($source) : $this->_path->get('root:' . $source);
     try {
         if ($force) {
             $this->config('force', true);
         }
         $less = new Less($this->_config);
         if (!FS::isFile($file)) {
             return $source;
         }
         list($source, $isExpired) = $less->compile($file);
         if ($isExpired) {
             $cacheId = FS::firstLine($source);
             $comment = '/* resource: ' . $this->_path->url($file) . ' */' . PHP_EOL;
             $fileHead = implode('', [$cacheId, Str::low($comment)]);
             $css = $this->_normalizeContent($source, $fileHead);
             $this->_write($source, $css);
         }
         $source = $this->_path->url(FS::clean($source, '/'));
         return $source;
     } catch (InternalErrorException $e) {
         throw new InternalErrorException($e->getMessage());
     }
 }
コード例 #2
0
ファイル: Cache.php プロジェクト: jbzoo/less
 /**
  * Check is current cache is expired
  */
 public function isExpired()
 {
     if (!FS::isFile($this->_resultFile)) {
         return true;
     }
     $fileAge = abs(time() - filemtime($this->_resultFile));
     if ($fileAge >= $this->_cache_ttl) {
         return true;
     }
     $firstLine = trim(FS::firstLine($this->_resultFile));
     $expected = trim($this->_getHeader());
     if ($expected === $firstLine) {
         return false;
     }
     return true;
 }
コード例 #3
0
ファイル: FileSystemTest.php プロジェクト: jbzoo/utils
 public function testFirstLine()
 {
     isContain('<?php', FS::firstLine(__FILE__));
     isNull(FS::firstLine(__FILE__ . '_noexists'));
 }