/**
  * @return ApiContext
  */
 protected static function getApiContext()
 {
     // First try default ApiContext
     $apiContext = ApiContext::getDefault();
     if ($apiContext === null) {
         $apiContext = new ApiContext(self::$credential);
         return $apiContext;
     }
     return $apiContext;
 }
Example #2
0
 /**
  * @return ApiContext
  * @throws BlockCypherMissingCredentialException
  */
 public function getApiContext()
 {
     // First try private property
     if ($this->apiContext !== null) {
         return $this->apiContext;
     }
     // Second try default ApiContext
     $apiContext = ApiContext::getDefault();
     if ($apiContext !== null) {
         return $apiContext;
     }
     // Third create a new ApiContext using local credentials
     if ($this->credential !== null) {
         $apiContext = new ApiContext($this->credential);
         return $apiContext;
     }
     throw new BlockCypherMissingCredentialException("Missing ApiContext or Credentials.");
 }