PHP code example of socalnick / orchestrate-php-client

1. Go to this page and download the library: Download socalnick/orchestrate-php-client 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/ */

    

socalnick / orchestrate-php-client example snippets


use SocalNick\Orchestrate\Client;
$client = new Client('your-api-key');

use SocalNick\Orchestrate\Client;
$client = new Client('your-api-key', 'https://api.aws-eu-west-1.orchestrate.io/v0/');

use SocalNick\Orchestrate\KvPutOperation;
$kvPutOp = new KvPutOperation("first_collection", "first_key", json_encode(array("name" => "Nick")));
$kvObject = $client->execute($kvPutOp);
$ref = $kvObject->getRef(); // 741357981fd7b5cb

use SocalNick\Orchestrate\KvPutOperation;
$kvPutOp = new KvPutOperation("first_collection", "second_key", json_encode(array("name" => "Terry")), array('if-match' => '741357981fd7b5cb'));
$kvObject = $client->execute($kvPutOp);
$ref = $kvObject->getRef(); // 0d1f15ab524a5c5a

use SocalNick\Orchestrate\KvPutOperation;
$kvPutOp = new KvPutOperation("first_collection", "second_key", json_encode(array("name" => "Bill")), array('if-none-match' => '*'));
$kvObject = $client->execute($kvPutOp); // null

use SocalNick\Orchestrate\KvPostOperation;
$kvPostOp = new KvPostOperation("first_collection", json_encode(array("name" => "Nick")));
$kvObject = $client->execute($kvPostOp);
$ref = $kvObject->getRef(); // 741357981fd7b5cb
$key = $kvObject->getKey(); // 05fb279bc820dd05

use SocalNick\Orchestrate\KvPatchOperationsOperation;
$kvPatchOperationsOp = new KvPatchOperationsOperation('first_collection', 'third_key');
$kvPatchOperationsOp
  ->add('birth_place.city', 'New York')
  ->remove('birth_place.country')
  ->replace('birth_place.state', 'New York')
  ->copy('full_name', 'name')
  ->test('age', 28)
  ->inc('age', 1)
  ->inc('years_until_death', -1);
$result = $client->execute($kvPatchOperationsOp);

use SocalNick\Orchestrate\KvPatchMergeOperation;
$partial = [
  'birth_place' => [
    'city' => 'New York',
    'country' => null,
    'state' => 'New York',
  ],
  'first_name' => null,
  'deprecated_first_name' => 'John',
  'name' => 'John Foster',
  'age' => 29,
  'years_until_death' => 39,
];
$kvPatchMergeOp = new KvPatchMergeOperation('first_collection', 'third_key', json_encode($partial));
$result = self::$client->execute($kvPatchMergeOp);

use SocalNick\Orchestrate\KvFetchOperation;
$kvFetchOp = new KvFetchOperation("films", "the_godfather");
$kvObject = $client->execute($kvFetchOp);
$ref = $kvObject->getRef(); // 9c1bc18e60d93848

use SocalNick\Orchestrate\KvFetchOperation;
$kvFetchOp = new KvFetchOperation("first_collection", "second_key", "741357981fd7b5cb");
$kvObject = $client->execute($kvFetchOp);
$ref = $kvObject->getRef(); // 741357981fd7b5cb

use SocalNick\Orchestrate\KvDeleteOperation;
$kvDeleteOp = new KvDeleteOperation("first_collection", "first_key");
$result = $client->execute($kvDeleteOp); // true

use SocalNick\Orchestrate\KvDeleteOperation;
$kvDeleteOp = new KvDeleteOperation("first_collection", "first_key", true);
$result = $client->execute($kvDeleteOp); // true

use SocalNick\Orchestrate\KvListOperation;
$kvListOp = new KvListOperation("films");
$kvListObject = $client->execute($kvListOp);
$count = $kvListObject->count(); // 10
$link = $kvListObject->getLink(); // /v0/films?limit=10&afterKey=the_godfather_part_2

use SocalNick\Orchestrate\KvListOperation;
$kvListOp = new KvListOperation("films", 5, 'anchorman');
$kvListObject = $client->execute($kvListOp);
$count = $kvListObject->count(); // 5
$link = $kvListObject->getLink(); // /v0/films?limit=5&afterKey=pulp_fiction

use SocalNick\Orchestrate\KvListOperation;
$kvListOp = new KvListOperation("films", 5, null, 'anchorman');
$kvListObject = $client->execute($kvListOp);
$count = $kvListObject->count(); // 5
$link = $kvListObject->getLink(); // /v0/films?limit=5&afterKey=shawshank_redemption

use SocalNick\Orchestrate\CollectionDeleteOperation;
$cDeleteOp = new CollectionDeleteOperation("first_collection");
$result = $client->execute($cDeleteOp); // true

use SocalNick\Orchestrate\SearchOperation;
$searchOp = new SearchOperation("films");
$searchResult = $client->execute($searchOp);
$count = $searchResult->count(); // 10
$total = $searchResult->totalCount(); // 12

use SocalNick\Orchestrate\SearchOperation;
$searchOp = new SearchOperation("films", "Genre:*Crime*", 2, 2, 'value.Title:asc');
$searchResult = $client->execute($searchOp);
$count = $searchResult->count(); // 2
$total = $searchResult->totalCount(); // 8
$firstKey = $searchResult->getValue()['results'][0]['path']['key']; // lock_stock_and_two_smoking_barrels

