/** * 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; }
/** * Determine textbox size * * @param string $fontSize * @param int $angle * @param string $fontFile * @param string $text * @return array * * @throws Exception */ protected static function _getTextboxSize($fontSize, $angle, $fontFile, $text) { // Determine textbox size $fontPath = FS::clean($fontFile); if (!FS::isFile($fontPath)) { throw new Exception('Unable to load font: ' . $fontFile); } $box = imagettfbbox($fontSize, $angle, $fontFile, $text); $boxWidth = abs($box[6] - $box[2]); $boxHeight = abs($box[7] - $box[1]); return array($boxWidth, $boxHeight); }
/** * Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in Configure. * * @param string $path * @return null|string */ public function assetTimestamp($path) { if ($this->_timeStampEnable() && strpos($path, '?') === false) { $Path = $this->_View->getPath(); if ($Path->isVirtual($path)) { $path = $Path->get($path); } if (FS::isFile($path)) { //@codingStandardsIgnoreStart return $path . '?' . @filemtime($path); //@codingStandardsIgnoreEnd } } return $path; }
/** * Load an image * * @param string $filename Path to image file * @return $this * * @throws Exception */ public function loadFile($filename) { $cleanFilename = FS::clean($filename); if (!FS::isFile($cleanFilename)) { throw new Exception('Image file not forund: ' . $filename); } $this->cleanup(); $this->_filename = $cleanFilename; $this->_loadMeta(); return $this; }
/** * Preg replace callback url. * * @param $match * @return null|string */ protected function _replaceUrlCallback($match) { $path = FS::clean($match[2], '/'); if (isset($path[2]) && $path[2] == ':') { $path = ltrim($match[2], '/'); } $url = null; if (FS::isFile($path)) { $url = $this->_path->url($path); } return $this->_getAssetUrl($url); }
public function testIsFile() { isFalse(FS::isFile(__DIR__)); isTrue(FS::isFile(__FILE__)); }