Exemple #1
0
 /**
  * Constructor.
  *
  * You can either pass an existing database connection as PDO instance or
  * a Doctrine DBAL Connection or a DSN string that will be used to
  * lazy-connect to the database when the cache is actually used.
  *
  * List of available options:
  *  * db_table: The name of the table [default: cache_items]
  *  * db_id_col: The column where to store the cache id [default: item_id]
  *  * db_data_col: The column where to store the cache data [default: item_data]
  *  * db_lifetime_col: The column where to store the lifetime [default: item_lifetime]
  *  * db_time_col: The column where to store the timestamp [default: item_time]
  *  * db_username: The username when lazy-connect [default: '']
  *  * db_password: The password when lazy-connect [default: '']
  *  * db_connection_options: An array of driver-specific connection options [default: array()]
  *
  * @param \PDO|Connection|string $connOrDsn       A \PDO or Connection instance or DSN string or null
  * @param string                 $namespace
  * @param int                    $defaultLifetime
  * @param array                  $options         An associative array of options
  *
  * @throws InvalidArgumentException When first argument is not PDO nor Connection nor string
  * @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
  * @throws InvalidArgumentException When namespace contains invalid characters
  */
 public function __construct($connOrDsn, $namespace = '', $defaultLifetime = 0, array $options = array())
 {
     if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
         throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
     }
     if ($connOrDsn instanceof \PDO) {
         if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
             throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))', __CLASS__));
         }
         $this->conn = $connOrDsn;
     } elseif ($connOrDsn instanceof Connection) {
         $this->conn = $connOrDsn;
     } elseif (is_string($connOrDsn)) {
         $this->dsn = $connOrDsn;
     } else {
         throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\\DBAL\\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, is_object($connOrDsn) ? get_class($connOrDsn) : gettype($connOrDsn)));
     }
     $this->table = isset($options['db_table']) ? $options['db_table'] : $this->table;
     $this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : $this->idCol;
     $this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : $this->dataCol;
     $this->lifetimeCol = isset($options['db_lifetime_col']) ? $options['db_lifetime_col'] : $this->lifetimeCol;
     $this->timeCol = isset($options['db_time_col']) ? $options['db_time_col'] : $this->timeCol;
     $this->username = isset($options['db_username']) ? $options['db_username'] : $this->username;
     $this->password = isset($options['db_password']) ? $options['db_password'] : $this->password;
     $this->connectionOptions = isset($options['db_connection_options']) ? $options['db_connection_options'] : $this->connectionOptions;
     parent::__construct($namespace, $defaultLifetime);
 }
 public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
 {
     parent::__construct('', $defaultLifetime);
     if (!isset($directory[0])) {
         $directory = sys_get_temp_dir() . '/symfony-cache';
     }
     if (isset($namespace[0])) {
         if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
             throw new InvalidArgumentException(sprintf('FilesystemAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
         }
         $directory .= '/' . $namespace;
     }
     if (!file_exists($dir = $directory . '/.')) {
         @mkdir($directory, 0777, true);
     }
     if (false === ($dir = realpath($dir))) {
         throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
     }
     if (!is_writable($dir .= DIRECTORY_SEPARATOR)) {
         throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory));
     }
     // On Windows the whole path is limited to 258 chars
     if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
         throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
     }
     $this->directory = $dir;
 }
Exemple #3
0
 public function __construct(\Redis $redisConnection, $namespace = '', $defaultLifetime = 0)
 {
     $this->redis = $redisConnection;
     if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
         throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
     }
     parent::__construct($namespace, $defaultLifetime);
 }
Exemple #4
0
 public function __construct($namespace = '', $defaultLifetime = 0)
 {
     if (!function_exists('apcu_fetch') || !ini_get('apc.enabled') || 'cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
         throw new CacheException('APCu is not enabled');
     }
     if ('cli' === PHP_SAPI) {
         ini_set('apc.use_request_time', 0);
     }
     parent::__construct($namespace, $defaultLifetime);
 }
 /**
  * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
  */
 public function __construct($redisClient, $namespace = '', $defaultLifetime = 0)
 {
     parent::__construct($namespace, $defaultLifetime);
     if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
         throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
     }
     if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\Client) {
         throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\\Client, %s given', __METHOD__, is_object($redisClient) ? get_class($redisClient) : gettype($redisClient)));
     }
     $this->redis = $redisClient;
 }
Exemple #6
0
 public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
 {
     if (!static::isSupported()) {
         throw new CacheException('OPcache is not enabled');
     }
     parent::__construct('', $defaultLifetime);
     $this->init($namespace, $directory);
     $e = new \Exception();
     $this->includeHandler = function () use($e) {
         throw $e;
     };
 }
Exemple #7
0
 public function __construct($namespace = '', $defaultLifetime = 0, $version = null)
 {
     if (!static::isSupported()) {
         throw new CacheException('APCu is not enabled');
     }
     if ('cli' === PHP_SAPI) {
         ini_set('apc.use_request_time', 0);
     }
     parent::__construct($namespace, $defaultLifetime);
     if (null !== $version) {
         CacheItem::validateKey($version);
         if (!apcu_exists($version . ':' . $namespace)) {
             $this->clear($namespace);
             apcu_add($version . ':' . $namespace, null);
         }
     }
 }
Exemple #8
0
 public function __construct($directory, $defaultLifetime = null)
 {
     parent::__construct('', $defaultLifetime);
     if (!file_exists($dir = $directory . '/.')) {
         @mkdir($directory, 0777, true);
     }
     if (false === ($dir = realpath($dir))) {
         throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
     }
     if (!is_writable($dir .= DIRECTORY_SEPARATOR)) {
         throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory));
     }
     // On Windows the whole path is limited to 258 chars
     if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 190) {
         throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
     }
     $this->directory = $dir;
 }
 public function __construct($directory, $defaultLifetime = 0, $namespace = '')
 {
     parent::__construct('', $defaultLifetime);
     if (!isset($directory[0])) {
         $directory = sys_get_temp_dir() . '/symfony-cache';
     }
     if (isset($namespace[0])) {
         $directory .= '/' . $namespace;
     }
     if (!file_exists($dir = $directory . '/.')) {
         @mkdir($directory, 0777, true);
     }
     if (false === ($dir = realpath($dir))) {
         throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
     }
     if (!is_writable($dir .= DIRECTORY_SEPARATOR)) {
         throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory));
     }
     // On Windows the whole path is limited to 258 chars
     if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
         throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
     }
     $this->directory = $dir;
 }
Exemple #10
0
 /**
  * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
  */
 public function __construct($redisClient, $namespace = '', $defaultLifetime = 0)
 {
     parent::__construct($namespace, $defaultLifetime);
     $this->setRedis($redisClient, $namespace);
 }
Exemple #11
0
 public function __construct(CacheProvider $provider, $defaultLifetime = null)
 {
     parent::__construct('', $defaultLifetime);
     $this->provider = $provider;
 }
 public function __construct(CacheProvider $provider, $namespace = '', $defaultLifetime = 0)
 {
     parent::__construct('', $defaultLifetime);
     $this->provider = $provider;
     $provider->setNamespace($namespace);
 }
 public function __construct($ns)
 {
     parent::__construct($ns);
 }