コード例 #1
0
ファイル: CachedResult.php プロジェクト: jwdeitch/components
 /**
  * Flush results stored in CacheStore and CachedResult.
  */
 public function flush()
 {
     $this->data = [];
     $this->count = 0;
     $this->store->delete($this->key);
     $this->key = null;
 }
コード例 #2
0
ファイル: RackspaceServer.php プロジェクト: spiral/components
 /**
  * Connect to rackspace servers using new or cached token.
  *
  * @throws ServerException
  */
 protected function connect()
 {
     if (!empty($this->authToken)) {
         //Already got credentials from cache
         return;
     }
     //Credentials request
     $request = new Request('POST', $this->options['authServer'], ['Content-Type' => 'application/json'], json_encode(['auth' => ['RAX-KSKEY:apiKeyCredentials' => ['username' => $this->options['username'], 'apiKey' => $this->options['apiKey']]]]));
     try {
         /**
          * @var ResponseInterface $response
          */
         $response = $this->client->send($request);
     } catch (ClientException $exception) {
         if ($exception->getCode() == 401) {
             throw new ServerException("Unable to perform Rackspace authorization using given credentials.");
         }
         throw new ServerException($exception->getMessage(), $exception->getCode(), $exception);
     }
     $response = json_decode((string) $response->getBody(), 1);
     foreach ($response['access']['serviceCatalog'] as $location) {
         if ($location['name'] == 'cloudFiles') {
             foreach ($location['endpoints'] as $server) {
                 $this->regions[$server['region']] = $server['publicURL'];
             }
         }
     }
     if (!isset($response['access']['token']['id'])) {
         throw new ServerException("Unable to fetch rackspace auth token.");
     }
     $this->authToken = $response['access']['token']['id'];
     if ($this->options['cache']) {
         $this->store->set($this->options['username'] . '@rackspace-token', $this->authToken, $this->options['lifetime']);
         $this->store->set($this->options['username'] . '@rackspace-regions', $this->regions, $this->options['lifetime']);
     }
 }
コード例 #3
0
ファイル: CacheHandler.php プロジェクト: jwdeitch/components
 /**
  * {@inheritdoc}
  */
 public function write($session_id, $session_data)
 {
     return $this->cacheStore->set($this->options['prefix'] . $session_id, $session_data, $this->lifetime);
 }