예제 #1
0
 /**
  * @param BlockCypherHttpConfig $httpConfig
  * @param string $request
  * @param mixed $options
  * @return mixed|void
  * @throws BlockCypherConfigurationException
  * @throws BlockCypherInvalidCredentialException
  * @throws BlockCypherMissingCredentialException
  */
 public function handle($httpConfig, $request, $options)
 {
     $credential = $this->apiContext->getCredential();
     $config = $this->apiContext->getConfig();
     if ($credential == null) {
         // Try picking credentials from the config file
         $credMgr = BlockCypherCredentialManager::getInstance($config);
         $credValues = $credMgr->getCredentialObject();
         if (!is_array($credValues)) {
             throw new BlockCypherMissingCredentialException("Empty or invalid credentials passed");
         }
         $credential = new SimpleTokenCredential($credValues['accessToken']);
     }
     if ($credential == null || !$credential instanceof SimpleTokenCredential) {
         throw new BlockCypherInvalidCredentialException("Invalid credentials passed");
     }
     $path = isset($options['path']) ? $options['path'] : '';
     $url = $this->getAbsoluteUrl($path, $this->apiContext);
     $httpConfig->setUrl($url);
     if (!array_key_exists("User-Agent", $httpConfig->getHeaders())) {
         $httpConfig->addHeader("User-Agent", BlockCypherUserAgent::getValue(BlockCypherConstants::SDK_NAME, BlockCypherConstants::SDK_VERSION));
     }
     /*if (!is_null($credential) && $credential instanceof SimpleTokenCredential && is_null($httpConfig->getHeader('Authorization'))) {
           $httpConfig->addHeader('Authorization', "Bearer " . $credential->getAccessToken($config), false);
       }*/
     if ($httpConfig->getMethod() == 'POST' || $httpConfig->getMethod() == 'PUT') {
         $httpConfig->addHeader('BlockCypher-Request-Id', $this->apiContext->getRequestId());
     }
     // Add any additional Headers that they may have provided
     $headers = $this->apiContext->getRequestHeaders();
     foreach ($headers as $key => $value) {
         $httpConfig->addHeader($key, $value);
     }
 }
예제 #2
0
 public static function SetUpForFunctionalTests(\PHPUnit_Framework_TestCase &$test)
 {
     $configs = array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => '../BlockCypher.log', 'log.LogLevel' => 'INFO', 'validation.level' => 'log');
     // Replace these values by entering your own token by visiting https://accounts.blockcypher.com/
     /** @noinspection SpellCheckingInspection */
     $token = 'c0afcccdde5081d6429de37d16166ead';
     /** @noinspection PhpUndefinedFieldInspection */
     $test->apiContext = new ApiContext(new SimpleTokenCredential($token));
     /** @noinspection PhpUndefinedFieldInspection */
     $test->apiContext->setConfig($configs);
     //BlockCypherConfigManager::getInstance()->addConfigFromIni(__DIR__. '/../../../sdk_config.ini');
     //BlockCypherConfigManager::getInstance()->addConfigs($configs);
     BlockCypherCredentialManager::getInstance()->setCredentialObject(BlockCypherCredentialManager::getInstance()->getCredentialObject('acct1'));
     self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
     if (self::$mode != 'sandbox') {
         // Mock BlockCypherRest Caller if mode set to mock
         /** @noinspection PhpUndefinedFieldInspection */
         $test->mockBlockCypherRestCall = $test->getMockBuilder('\\BlockCypher\\Transport\\BlockCypherRestCall')->disableOriginalConstructor()->getMock();
         /** @noinspection PhpUndefinedFieldInspection */
         $test->mockBlockCypherRestCall->expects($test->any())->method('execute')->will($test->returnValue($test->response));
     }
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = BlockCypherCredentialManager::getInstance($this->config);
 }
예제 #4
0
 /**
  * Get Credential
  *
  * @return \BlockCypher\Auth\SimpleTokenCredential
  */
 public function getCredential()
 {
     if ($this->credential == null) {
         return BlockCypherCredentialManager::getInstance()->getCredentialObject();
     }
     return $this->credential;
 }