本文整理汇总了PHP中Cache::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::__construct方法的具体用法?PHP Cache::__construct怎么用?PHP Cache::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Check for existence of the wincache extension This method cannot be invoked externally. The driver must
* be instantiated using the `Cache::instance()` method.
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
protected function __construct(array $config)
{
if (!extension_loaded('wincache')) {
throw new Kohana_Cache_Exception('PHP wincache extension is not available.');
}
parent::__construct($config);
}
示例2: __construct
/**
* Sets up the PDO SQLite table and
* initialises the PDO connection
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
protected function __construct(array $config)
{
parent::__construct($config);
$database = Arr::get($this->_config, 'database', NULL);
if ($database === NULL) {
throw new Kohana_Cache_Exception('Database path not available in Kohana Cache configuration');
}
// Load new Sqlite DB
$this->_db = new PDO('sqlite:' . $database);
// Test for existing DB
$result = $this->_db->query("SELECT * FROM sqlite_master WHERE name = 'caches' AND type = 'table'")->fetchAll();
// If there is no table, create a new one
if (0 == count($result)) {
$database_schema = Arr::get($this->_config, 'schema', NULL);
if ($database_schema === NULL) {
throw new Kohana_Cache_Exception('Database schema not found in Kohana Cache configuration');
}
try {
// Create the caches table
$this->_db->query(Arr::get($this->_config, 'schema', NULL));
} catch (PDOException $e) {
throw new Kohana_Cache_Exception('Failed to create new SQLite caches table with the following error : :error', array(':error' => $e->getMessage()));
}
}
}
示例3: __construct
/**
* Responsiblity of the constructor is crucial.
* 1.Get the cache file path.
* 2.Create the cache file if it doesn't exists.
* 3.Get the area data if the file exists.
*/
public function __construct()
{
parent::__construct();
$this->areaService = new AreaService();
$this->filepath = parent::$path . '/' . self::$filename;
if (!file_exists($this->filepath)) {
$this->provinces = $this->areaService->getProvincesWithoutDirect();
$this->provincesWithSub = $this->areaService->getProvincesWithoutDirect();
$this->areaService->fillSubareas($this->provincesWithSub);
$this->cities = $this->areaService->getCitiesIncludeDirect();
$this->provinces_json = json_encode($this->provinces);
$this->provincesWithSub_json = json_encode($this->provincesWithSub);
$this->cities_json = json_encode($this->cities);
$this->writeIntoFile($this->provinces_json, $this->provincesWithSub_json, $this->cities_json);
} else {
$areaCacheFile = fopen($this->filepath, 'r') or die('File: ' . $this->filepath . ' open failed!');
$this->provinces_json = fgets($areaCacheFile);
$this->provincesWithSub_json = fgets($areaCacheFile);
$this->cities_json = fgets($areaCacheFile);
fclose($areaCacheFile);
$this->provinces = json_decode($this->provinces_json);
$this->provincesWithSub = json_decode($this->provincesWithSub_json);
$this->cities = json_decode($this->cities_json);
}
}
示例4: __construct
/**
* Check for existence of the APC extension This method cannot be invoked externally. The driver must
* be instantiated using the `Cache::instance()` method.
* @param array $config configuration
* @throws Cache_Exception
*/
protected function __construct(array $config)
{
if (!extension_loaded('apc')) {
throw new Cache_Exception('PHP APC extension is not available.');
}
parent::__construct($config);
}
示例5: __construct
public function __construct($prefix = '')
{
parent::__construct($prefix);
if (is_null(self::$cache)) {
// TODO allow configuring a RedisArray, see https://github.com/nicolasff/phpredis/blob/master/arrays.markdown#redis-arrays
self::$cache = new \Redis();
$config = \OC::$server->getSystemConfig()->getValue('redis', array());
if (isset($config['host'])) {
$host = $config['host'];
} else {
$host = '127.0.0.1';
}
if (isset($config['port'])) {
$port = $config['port'];
} else {
$port = 6379;
}
if (isset($config['timeout'])) {
$timeout = $config['timeout'];
} else {
$timeout = 0.0;
// unlimited
}
self::$cache->connect($host, $port, $timeout);
}
}
示例6: __construct
/**
* Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must
* be instantiated using the `Cache::instance()` method.
*
* @param array config
* @throws Cache_Exception
*/
protected function __construct(array $config)
{
// Setup parent
parent::__construct($config);
try {
$directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir);
$this->_cache_dir = new SplFileInfo($directory);
} catch (ErrorException $e) {
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
} catch (UnexpectedValueException $e) {
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
}
// If the defined directory is a file, get outta here
if ($this->_cache_dir->isFile()) {
throw new Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath()));
}
// Check the read status of the directory
if (!$this->_cache_dir->isReadable()) {
throw new Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
}
// Check the write status of the directory
if (!$this->_cache_dir->isWritable()) {
throw new Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
}
}
示例7: __construct
/**
* Check for existence of the APC extension
*
* @throws Kohana_Cache_Exception
*/
protected function __construct()
{
parent::__construct();
if (!extension_loaded('apc')) {
throw new Kohana_Cache_Exception('PHP APC extension is not available.');
}
}
示例8: __construct
/**
* Check for existence of the eAccelerator extension
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
protected function __construct(array $config)
{
if (!extension_loaded('eaccelerator')) {
throw new Kohana_Cache_Exception('PHP eAccelerator extension is not available.');
}
parent::__construct($config);
}
示例9: __construct
/**
* Check for existence of the APC extension
*
* [!!] This method cannot be invoked externally
*
* The driver must be instantiated using the `Cache::instance()` method.
*
* @param array $config configuration
*
* @throws Cache_Exception
*/
protected function __construct(array $config)
{
if (!function_exists('apc_store') or !ini_get('apc.enabled')) {
throw new Cache_Exception('You must have PHP APC installed and enabled to use.');
}
parent::__construct($config);
}
示例10: __construct
/**
* Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must
* be instantiated using the `Cache::instance()` method.
*
* @param array config
* @throws Kohana_Cache_Exception
*/
protected function __construct(array $config)
{
// Setup parent
parent::__construct($config);
try {
$directory = Arr::get($this->_config, 'cache_dir', APPPATH . Cache_File::CACHE_DIR);
$this->_cache_dir = new RecursiveDirectoryIterator($directory);
} catch (UnexpectedValueException $e) {
if (!mkdir($directory, 0777, TRUE)) {
throw new Kohana_Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory));
}
chmod($directory, 0777);
$this->_cache_dir = new RecursiveDirectoryIterator($directory);
}
// If the defined directory is a file, get outta here
if ($this->_cache_dir->isFile()) {
throw new Kohana_Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath()));
}
// Check the read status of the directory
if (!$this->_cache_dir->isReadable()) {
throw new Kohana_Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
}
// Check the write status of the directory
if (!$this->_cache_dir->isWritable()) {
throw new Kohana_Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
}
}
示例11: __construct
public function __construct($options = array())
{
parent::__construct($options);
$this->file = $this->optionable[self::PARAM_DIRECTORY] . self::KEY_PREFIX;
$this->fileTtl = $this->optionable[self::PARAM_DIRECTORY] . self::TTL_PREFIX;
$this->directory = $this->optionable[self::PARAM_DIRECTORY];
// $this->throwDbException();
}
示例12: __construct
public function __construct($config)
{
parent::__construct($config);
$servers = $this->_config['servers'];
$server = array_shift($servers);
$this->_redis = new Redis();
$this->_redis->connect($server['host'], $server['port']);
}
示例13: __construct
/**
* Constructs the memcached object
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
public function __construct(array $config)
{
// Check that memcached is loaded
if (!extension_loaded('memcached')) {
throw new Kohana_Cache_Exception('Memcached extension is not loaded');
}
parent::__construct($config);
// Check whether this is a persistent connection
if ($config['persistent'] == FALSE) {
// Setup a non-persistent memcached connection
$this->_memcached = new Memcached();
} else {
// Setup a persistent memcached connection
$this->_memcached = new Memcached($this->_config['persistent_id']);
}
// Load servers from configuration
$servers = Arr::get($this->_config, 'servers', NULL);
if (!$servers) {
// Throw exception if no servers found in configuration
throw new Kohana_Cache_Exception('No Memcache servers defined in configuration');
}
// Add memcache servers
foreach ($servers as $server) {
if (!$this->_memcached->addServer($server['host'], $server['port'], $server['weight'])) {
throw new Kohana_Cache_Exception('Could not connect to memcache host at \':host\' using port \':port\'', array(':host' => $server['host'], ':port' => $server['port']));
}
}
// Load memcached options from configuration
$options = Arr::get($this->_config, 'options', NULL);
// Make sure there are options to set
if ($options != NULL) {
// Set the options
foreach ($options as $key => $value) {
// Special cases for a few options
switch ($key) {
case 'serializer':
$value = $this->_serializer_map[$value];
break;
case 'hash':
$value = $this->_hash_map[$value];
break;
case 'distribution':
$value = $this->_distribution_map[$value];
break;
case 'prefix_key':
// Throw exception is key prefix is greater than 128 characters
if (strlen($value) > 128) {
throw new Kohana_Cache_Exception('Memcached prefix key cannot exceed 128 characters');
}
break;
default:
break;
}
$this->_memcached->setOption($this->_options_map[$key], $value);
}
}
}
示例14: __construct
public function __construct($prefix = '')
{
parent::__construct($prefix);
if (is_null(self::$cache)) {
self::$cache = new \Memcached();
list($host, $port) = \OC_Config::getValue('memcached_server', array('localhost', 11211));
self::$cache->addServer($host, $port);
}
}
示例15: __construct
/**
* Constructs the redis Kohana_Cache object
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
public function __construct(array $config)
{
// Check for the Rediska module
if (!class_exists('Rediska')) {
throw new Kohana_Cache_Exception('Rediska module not loaded');
}
parent::__construct($config);
$instance = Arr::get($this->_config, 'instance', Rediska::DEFAULT_NAME);
$this->_rediska = Rediska_Manager::get($instance);
}