/**
  * Return Prismic Session Container
  * @param  ServiceLocatorInterface $serviceLocator
  * @return PrismicContainer
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $container = new PrismicContainer('Prismic');
     $context = $serviceLocator->get('NetgluePrismic\\Context');
     $container->setContext($context);
     if ($container->hasAccessToken()) {
         $context->setPrivilegedAccess(true);
     }
     return $container;
 }
 /**
  * Return Prismic Api Client
  * @param  ServiceLocatorInterface $serviceLocator
  * @return Api
  * @throws \RuntimeException
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (!isset($config['prismic']['api'])) {
         throw new \RuntimeException('No configuration has been provided in order to retrieve a Prismic API Client');
     }
     $config = $config['prismic'];
     $httpClient = $cache = null;
     $url = $config['api'];
     $token = $configToken = isset($config['token']) ? $config['token'] : null;
     /**
      * Check the Session for a token and prefer that if it exists.
      * We cannot retrieve the Prismic Container from the service manager
      * because it depends on the Context, so we'd have a circular dependency
      */
     $session = new PrismicContainer('Prismic');
     if ($session->hasAccessToken()) {
         $token = $session->getAccessToken();
     }
     /**
      * See if a cache service name has been provided and wrap it in the facade
      * if required
      */
     if (!empty($config['cache'])) {
         $storage = $serviceLocator->get($config['cache']);
         if (!$storage instanceof CacheInterface) {
             $cache = new Facade($storage);
         } else {
             $cache = $storage;
         }
     }
     if (!empty($config['httpClient'])) {
         $httpClient = $serviceLocator->get($config['httpClient']);
     }
     /**
      * @see \Prismic\Api::get($apiUrl, $accesssToken, \Guzzle\Http\Client $client, \Prismic\Cache\CacheInterface $cache)
      */
     /**
      * Wrap api initialisation in a try/catch in case the temporary token we got from the session
      * has expired
      */
     try {
         $api = Api::get($url, $token, $httpClient, $cache);
     } catch (HttpAdapterException $e) {
         $api = Api::get($url, $configToken, $httpClient, $cache);
     }
     return $api;
 }
 public function testSetGetHasAccessToken()
 {
     $session = new PrismicContainer('Test');
     $this->assertFalse($session->hasAccessToken());
     $this->assertNull($session->getAccessToken());
     $session->setAccessToken('foo');
     $this->assertTrue($session->hasAccessToken());
     $this->assertSame('foo', $session->getAccessToken());
 }