Skip to content
This repository has been archived by the owner on Oct 24, 2020. It is now read-only.

Adding Configurations

Owen Voke edited this page Nov 12, 2017 · 7 revisions

BlockCypher-PHP-SDK allows you to configure the SDKs to your need. There are many configurations available. In this step, we will add more configurations to our first.php that we created when making the first call to BlockCypher using our SDK.

Instructions

First, make a copy of first.php and name it second.php. You could alternatively copy the completed file here: second.php

  1. Open second.php and locate the code that creates a new instance of $apiContext. ApiContext object is a context object that holds/relates to configurations that you want to pass to each request to BlockCypher SDK. Add the following code immediately after that.

    // Step 2.1 : Between Step 2 and Step 3
    $apiContext->setConfig(
          array(
            'mode' => 'sandbox',
            'log.LogEnabled' => true,
            'log.FileName' => 'BlockCypher.log',
            'log.LogLevel' => 'DEBUG'
          )
    );
  2. Save and run php -f second.php. This will execute the same code as we saw earlier, with similar output. So, what changed ? Go to your project directory, and you will notice a new file BlockCypher.log has been created. It should look something like this:

    [05-05-2015 04:58:31] BlockCypher\Core\BlockCypherHttpConnection: INFO	: Response Status 	: 201
    [05-05-2015 04:58:31] BlockCypher\Core\BlockCypherHttpConnection: DEBUG	: Response Headers	: HTTP/1.1 201 Created, Server: nginx/1.6.2, Date: Tue, 05 May 2015 15:58:33 GMT, Content-Type: application/json, Content-Length: 248, Connection: keep-alive, Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Origin: *, X-Ratelimit-Remaining: 59949, , 
    [05-05-2015 04:58:31] BlockCypher\Core\BlockCypherHttpConnection: DEBUG	: Response Data 	: {
      "id": "6772a455-41dd-41c6-8693-754b8b76fc0b",
      "token": "c0afcccdde5081d6429de37d16166ead",
      "url": "https://requestb.in/slmm49sl?uniqid=5548e8a08ce64",
      "callback_errors": 0,
      "event": "unconfirmed-tx",
      "filter": "event=unconfirmed-tx"
    }
    

Basically, what we did was told SDK to enable Logging, and write logs with FINE to BlockCypher.log. You can change those settings, and achieve desired result.

This is one of the configuration SDK provides. There are many other configurations that would be discussed later in the documentation.

NOTE
  • To reduce redundant code and minimize security risks, you could create a file bootstrap.php and move all your configuration settings there, and just include bootstrap.php.

Next Step