set() public method

Takes and stores data for later retrieval. This data can be any php data, including arrays and object, except resources and objects which are unable to be serialized.
public set ( mixed $value ) : self
$value mixed bool
return self
Example #1
0
 function it_expands_a_url(Provider $provider, PoolInterface $pool, ItemInterface $item)
 {
     $item->isMiss()->willReturn(true);
     $item->set('http://any.url')->shouldBeCalled();
     $pool->getItem(md5('http://short.ly/1234'))->willReturn($item);
     $provider->expand('http://short.ly/1234')->willReturn('http://any.url');
     $this->expand('http://short.ly/1234')->shouldReturn('http://any.url');
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function signIn($duration = NULL)
 {
     // @todo Do we need to lock $this->tokenCache?
     $options['auth'] = array($this->getUsername(), $this->getPassword());
     $options['query'] = array('schema' => '1.0', 'form' => 'json');
     if (!empty($duration)) {
         // API expects this value in milliseconds, not seconds.
         $options['query']['_duration'] = $duration * 1000;
         $options['query']['_idleTimeout'] = $duration * 1000;
     }
     $time = time();
     $data = $this->getClient()->get('https://identity.auth.theplatform.com/idm/web/Authentication/signIn', $options);
     $token = $data['signInResponse']['token'];
     $lifetime = floor(min($data['signInResponse']['duration'], $data['signInResponse']['idleTimeout']) / 1000);
     $this->getLogger()->info('Fetched new mpx token {token} for user {username} that expires on {date}.', array('token' => $token, 'username' => $this->getUsername(), 'date' => date(DATE_ISO8601, $time + $lifetime)));
     // Save the token to the cache and return it.
     $this->tokenCache->set($token, $lifetime);
     return $token;
 }
Example #3
0
 private function assertDisabledStash(\Stash\Interfaces\ItemInterface $item)
 {
     $this->assertFalse($item->set('true'), 'storeData returns false for disabled cache');
     $this->assertNull($item->get(), 'getData returns null for disabled cache');
     $this->assertFalse($item->clear(), 'clear returns false for disabled cache');
     $this->assertTrue($item->isMiss(), 'isMiss returns true for disabled cache');
     $this->assertFalse($item->extend(), 'extend returns false for disabled cache');
     $this->assertTrue($item->lock(100), 'lock returns true for disabled cache');
 }
Example #4
0
 /**
  * @param ResponseInterface $response
  * @param ItemInterface     $item
  * @param array|null        $data
  *
  * @throws \RuntimeException
  *
  * @return array
  */
 protected function handleSuccessfulResponse(ResponseInterface $response, ItemInterface $item, $data)
 {
     switch ((int) $response->getStatusCode()) {
         case 200:
             $data = json_decode($response->getBody(), true);
             if ($response->hasHeader('Last-Modified') === true) {
                 $item->set(['modified' => $response->getHeader('Last-Modified'), 'json' => $data]);
             }
             return $data;
         case 304:
             return $data['json'];
         default:
             throw new \RuntimeException('No support added for HTTP Status Code ' . $response->getStatusCode());
     }
 }