PHP code example of context-dev / context-dev-php

1. Go to this page and download the library: Download context-dev/context-dev-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

context-dev / context-dev-php example snippets




use ContextDev\Client;

$client = new Client(apiKey: getenv('CONTEXT_DEV_API_KEY') ?: 'My API Key');

$brand = $client->brand->retrieve(domain: 'REPLACE_ME', type: 'by_domain');

var_dump($brand->brand);



use ContextDev\Core\Exceptions\APIConnectionException;
use ContextDev\Core\Exceptions\RateLimitException;
use ContextDev\Core\Exceptions\APIStatusException;

try {
  $brand = $client->brand->retrieve(domain: 'REPLACE_ME', type: 'by_domain');
} catch (APIConnectionException $e) {
  echo "The server could not be reached", PHP_EOL;
  var_dump($e->getPrevious());
} catch (RateLimitException $e) {
  echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
} catch (APIStatusException $e) {
  echo "Another non-200-range status code was received", PHP_EOL;
  echo $e->getMessage();
}



use ContextDev\Client;

// Configure the default for all requests:
$client = new Client(requestOptions: ['maxRetries' => 0]);

// Or, configure per-request:
$result = $client->brand->retrieve(
  domain: 'REPLACE_ME', type: 'by_domain', requestOptions: ['maxRetries' => 5]
);



$brand = $client->brand->retrieve(
  domain: 'REPLACE_ME',
  type: 'by_domain',
  requestOptions: [
    'extraQueryParams' => ['my_query_parameter' => 'value'],
    'extraBodyParams' => ['my_body_parameter' => 'value'],
    'extraHeaders' => ['my-header' => 'value'],
  ],
);



$response = $client->request(
  method: "post",
  path: '/undocumented/endpoint',
  query: ['dog' => 'woof'],
  headers: ['useful-header' => 'interesting-value'],
  body: ['hello' => 'world']
);