@@ -45,10 +45,10 @@ class PropertyContainer
45
45
46
46
public function __set ($ k , $ v )
47
47
{
48
- // because neo cant handle NULLs
49
- if ( $ v === NULL ) $ v = '' ;
50
-
51
- $ this ->_data [$ k ] = $ v ;
48
+ if ( $ v === NULL && isset ( $ this -> _data [ $ k ]))
49
+ unset( $ this -> _data [ $ k ]) ;
50
+ else
51
+ $ this ->_data [$ k ] = $ v ;
52
52
}
53
53
54
54
public function __get ($ k )
@@ -87,16 +87,23 @@ public function delete()
87
87
if (!$ this ->_is_new )
88
88
{
89
89
list ($ response , $ http_code ) = HTTPUtil::deleteRequest ($ this ->getUri ());
90
+
91
+ if ($ http_code !=204 ) throw new HttpException ($ http_code );
92
+
90
93
$ this ->_id = NULL ;
91
94
$ this ->_id_new = TRUE ;
92
95
}
93
96
}
94
97
95
98
public function save ()
96
99
{
97
- list ($ response , $ http_code ) = HTTPUtil::jsonPostRequest ($ this ->getUri (), $ this ->_data );
98
-
99
- if ($ http_code !=201 ) throw new HttpException ($ http_code );
100
+ if ($ this ->_is_new ) {
101
+ list ($ response , $ http_code ) = HTTPUtil::jsonPostRequest ($ this ->getUri (), $ this ->_data );
102
+ if ($ http_code !=201 ) throw new HttpException ($ http_code );
103
+ } else {
104
+ list ($ response , $ http_code ) = HTTPUtil::jsonPutRequest ($ this ->getUri ().'/properties ' , $ this ->_data );
105
+ if ($ http_code !=204 ) throw new HttpException ($ http_code );
106
+ }
100
107
101
108
if ($ this ->_is_new )
102
109
{
@@ -235,16 +242,21 @@ public function getOtherNode($node)
235
242
236
243
public function save ()
237
244
{
238
- $ payload = array (
245
+ if ($ this ->_is_new ) {
246
+ $ payload = array (
239
247
'to ' => $ this ->getEndNode ()->getUri (),
240
248
'type ' => $ this ->_type ,
241
249
'data ' =>$ this ->_data
242
250
);
243
-
244
- list ($ response , $ http_code ) = HTTPUtil::jsonPostRequest ($ this ->getUri (), $ payload );
245
-
246
- if ($ http_code !=201 ) throw new HttpException ($ http_code );
247
-
251
+
252
+ list ($ response , $ http_code ) = HTTPUtil::jsonPostRequest ($ this ->getUri (), $ payload );
253
+
254
+ if ($ http_code !=201 ) throw new HttpException ($ http_code );
255
+ } else {
256
+ list ($ response , $ http_code ) = HTTPUtil::jsonPutRequest ($ this ->getUri ().'/properties ' , $ this ->_data );
257
+ if ($ http_code !=204 ) throw new HttpException ($ http_code );
258
+ }
259
+
248
260
if ($ this ->_is_new )
249
261
{
250
262
$ this ->_id = end (explode ("/ " , $ response ['self ' ]));
@@ -257,16 +269,22 @@ public function delete()
257
269
if (!$ this ->_is_new )
258
270
{
259
271
list ($ response , $ http_code ) = HTTPUtil::deleteRequest ($ this ->getUri ());
272
+
273
+ if ($ http_code !=204 ) throw new HttpException ($ http_code );
274
+
260
275
$ this ->_id = NULL ;
261
276
$ this ->_id_new = TRUE ;
262
277
}
263
278
}
264
279
265
280
public function getUri ()
266
281
{
267
- $ uri = $ this ->getStartNode ()->getUri ().'/relationships ' ;
282
+ if ($ this ->_is_new )
283
+ $ uri = $ this ->getStartNode ()->getUri ().'/relationships ' ;
284
+ else
285
+ $ uri = $ this ->_neo_db ->getBaseUri ().'relationship/ ' .$ this ->getId ();
268
286
269
- if (!$ this ->_is_new ) $ uri .= '/ ' .$ this ->getId ();
287
+ // if (!$this->_is_new) $uri .= '/'.$this->getId();
270
288
271
289
return $ uri ;
272
290
}
@@ -314,30 +332,35 @@ class HTTPUtil
314
332
function request ($ url , $ method ='GET ' , $ post_data ='' , $ content_type ='' , $ accept_type ='' )
315
333
{
316
334
// Uncomment for debugging
317
- //echo 'HTTP: ', $method, " : " ,$url , "\n";
335
+ //echo 'HTTP: ', $method, " : " ,$url , " : ", $post_data, " \n";
318
336
319
337
$ ch = curl_init ();
320
338
curl_setopt ($ ch , CURLOPT_URL , $ url );
321
339
curl_setopt ($ ch , CURLOPT_HEADER , 0 );
322
340
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , TRUE );
323
341
curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION ,1 );
342
+
343
+
344
+ //if ($method==self::POST){
345
+ // curl_setopt($ch, CURLOPT_POST, true);
346
+ //} else {
347
+ // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
348
+ //}
324
349
325
- if ($ method ==self ::POST ){
326
- curl_setopt ($ ch , CURLOPT_POST , true );
327
- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ post_data );
328
- } else {
329
- curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , $ method );
330
- }
331
-
350
+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , $ method );
351
+
332
352
if ($ post_data )
333
353
{
354
+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ post_data );
355
+
334
356
$ headers = array (
335
357
'Content-Length: ' . strlen ($ post_data ),
336
358
'Content-Type: ' .$ content_type ,
337
359
'Accept: ' .$ accept_type
338
360
);
339
361
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
340
362
}
363
+
341
364
$ response = curl_exec ($ ch );
342
365
343
366
$ http_code = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
@@ -358,6 +381,11 @@ function jsonRequest($url, $method, $data=NULL)
358
381
return $ ret ;
359
382
}
360
383
384
+ function jsonPutRequest ($ url , $ data )
385
+ {
386
+ return self ::jsonRequest ($ url , self ::PUT , $ data );
387
+ }
388
+
361
389
function jsonPostRequest ($ url , $ data )
362
390
{
363
391
return self ::jsonRequest ($ url , self ::POST , $ data );
0 commit comments