public function testServingFile() { $response = new StaticFileResponse($this->testFilePath); $lastModified = new DateTime(); $lastModified->setTimestamp(File::lastModified($this->testFilePath)); $this->assertEquals($response->getStatusCode(), 200); $this->assertEquals($response->getContent(), $this->testFileContent); $this->assertEquals($response->getLastModified()->getTimestamp(), $lastModified->getTimestamp()); }
/** * Pārbauda iekļauto JavaScript datņu unikalitāti un ievieto vēl neiekļautās norādes JavaScript masīvā * * @param array $inc_arr Bloka iekļauto JavaScript norāžu masīvs */ private function checkIncludesUniq($inc_arr) { foreach ($inc_arr as $inc) { $inc = $inc . "?v=" . File::lastModified(public_path() . "/" . $inc); if (!in_array($inc, $this->script_arr)) { $this->script_arr[count($this->script_arr)] = $inc; } } }
public function __construct($filePath) { parent::__construct(); if (!File::isFile($filePath)) { throw new Exception("Cannot read file: {$filePath}"); } $fileContent = file_get_contents($filePath); $this->setContent($fileContent); $lastModified = new DateTime(); $lastModified->setTimestamp(File::lastModified($filePath)); $this->setLastModified($lastModified); $this->isNotModified(App::make('request')); }
/** * Resize an image * @param string $url * @param integer $width * @param integer $height * @param boolean $crop * @return string */ public function resize($url, $width = 100, $height = null, $crop = false, $quality = 90) { if ($url) { // URL info $info = pathinfo($url); // The size if (!$height) { $height = $width; } // Quality $quality = Config::get('redminportal::image.quality', $quality); // Directories and file names $fileName = $info['basename']; $sourceDirPath = public_path() . '/' . $info['dirname']; $sourceFilePath = $sourceDirPath . '/' . $fileName; $targetDirName = $width . 'x' . $height . ($crop ? '_crop' : ''); $targetDirPath = $sourceDirPath . '/' . $targetDirName . '/'; $targetFilePath = $targetDirPath . $fileName; $targetUrl = asset($info['dirname'] . '/' . $targetDirName . '/' . $fileName); // Create directory if missing try { // Create dir if missing if (!Filesystem::isDirectory($targetDirPath) and $targetDirPath) { @Filesystem::makeDirectory($targetDirPath); } // Set the size $size = new Box($width, $height); // Now the mode $mode = $crop ? ImageInterface::THUMBNAIL_OUTBOUND : ImageInterface::THUMBNAIL_INSET; if (!Filesystem::exists($targetFilePath) or Filesystem::lastModified($targetFilePath) < Filesystem::lastModified($sourceFilePath)) { $this->imagine->open($sourceFilePath)->thumbnail($size, $mode)->save($targetFilePath, array('quality' => $quality)); } } catch (\Exception $e) { Log::error('[IMAGE SERVICE] Failed to resize image "' . $url . '" [' . $e->getMessage() . ']'); } return $targetUrl; } }
/** * Get file last modified * * @param string $filePath File path * @return int Last modified time */ private function lastModified($filePath) { return File::lastModified($filePath); }
/** * Combine the given array of assets. Minify, if enabled. * Returns new array containing one asset. * * @param array $assets Array of assets. * @param string $type File type (script, style). * * @return array */ public function combine(array $assets, $type) { $paths = array(); $lastmod = 0; foreach ($assets as $asset) { $paths[] = $asset['path']; $mod = @File::lastModified($asset['path']); if ($mod > $lastmod) { $lastmod = $mod; } } if ($this->show_refer) { $file = $this->cache_path . '/casset-' . md5(implode(',', $paths) . $lastmod) . '-' . $this->name; } else { $file = $this->cache_path . '/' . md5(implode(',', $paths) . $lastmod); } $file .= 'script' === $type ? '.js' : '.css'; $combine = false; if (!File::exists($file)) { $combine = true; } else { if (File::lastModified($file) < $lastmod) { $combine = true; } } if ($combine) { $content = ''; foreach ($assets as $asset) { if (!File::exists($asset['path'])) { continue; } $c = File::get($asset['path']); if ($asset['ext'] == 'css' && preg_match_all('~url\\(([\\"\'^\\)]*)?([^\\)]*)([\\"\'^\\)]*)?\\)~i', $c, $match)) { foreach ($match[2] as $row => $link) { $link = UrlFormat::toAbsolute(asset($asset['url']), $link); $c = str_replace($match[0][$row], 'url("' . preg_replace('~^https?:~i', '', $link) . '")', $c); } } if ($this->minify && !(stripos($asset['source'], '.min') || stripos($asset['source'], '-min'))) { switch ($type) { case 'style': $min = new \CSSmin(); $c = $min->run($c); #$c = Compressors\Css::process($c); break; case 'script': $c = \JSMin::minify($c); #$c = Compressors\Js::minify($c); break; } } if ($this->show_refer) { $content .= "/* {$asset['source']} */\n{$c}\n\n"; } else { $content .= "/* --- */\n{$c}\n\n"; } } File::put($file, $content); } return array(array('path' => $file, 'attributes' => array(), 'url' => str_ireplace($this->public_path, '', $file))); }
/** * Combine the given array of assets. Minify, if enabled. * Returns new array containing one asset. * * @param array $assets Array of assets. * @param string $type File type (script, style). * * @return array */ public function combine(array $assets, $type) { $paths = array(); $lastmod = 0; foreach ($assets as $asset) { $paths[] = $asset['path']; $mod = File::lastModified($asset['path']); if ($mod > $lastmod) { $lastmod = $mod; } } $file = $this->cache_path . '/casset-' . md5(implode(',', $paths) . $lastmod) . '-' . $this->name; $file .= 'script' === $type ? '.js' : '.css'; $combine = false; if (!File::exists($file)) { $combine = true; } else { if (File::lastModified($file) < $lastmod) { $combine = true; } } if ($combine) { $content = ''; foreach ($assets as $asset) { if (!File::exists($asset['path'])) { continue; } $c = File::get($asset['path']); if ($this->minify && !(stripos($asset['source'], '.min') || stripos($asset['source'], '-min'))) { switch ($type) { case 'style': $c = Compressors\Css::process($c); break; case 'script': $c = Compressors\Js::minify($c); break; } } $content .= "/* {$asset['source']} */\n{$c}\n\n"; } File::put($file, $content); } return array(array('path' => $file, 'attributes' => array(), 'url' => str_ireplace($this->public_path, '', $file))); }