1 | <?php |
||
21 | class TransformationHandler |
||
22 | { |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $requestTransformations = []; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $responseTransformations = []; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $schemaTransformations = []; |
||
37 | |||
38 | /** |
||
39 | * Applies all transformations defined for the given API and endpoint on a request. |
||
40 | * |
||
41 | * @param string $api The API name |
||
42 | * @param string $endpoint The endpoint |
||
43 | * @param Request $requestIn The original request object. |
||
44 | * @param Request $requestOut The request object to use for transformations |
||
45 | * @return Request The transformed request |
||
46 | */ |
||
47 | public function transformRequest($api, $endpoint, Request $requestIn, Request $requestOut) |
||
56 | |||
57 | /** |
||
58 | * Applies all transformations defined for the given API and endpoint on a response. |
||
59 | * |
||
60 | * @param string $api The API name |
||
61 | * @param string $endpoint The endpoint |
||
62 | * @param Response $responseIn The original response object |
||
63 | * @param Response $responseOut The response object to use for transformations |
||
64 | * @return Response The transformed response |
||
65 | */ |
||
66 | public function transformResponse($api, $endpoint, Response $responseIn, Response $responseOut) |
||
75 | |||
76 | /** |
||
77 | * Applies all transformations defined for the given API and endpoint on a schema. |
||
78 | * |
||
79 | * @param string $api The API name |
||
80 | * @param string $endpoint The endpoint |
||
81 | * @param \stdClass $schemaIn The original schema object |
||
82 | * @param \stdClass $schemaOut The schema object to use for transformations |
||
83 | * @return \stdClass The transformed schema |
||
84 | */ |
||
85 | public function transformSchema($api, $endpoint, \stdClass $schemaIn, \stdClass $schemaOut) |
||
94 | |||
95 | /** |
||
96 | * Returns the request transformations registered for a given API and endpoint. |
||
97 | * |
||
98 | * @param string $api The API name |
||
99 | * @param string $endpoint The endpoint |
||
100 | * @return array The transformations |
||
101 | */ |
||
102 | public function getRequestTransformations($api, $endpoint) |
||
107 | |||
108 | /** |
||
109 | * Returns the transformations registered for a given API and endpoint. |
||
110 | * |
||
111 | * @param string $api The API name |
||
112 | * @param string $endpoint The endpoint |
||
113 | * @return array The transformations |
||
114 | */ |
||
115 | public function getResponseTransformations($api, $endpoint) |
||
120 | |||
121 | /** |
||
122 | * Returns the transformations registered for a given API and endpoint. |
||
123 | * |
||
124 | * @param string $api The API name |
||
125 | * @param string $endpoint The endpoint |
||
126 | * @return array The transformations |
||
127 | */ |
||
128 | public function getSchemaTransformations($api, $endpoint) |
||
133 | |||
134 | /** |
||
135 | * Adds a transformation to a given API and endpoint. |
||
136 | * |
||
137 | * @param string $api The API name |
||
138 | * @param string $endpoint The API endpoint |
||
139 | * @param RequestTransformationInterface $transformation The transformation |
||
140 | * @return int The position of the added transformation within the transformation array. |
||
141 | */ |
||
142 | public function addRequestTransformation($api, $endpoint, RequestTransformationInterface $transformation) |
||
147 | |||
148 | /** |
||
149 | * Adds a response transformation to a given API and endpoint. |
||
150 | * |
||
151 | * @param string $api The API name |
||
152 | * @param string $endpoint The API endpoint |
||
153 | * @param ResponseTransformationInterface $transformation The transformation |
||
154 | * @return int The position of the added transformation within the transformation array. |
||
155 | */ |
||
156 | public function addResponseTransformation($api, $endpoint, ResponseTransformationInterface $transformation) |
||
161 | |||
162 | /** |
||
163 | * Adds a schema transformation to a given API and endpoint. |
||
164 | * |
||
165 | * @param string $api The API name |
||
166 | * @param string $endpoint The API endpoint |
||
167 | * @param SchemaTransformationInterface $transformation The transformation |
||
168 | * @return int The position of the added transformation within the transformation array. |
||
169 | */ |
||
170 | public function addSchemaTransformation($api, $endpoint, SchemaTransformationInterface $transformation) |
||
175 | } |
||
176 |