1. Go to this page and download the library: Download acquia/content-hub-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/ */
acquia / content-hub-php example snippets
use Acquia\ContentHubClient\ContentHub;
// The URL to the Content Hub instance, provided by Acquia. Note that us-east-1
// might be replaced by a region that is within your geographic proximity.
$url = 'https://us-east-1.content-hub.acquia.com';
// The API key and secret key provided by Acquia that are used to authenticate
// requests to Content Hub.
$apiKey = 'AAAAAAAAAAAAAAAAAAAA';
$secretKey = 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB';
// For versions => 1.3, the api key is passed via the HMAC middleware.
$middleware = new MiddlewareHmacV1($apiKey, $secretKey, 'V1');
$client = new ContentHub('', $middleware, ['base_url' => $url]);
// For versions < 1.3, use the following client callback.
$client = new ContentHub($apiKey, $secretKey, '', ['base_url' => $url]);
// Register the application (or client site) with Content Hub. The parameter
// passed to this method is the human-readable name of the application.
$clientSite = $client->register('myclientsite');
// Stores the application's unique identifier that is assigned by Content Hub.
$clientId = $clientSite['uuid'];
// Add the endpoint that received webhooks posted from Content Hub.
$webhook = $client->addWebhook('http://example.com/content-hub/webhooks');
// Deleting the webhook receiver endpoint so that the application will no longer
// receive webhooks.
$client->deleteWebhook($webhook['uuid']);
use Acquia\ContentHubClient\ContentHub;
use Acquia\ContentHubClient\Middleware\MiddlewareHmacV1;
use Acquia\ContentHubClient\Entities;
use Acquia\ContentHubClient\Entity;
use Acquia\ContentHubClient\Attribute;
use Acquia\ContentHubClient\Asset;
$middleware = new MiddlewareHmacV1($apiKey, $secretKey, 'V1');
$client = new ContentHub($clientId, $middleware, ['base_url' => $url]);
// The unique identifier of the entity, usually a randomly generated UUID.
// See https://github.com/ramsey/uuid to simplify UUID generation in PHP.
$uuid = '00000000-0000-0000-0000-000000000000'
// Build the entity, add ibute = new Attribute(Attribute::TYPE_STRING);
$attribute->setValue('[asset-1]');
$entity->setAttribute('image', $attribute);
$asset = new Asset();
$asset->setUrl('http://placehold.it/100');
$asset->setReplaceToken('[asset-1]');
$entity->addAsset($asset);
// Create an entity container, add the entity to it.
$entities = new Entities();
$entities->addEntity($entity);
// Render the entities in Common Data Format (CDF). This should be the payload
// returned by requests to $resourceUrl (defined below).
$cdf = $entities->json();
// Queue the entity to be added to Content Hub. An important concept in Content
// Hub is that write operations are asynchronous, meaning that the actions are
// not performed right away. In this example, a URL is passed to Content Hub
// which is expected to render the entities that you want to add to the hub in
// CDF. Content Hub receives the request and immediately returns a 202 which
// signifies that the request was received. In the background, Content Hub then
// makes a request to the URL, reads the CDF, and adds the entities. Success and
// error messages are sent via webhooks, so it is important to implement a
// webhook receiver endpoint so that you know what is going on.
$resourceUrl = 'http://example.com/path/to/cdf';
$client->createEntities($resourceUrl);
// Get the entity from Content Hub.
$entity = $client->readEntity($uuid);
// Get the "name" attribute in English, then Spanish.
$name = $entity->getAttribute('name')->getValue('en');
$nombre = $entity->getAttribute('name')->getValue('es');
// Get the URL of the image attribute by dereferencing the token.
$token = $entity->getAttribute('image')->getValue();
$url = $entity->getAsset($token)->getUrl();
// Update the value of the "age" attribute from 4 to 5.
$attribute = new Attribute(Attribute::TYPE_INTEGER);
$attribute->setValue(5);
$entity->setAttribute('age', $attribute);
// Updating entities is also an asynchronous operation, so it may take a couple
// of seconds for the changes to be reflected in the hub.
$client->updateEntity($resourceUrl, $uuid);
// Delete the entity by passing it's UUID. Delete operations are asynchronous,
// so it may take a couple of seconds for entities to be purged from the hub.
$client->deleteEntity($uuid);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.