PHP code example of graphcommons / graphcommons

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

    

graphcommons / graphcommons example snippets


// manual
hCommons\Autoload;

Autoload::register();

// Dumps all Request and Response stuff (usefull while dev stage). (@default)
bool $debug = false;

// Sets cURL options. (@default)
array $clientOptions = [
    'redir'          => true, // follow location
    'redirMax'       => 3,    // follow location max
    'timeout'        => 5,    // read timeout
    'timeoutConnect' => 3,    // connect timeout
];

use GraphCommons\Api;

$api = new Api('<Yor API Key>' ?bool $debug = false, ?array $clientOptions = []);

// GET /status
dump $api->status(); // => ?object

// GET /search
dump $api->search('<Search Query>' ?array $uriParams = []); // => array

use GraphCommons\Thing\Graph;

$graph = new Graph($api);

// HEAD /graphs/:id
dump $graph->check('<ID>'); // => bool

// GET /graphs/:id
dump $graph->get('<ID>'); // => ?object

// POST /graphs
dump $graph->create([
    'name'        => 'Test',
    'description' => '',
    'status'      => Graph::STATUS_DRAFT,
    'signals'     => [
        ['action'    => Graph::SIGNAL_CREATE_EDGE,
         'from_name' => 'Ahmet',
         'from_type' => 'Person',
         'to_name'   => 'Burak',
         'to_type'   => 'Person',
         'name'      => 'COLLABORATED',
         'weight'    => 2]
    ]
]); // => ?object

// PUT /graphs/:id
dump $graph->update('<ID>', [
    'name'        => 'Test',
    'description' => 'Test description.',
    'subtitle'    => 'Test subtitle.',
]); // => ?object

// PUT /graphs/:id/clear
dump $graph->clear('<ID>'); // => ?object

// PUT /graphs/:id/add
dump $graph->createSignal('<ID>', [
    ['action'    => Graph::SIGNAL_CREATE_EDGE,
     'from_name' => 'Ahmet',
     'from_type' => 'Person',
     'to_name'   => 'Fatih',
     'to_type'   => 'Person',
     'name'      => 'COLLABORATED',
     'weight'    => 2]
]); // => ?object

// GET /graphs/:id/types
dump $graph->getTypes('<ID>'); // => ?object

// GET /graphs/:id/edges
dump $graph->getEdges('<ID>', array $uriParams); // => ?object

// GET /graphs/:id/paths
dump $graph->getPaths('<ID>', array $uriParams); // => ?object

// GET /graphs/:id/collab_filter
dump $graph->getCollabFilter('<ID>', array $uriParams); // => ?object

// GET /graphs/search
dump $api->search('<Search Query>' ?array $uriParams = []); // => array

// DELETE /graphs/:id
dump $api->delete('<ID>'); // => ?object

use GraphCommons\Thing\Node;

$node = new Node($api);

// GET /nodes/:id
dump $node->get('<ID>'); // => ?object

// GET /nodes/search
dump $node->search('<Search Query>' ?array $uriParams = []); // => array

use GraphCommons\Thing\Hub;

$hub = new Hub($api);

// GET /hubs/:id
dump $hub->get('<ID>'); // => ?object

// GET /hubs/:id/types
dump $hub->getTypes('<ID>'); // => ?object

// GET /hubs/:id/paths
dump $hub->getPaths('<ID>', array $uriParams); // => ?object

// GET /hubs/:id/collab_filter
dump $hub->getCollabFilter('<ID>', array $uriParams); // => ?object

// GET /graphs/search (alias, with Hub ID)
dump $hub->searchGraphs('<ID>', '<Search Query>', ?array $uriParams = []); // => array

// GET /nodes/search (alias, with Hub ID)
dump $hub->searchNodes('<ID>', '<Search Query>', ?array $uriParams = []); // => array