Graph Commons is a collaborative 'network mapping' platform and a knowledge base of relationships. You can map relationships at scale and unfold the mystery about complex issues that impact you and your community.
See more about here.
- Set autoloader properly or use Composer.
- Use PHP >= 7.2 (or see others PHP < 7.2, PHP < 7.1, PHP < 7.0).
- Run each call in
try/catch
blocks. - On README,
dump
meansvar_dump()
, besides?
means optional for function arguments and nullable for function returns.
Notice: See Graph Commons's official documents here before using this library.
// manual
require '<Path to GraphCommons>/src/Autoload.php';
use GraphCommons\Autoload;
Autoload::register();
composer require graphcommons/graphcommons
// composer.json
{"require": {"graphcommons/graphcommons": "~3.0"}}
Configuration is optional but you can provide all these;
// 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
];
Notice: If any error, all (caller) methods below will throw GraphCommons\ClientException
due to using GraphCommons\Client::send()
method that makes call to Graph Commons API and throws exception when an error occurres through. So please, use try/catch
blocks while making your calls, not regarding this usage examples.
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