本文整理汇总了PHP中Doctrine\Common\Cache\Cache::getNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::getNamespace方法的具体用法?PHP Cache::getNamespace怎么用?PHP Cache::getNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Cache\Cache
的用法示例。
在下文中一共展示了Cache::getNamespace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string $qbankURL The URL to the QBank API.
* @param Credentials $credentials The credentials used to connect.
* @param array $options Associative array containing options.
* <ul>
* <li>Cache $options[cache] A cache implementation to store tokens and responses in. Highly recommended.</li>
* <li>QBankCachePolicy $options[cachePolicy] A policy on how to use caching for API queries, if not provided cache will not be available for API queries.</li>
* <li>LoggerInterface $options[log] A PSR-3 log implementation.</li>
* <li>bool $options[verifyCertificates] Whether to verify certificates for https connections. Defaults to true.</li>
* </ul>
*/
public function __construct($qbankURL, Credentials $credentials, array $options = [])
{
// Setup logging
if (!empty($options['log']) && $options['log'] instanceof LoggerInterface) {
$this->logger = $options['log'];
} else {
$this->logger = new NullLogger();
}
$this->basepath = $this->buildBasepath($qbankURL);
// Store credentials for later use
$this->credentials = $credentials;
// Optionaly setup cache
if (!empty($options['cache']) && $options['cache'] instanceof Cache) {
$this->cache = $options['cache'];
if ($this->cache instanceof CacheProvider && !$this->cache->getNamespace()) {
$this->cache->setNamespace(md5($this->basepath . $this->credentials->getUsername() . $this->credentials->getPassword()));
}
} else {
$this->logger->notice('No caching supplied! Without caching both performance and security is reduced.');
}
// Setup the cache policy
if (!empty($options['cachePolicy']) && $options['cachePolicy'] instanceof CachePolicy) {
$this->cachePolicy = $options['cachePolicy'];
if (!$this->cache instanceof Cache && $this->cachePolicy->isEnabled()) {
throw new \LogicException('You have supplied a cache policy that says cache is enabled but no cache provider have been defined.');
}
} else {
$this->cachePolicy = new CachePolicy(false, 0);
$this->logger->warning('No cache policy supplied! Without a cache policy no API queries will be cached.');
}
if (isset($options['verifyCertificates'])) {
$this->verifyCertificates = (bool) $options['verifyCertificates'];
} else {
$this->verifyCertificates = true;
}
}