PHP code example of autoprotect-group / neo4j-common

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

    

autoprotect-group / neo4j-common example snippets



use GraphAware\Common\Graph\Label;

$label = new Label("User");
echo $label->getName(); // Returns (string) "User"

// or static construction

$label = Label::label("User");


use GraphAware\Common\Graph\Node;

$node = new Node(1, array("User", "Person"));
$node->getId(); // Returns (int) 1
$node->getLabels(); // Returns an array of \GraphAware\Common\Graph\Label objects

use GraphAware\Common\Graph\Relationship;

$rel = new Relationship(1, RelationshipType::withName("RELATES"), $node, $node2);
echo $rel->getType(); // Returns (string) "RELATES"
var_dump($rel->isType(RelationshipType::withName("RELATES"))); // Returns (bool) true


use GraphAware\Common\Graph\Direction;

$direction = new Direction(Direction::INCOMING);
echo $direction; // Returns (string) "INCOMING"

// Or static call construction

$direction = Direction::OUTGOING;
echo $direction; // Returns (string) "OUTGOING"

use GraphAware\Common\Graph\RelationshipType;

$relType = RelationshipType::withName("FOLLOWS");
echo $relType->getName(); // Returns (string) "FOLLOWS"
echo (string) $relType; // implements __toString method : Returns (string) "FOLLOWS"


use GraphAware\Common\Cypher\Statement;

$statement = Statement::create("MATCH (n) WHERE id(n) = {id} RETURN n", array("id" => 324));

echo $statement->getQuery(); // Returns (string) "MATCH (n) WHERE id(n) = {id} RETURN n"
echo count($statement->getParameters()); // Returns (int) 1


use GraphAware\Common\Cypher\Statement
    GraphAware\Common\Cypher\StatementCollection;

$collection = new StatementCollection();
$collection->add(Statement::create("MATCH (n) RETURN count(n)"));

print_r($collection->getStatements());
echo $collection->isEmpty();