neoxygen / neo4j-neoclient

Simple PHP HttpClient for the Neo4j ReST API with Multi DB Support
MIT License
121 stars 138 forks source link

added getPathBetween method #5

Closed ikwattro closed 9 years ago

ikwattro commented 9 years ago

@Mulkave This adds the getPathBetween method :

Usage

$start = ['label' => 'Person', 'properties' => ['name' => 'Chris']];
$end = ['properties' => ['name' => 'Abel']];
$paths = $client->getPathBetween($start, $end);

// Specifying depth :

$client->getPathBetween($start, $end, 3);

// Specifying direction

$client->getPathBetween($start, $end, 2, 'IN');

Using the current Response Formatter, you can already have some insights about your path :

$response = $client->getPathBetween($start, $end);
$formatter = new ResponseFormatter();
$result = $response->format($response);
// Knowing the number of hops :
$hops = $result->getRelationshipsCount();

You can traverse all relationships and having informations about nodes attached to them :

foreach ($result->getRelationships() as $rel){
  $startNode = $rel->getStartNode();
  $endNode = $rel->getEndNode();
}

Should this fit your needs ?

Mulkave commented 9 years ago

awesome :+1: will give this a try tomorrow and let you know :smiley:

Mulkave commented 9 years ago

One thing that would be really helpful here if we could be able to add the label identifier as well. i.e.

$start = ['label' => 'User', 'id' => 123];
$end = ['label' => 'Phone', 'id' => 987];
$paths = $client->getPathBetween($start, $end);