Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit ed4b9d7

Browse files
[wip] Implementing direct access to the response vpack
1 parent c0257ee commit ed4b9d7

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ extern "C" {
155155

156156
response.method<&arangodb::fuerte::php::Response::getHttpCode>("getHttpCode");
157157
response.method<&arangodb::fuerte::php::Response::getBody>("getBody");
158+
response.method<&arangodb::fuerte::php::Response::accessResponse>("accessResponse", {
159+
Php::ByVal("accessor", Php::Type::String)
160+
});
161+
response.method<&arangodb::fuerte::php::Response::accessResponseTop>("accessResponseTop", {
162+
Php::ByVal("accessor", Php::Type::String)
163+
});
158164

159165
extension->add(std::move(response));
160166
}

src/response.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,62 @@ namespace arangodb { namespace fuerte { namespace php {
3030
return body;
3131
}
3232

33+
Php::Value Response::accessResponse(Php::Parameters& params)
34+
{
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+
}
45+
46+
Php::Value Response::accessResponseTop(Php::Parameters& params)
47+
{
48+
std::string accessor = params[0];
49+
50+
vp::Slice slice = this->response.slices().front().get(accessor);
51+
return this->sliceToPhpValue(slice);
52+
}
53+
54+
Php::Value Response::sliceToPhpValue(const vp::Slice& slice)
55+
{
56+
switch(slice.type()) {
57+
case vp::ValueType::String:
58+
return slice.copyString();
59+
break;
60+
61+
case vp::ValueType::Int:
62+
case vp::ValueType::UInt:
63+
case vp::ValueType::SmallInt:
64+
return slice.getInt();
65+
break;
66+
67+
case vp::ValueType::Double:
68+
return slice.getDouble();
69+
break;
70+
71+
case vp::ValueType::Null:
72+
return NULL;
73+
break;
74+
75+
case vp::ValueType::Array:
76+
return -1;
77+
break;
78+
79+
case vp::ValueType::Object:
80+
return -1;
81+
break;
82+
83+
default:
84+
return -1;
85+
}
86+
}
87+
88+
3389
fu::Response* Response::getFuerteResponse()
3490
{
3591
return &this->response;

src/response.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
#include <phpcpp.h>
44

5+
#include <sstream>
6+
57
#include <fuerte/fuerte.h>
68
#include <fuerte/types.h>
79

810
#include "velocypack/vpack.h"
911
#include "velocypack/velocypack-exception-macros.h"
12+
#include "velocypack/ValueType.h"
1013

1114
#include "exception.h"
1215

@@ -20,12 +23,15 @@ namespace arangodb { namespace fuerte { namespace php {
2023
private:
2124
fu::Response response;
2225

26+
Php::Value sliceToPhpValue(const vp::Slice& slice);
27+
2328
public:
2429
Response(const fu::Response &response);
2530

2631
Php::Value getHttpCode();
27-
2832
Php::Value getBody();
33+
Php::Value accessResponse(Php::Parameters& params);
34+
Php::Value accessResponseTop(Php::Parameters& params);
2935

3036
fu::Response* getFuerteResponse();
3137
};

0 commit comments

Comments
 (0)