for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* AnimeDb package.
*
* @author Peter Gribanov <[email protected]>
* @copyright Copyright (c) 2014, Peter Gribanov
* @license http://opensource.org/licenses/MIT
*/
namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver;
class File extends BaseDriver
{
* @var string
const FILENAME_SUFFIX = '.key';
protected $dir;
* @param string $dir
public function __construct($dir)
$this->dir = $dir;
}
* @param string $key
* @return \DateTime|null
public function get($key)
$file = $this->getFilename($key);
if (file_exists($file)) {
return (new \DateTime())->setTimestamp(filemtime($file));
return;
* @param \DateTime $time
* @return bool
public function set($key, \DateTime $time)
$time = $time->getTimestamp();
if (!file_exists($file) || $time > filemtime($file)) {
return touch($file, $time);
return true;
public function remove($key)
return unlink($file);
return false;
* @return string
protected function getFilename($key)
if (!is_dir($this->dir)) {
mkdir($this->dir, 0755, true);
return $this->dir.'/'.md5($key).self::FILENAME_SUFFIX;