/**
  * {@inheritDoc}
  */
 public function login(CredentialsInterface $credentials = null, $workspaceName = null)
 {
     $this->credentials = $credentials;
     $this->workspaceName = $workspaceName ?: 'default';
     if (!$this->checkLoginOnServer) {
         return $this->workspaceName;
     }
     $apiEndpoint = $this->getApiEndpointUri($this->workspaceName);
     $accessToken = $this->accessToken;
     if ($credentials instanceof SimpleCredentials && null !== $credentials->getUserID()) {
         // TODO oauth login
         $clientId = $credentials->getUserID();
         $clientSecret = $credentials->getPassword();
         //$accessToken = ..
     }
     try {
         // TODO inject a factory to create Prismic\Api instances
         $this->api = Api::get($apiEndpoint, $accessToken);
     } catch (RequestException $e) {
         throw new NoSuchWorkspaceException("Requested workspace: '{$this->workspaceName}'", null, $e);
     } catch (\RuntimeException $e) {
         throw new RepositoryException("Could not connect to endpoint: '{$apiEndpoint}'", null, $e);
     }
     $this->ref = $this->api->master()->getRef();
     $this->bookmarksByName = (array) $this->api->bookmarks();
     $this->bookmarksByUuid = array_flip($this->bookmarksByName);
     $this->loggedIn = true;
     return $this->workspaceName;
 }
Exemple #2
0
 /**
  * Returns either the master ref, or the defined ref
  *
  * @param Api $api
  *
  * @return string
  */
 private function getRef(Api $api)
 {
     if ($this->model->ref != null) {
         return $this->model->ref;
     }
     return $api->master()->getRef();
 }