当前位置: 首页>>代码示例>>PHP>>正文


PHP Cache::getNamespace方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:QBNK,项目名称:qbank3api-phpwrapper,代码行数:47,代码来源:QBankApi.php


注:本文中的Doctrine\Common\Cache\Cache::getNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。