1 | <?php |
||
15 | class ScaleEngineRequestVisitor extends AbstractRequestVisitor |
||
16 | { |
||
17 | /** @type \SplObjectStorage Data object for persisting JSON data. */ |
||
18 | private $_storage; |
||
19 | |||
20 | /** @type string The API secret used to sign requests. */ |
||
21 | private $_apiSecret; |
||
22 | |||
23 | /** |
||
24 | * Create the visitor, initializing the SPL Object Storage. |
||
25 | * |
||
26 | * @param string $apiSecret The API secret used to sign requests. |
||
27 | */ |
||
28 | public function __construct($apiSecret) |
||
33 | |||
34 | /** |
||
35 | * Handle a single parameter for a command. |
||
36 | * |
||
37 | * Each command has it's own storage inside the SPL Object Storage. This |
||
38 | * adds the parameter/value to the storage for that command, after |
||
39 | * processing any filters, etc. for the parameter. |
||
40 | * |
||
41 | * @param CommandInterface $command The command the parameter is for. |
||
42 | * @param RequestInterface $request The HTTP request being prepared. |
||
43 | * Unused. |
||
44 | * @param Parameter $param The parameter definition being set. |
||
45 | * @param mixed $value The value the parameter is being set to. |
||
46 | * @return void |
||
47 | */ |
||
48 | public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) |
||
54 | |||
55 | /** |
||
56 | * Finalizes the data for a request and sets it in the response. |
||
57 | * |
||
58 | * ScaleEngine requires a signature of the request to be added to the |
||
59 | * request. The data is then JSON-encoded and shoved into a POST field |
||
60 | * named `json`. |
||
61 | * |
||
62 | * @param CommandInterface $command The command being sent. |
||
63 | * @param RequestInterface $request The HTTP request being prepared. Will |
||
64 | * be modified with the serialized data added as a POST field. |
||
65 | * @return void |
||
66 | */ |
||
67 | public function after(CommandInterface $command, RequestInterface $request) |
||
81 | |||
82 | /** |
||
83 | * Gets the signature of the data using ScaleEngine's algorithm. |
||
84 | * |
||
85 | * This is a potentially fragile method as it could break if `json_encode` |
||
86 | * changes. |
||
87 | * |
||
88 | * @param array $data The data from the request to sign. |
||
89 | * @return string The base64-encoded signature of the data. |
||
90 | */ |
||
91 | private function _getSignature(array $data) |
||
97 | } |
||
98 |