Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Type Casting #1

Merged
merged 3 commits into from over 2 years ago

2 participants

Thomas Parisot Al James
Thomas Parisot

Added some type casting to avoid mistakes in HTTP calls (like creating a relationship with node IDs instead of node objects)

Al James onewheelgood merged commit 62942e1 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Oct 25, 2011
Thomas Parisot oncletom Added type casting 64fc534
Thomas Parisot oncletom * added Gremlin Script method
* refactored plugin command in `performPluginCommand`
15bf04f
Thomas Parisot oncletom Fixed typo 531e231
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 18 additions and 10 deletions. Show diff stats Hide diff stats

  1. +18 10 php-neo-rest.php
28 php-neo-rest.php
@@ -37,10 +37,10 @@ public function getBaseUri()
37 37 {
38 38 return $this->base_uri;
39 39 }
40   -
41   - public function performCypherQuery($query, $inflate_nodes=true){
42   - $uri = $this->base_uri.'ext/CypherPlugin/graphdb/execute_query';
43   - $data = array('query'=>$query);
  40 +
  41 + public function performPluginCommand($plugin, $command, $data, $inflate_nodes = true)
  42 + {
  43 + $uri = $this->base_uri.'ext/'.$plugin.'Plugin/graphdb/'.$command;
44 44
45 45 list($response, $http_code) = HTTPUtil::jsonPostRequest($uri, $data);
46 46
@@ -66,6 +66,14 @@ public function performCypherQuery($query, $inflate_nodes=true){
66 66 throw new HttpException($http_code);
67 67 }
68 68 }
  69 +
  70 + public function performCypherQuery($query, $inflate_nodes=true){
  71 + return $this->performPluginCommand('Cypher', 'execute_query', array('query' => $query));
  72 + }
  73 +
  74 + public function performGremlinScript($script, $inflate_nodes=true){
  75 + return $this->performPluginCommand('Gremlin', 'execute_script', array('script' => $script));
  76 + }
69 77 }
70 78
71 79 class PropertyContainer
@@ -105,7 +113,7 @@ class Node extends PropertyContainer
105 113 var $_id;
106 114 var $_is_new;
107 115
108   - public function __construct($neo_db)
  116 + public function __construct(GraphDatabaseService $neo_db)
109 117 {
110 118 $this->_neo_db = $neo_db;
111 119 $this->_is_new = TRUE;
@@ -186,7 +194,7 @@ public function getRelationships($direction=Relationship::DIRECTION_BOTH, $types
186 194 return $relationships;
187 195 }
188 196
189   - public function createRelationshipTo($node, $type)
  197 + public function createRelationshipTo(Node $node, $type)
190 198 {
191 199 $relationship = new Relationship($this->_neo_db, $this, $node, $type);
192 200 return $relationship;
@@ -201,7 +209,7 @@ public function getUri()
201 209 return $uri;
202 210 }
203 211
204   - public static function inflateFromResponse($neo_db, $response)
  212 + public static function inflateFromResponse(GraphDatabaseService $neo_db, array $response)
205 213 {
206 214 $node = new Node($neo_db);
207 215 $node->_is_new = FALSE;
@@ -225,7 +233,7 @@ class Relationship extends PropertyContainer
225 233 var $_node1;
226 234 var $_node2;
227 235
228   - public function __construct($neo_db, $start_node, $end_node, $type)
  236 + public function __construct(GraphDatabaseService $neo_db, Node $start_node, Node $end_node, $type)
229 237 {
230 238 $this->_neo_db = $neo_db;
231 239 $this->_is_new = TRUE;
@@ -264,7 +272,7 @@ public function getEndNode()
264 272 return $this->_node2;
265 273 }
266 274
267   - public function getOtherNode($node)
  275 + public function getOtherNode(Node $node)
268 276 {
269 277 return ($this->_node1->getId()==$node->getId()) ? $this->getStartNode() : $this->getEndNode();
270 278 }
@@ -318,7 +326,7 @@ public function getUri()
318 326 return $uri;
319 327 }
320 328
321   - public static function inflateFromResponse($neo_db, $response)
  329 + public static function inflateFromResponse(GraphDatabaseService $neo_db, array $response)
322 330 {
323 331 $start_id = end(explode("/", $response['start']));
324 332 $end_id = end(explode("/", $response['end']));

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.