use SocalNick\Orchestrate\SearchAggregateOperation;
$searchOp = new SearchAggregateOperation("films", 'value.imdbRating:stats');
$searchResult = $client->execute($searchOp);
$min = $searchResult->getValue()['aggregates'][0]['statistics']['min']; // 5.9
$max = $searchResult->getValue()['aggregates'][0]['statistics']['max']; // 9.3

use SocalNick\Orchestrate\EventPostOperation;
$evPostOp = new EventPostOperation("films", "pulp_fiction", "comment", json_encode(array("message" => "This is my favorite movie!")));
$evPostResult = $client->execute($evPostOp); // instance_of SocalNick\Orchestrate\EventUpsertResult

use SocalNick\Orchestrate\EventPostOperation;
$evPostOp = new EventPostOperation("films", "pulp_fiction", "comment", json_encode(array("message" => "This is my favorite movie!")), 1395029140000);
$evPostResult = $client->execute($evPostOp); // instance_of SocalNick\Orchestrate\EventUpsertResult

use SocalNick\Orchestrate\EventFetchOperation;
$evFetchOp = new EventFetchOperation("films", "pulp_fiction", "comment", $evPostResult->getTimestamp(), $evPostResult->getOrdinal());
$evObject = $client->execute($evFetchOp);
$message = $evObject->getValue()['value']['message']; // This is my favorite movie!

use SocalNick\Orchestrate\EventPutOperation;
$evPutOp = new EventPutOperation("films", "pulp_fiction", "comment", json_encode(array("message" => "This is still my favorite movie!")), $evPostResult->getTimestamp(), $evPostResult->getOrdinal());
$evPutResult = $client->execute($evPutOp); // instance_of SocalNick\Orchestrate\EventUpsertResult

use SocalNick\Orchestrate\EventPutOperation;
$evPutOp = new EventPutOperation("films", "pulp_fiction", "comment", json_encode(array("message" => "Seriously, this is still my favorite movie!")), $evPostResult->getTimestamp(), $evPostResult->getOrdinal(), $evPutResult->getRef());
$evPutResult = $client->execute($evPutOp); // instance_of SocalNick\Orchestrate\EventUpsertResult

use SocalNick\Orchestrate\EventDeleteOperation;
$evDeleteOp = new EventDeleteOperation("films", "pulp_fiction", "comment", $evPutResult->getTimestamp(), $evPutResult->getOrdinal(), true);
$result = $client->execute($evDeleteOp); // true

use SocalNick\Orchestrate\EventDeleteOperation;
$evDeleteOp = new EventDeleteOperation("films", "pulp_fiction", "comment", $evPutResult->getTimestamp(), $evPutResult->getOrdinal(), true, $evPutResult->getRef());
$result = $client->execute($evDeleteOp); // true

use SocalNick\Orchestrate\EventListOperation;
$evListOp = new EventListOperation("films", "pulp_fiction", "comment");
$evListObject = $client->execute($evListOp);
$evListObject->count(); // 10

use SocalNick\Orchestrate\EventListOperation;
$evListOp = new EventListOperation("films", "pulp_fiction", "comment", 20);
$evListObject = $client->execute($evListOp);
$evListObject->count(); // 20

use SocalNick\Orchestrate\EventListOperation;
$evListOp = new EventListOperation("films", "pulp_fiction", "comment", 20, $startEvent, $afterEvent, $beforeEvent, $endEvent);
$evListObject = $client->execute($evListOp);

use SocalNick\Orchestrate\GraphPutOperation;
$graphPutOp = new GraphPutOperation("films", "the_godfather", "sequel", "films", "the_godfather_part_2");
$result = $client->execute($graphPutOp); // true

$graphPutOp = new GraphPutOperation("films", "the_godfather_part_2", "sequel", "films", "the_godfather_part_3");
$result = $client->execute($graphPutOp); // true

use SocalNick\Orchestrate\GraphFetchOperation;
$graphFetchOp = new GraphFetchOperation("films", "the_godfather", "sequel/sequel");
$graphObject = $client->execute($graphFetchOp);
$count = $graphObject->count(); // 1

use SocalNick\Orchestrate\GraphFetchOperation;
$graphFetchOp = new GraphFetchOperation("directors", "francis_ford_coppola", "films_directed", 1, 1);
$graphObject = $client->execute($graphFetchOp);
$count = $graphObject->count(); // 1
$next = $graphObject->getNext(); // /v0/directors/francis_ford_coppola/relations/films_directed?limit=1&offset=2
$prev = $graphObject->getPrev(); // /v0/directors/francis_ford_coppola/relations/films_directed?limit=1&offset=0

use SocalNick\Orchestrate\GraphDeleteOperation;
$graphDeleteOp = new GraphDeleteOperation("films", "the_godfather", "sequel", "films", "the_godfather_part_2");
$result = $client->execute($graphDeleteOp); // true

$graphDeleteOp = new GraphDeleteOperation("films", "the_godfather_part_2", "sequel", "films", "the_godfather_part_3");
$result = $client->execute($graphDeleteOp); // true

use SocalNick\Orchestrate\GraphFetchOperation;
$graphFetchOp = new GraphFetchOperation("films", "the_godfather", "sequel");
$graphObject = $client->execute($graphFetchOp);
$count = $graphObject->count(); // 0

$graphFetchOp = new GraphFetchOperation("films", "the_godfather_part_2", "sequel");
$graphObject = $client->execute($graphFetchOp);
$count = $graphObject->count(); // 0

$ composer