for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Simple image caching component.
*
* @author Sam Stenvall <[email protected]>
* @copyright Copyright © Sam Stenvall 2013-
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
*/
class ImageCache
{
* @var string the absolute path to the cache
private $_cachePath;
* @var string the URL to the cache
private $_cacheUrl;
* Class constructor
public function __construct()
$this->_cachePath = realpath(Yii::app()->basePath.'/..').'/images/image-cache';
$this->_cacheUrl = Yii::app()->baseUrl.'/images/image-cache';
}
* Checks if the given file exists in the cache
* @param string $filename
* @return boolean
public function has($filename)
return file_exists($this->_cachePath.DIRECTORY_SEPARATOR.$filename);
* Returns the URL to the given file (assuming it is cached)
* @return string
public function get($filename)
return $this->_cacheUrl.'/'.$filename;
* Getter for _cachePath
public function getCachePath()
return $this->_cachePath;
* Getter for _cacheUrl
public function getCacheUrl()
return $this->_cacheUrl;