@@ -30,25 +30,37 @@ namespace arangodb { namespace fuerte { namespace php {
3030 return body;
3131 }
3232
33- Php::Value Response::accessResponse (Php::Parameters& params)
33+ Php::Value Response::get (Php::Parameters& params)
3434 {
35- std::vector<std::string> accessor;
36- std::istringstream accessorStr (params[0 ]);
37-
38- for (std::string token; std::getline (accessorStr, token, ' .' ); ) {
39- accessor.push_back (std::move (token));
40- }
41-
42- vp::Slice slice = this ->response .slices ().front ().get (accessor);
43- return this ->sliceToPhpValue (slice);
44- }
35+ try {
4536
46- Php::Value Response::accessResponseTop (Php::Parameters& params)
47- {
48- std::string accessor = params[0 ];
37+ if (params[0 ].isString ()) {
38+ return this ->sliceToPhpValue (this ->response .slices ().front ().get (params[0 ].rawValue ()));
39+
40+ } else if (params[0 ].isArray ()) {
41+ vp::Slice tmpSlice (this ->response .slices ().front ());
42+
43+ for (auto const &value : params[0 ]) {
44+ if (value.second .isNumeric ()) {
45+ tmpSlice = vp::Slice (tmpSlice.at (value.second .numericValue ()));
46+ } else if (value.second .isString ()) {
47+ tmpSlice = vp::Slice (tmpSlice.get (value.second .rawValue ()));
48+ } else {
49+ ARANGODB_THROW (InvalidArgumentException (), " The accessor may only contain strings and integers in %s on line %d" );
50+ return NULL ;
51+ }
52+ }
53+
54+ return this ->sliceToPhpValue (tmpSlice);
55+ } else {
56+ ARANGODB_THROW (InvalidArgumentException (), " The accessor must be either of type array or of type string in %s on line %d" );
57+ return NULL ;
58+ }
4959
50- vp::Slice slice = this ->response .slices ().front ().get (accessor);
51- return this ->sliceToPhpValue (slice);
60+ } catch (vp::Exception e) {
61+ ARANGODB_THROW (RuntimeException (), e.what ());
62+ return NULL ;
63+ }
5264 }
5365
5466 Php::Value Response::sliceToPhpValue (const vp::Slice& slice)
@@ -73,11 +85,8 @@ namespace arangodb { namespace fuerte { namespace php {
7385 break ;
7486
7587 case vp::ValueType::Array:
76- return -1 ;
77- break ;
78-
7988 case vp::ValueType::Object:
80- return - 1 ;
89+ return this -> sliceToJson (slice) ;
8190 break ;
8291
8392 default :
@@ -86,6 +95,25 @@ namespace arangodb { namespace fuerte { namespace php {
8695 }
8796
8897
98+ Php::Value Response::sliceToJson (const vp::Slice& slice)
99+ {
100+ std::string json;
101+
102+ try {
103+ vp::Options dumperOptions;
104+
105+ vp::StringSink sink (&json);
106+ vp::Dumper dumper (&sink, &dumperOptions);
107+ dumper.dump (slice);
108+ } catch (vp::Exception const & e) {
109+ ARANGODB_THROW (InvalidArgumentException (), e.what ());
110+ return NULL ;
111+ }
112+
113+ return json;
114+ }
115+
116+
89117 fu::Response* Response::getFuerteResponse ()
90118 {
91119 return &this ->response ;
0 commit comments