/** * Captures custom meta arguments * * @param array $args * @return void */ protected function __captureCustomMetaArgs(array &$args = array()) { foreach ($args as $key => $value) { if (preg_match('/^meta\\:/', $key)) { $data_string = str_replace('meta:', '', $key); if ($data_string) { $data = null; if (Utils::isJson($data_string)) { $data = $data_string ? json_decode($data_string, true) : null; } else { // check for comparator $params = explode(':', $data_string); $data = array('key' => isset($params[0]) ? $params[0] : '', 'compare' => isset($params[1]) && array_key_exists(strtolower($params[1]), static::$comparator_map) ? static::$comparator_map[$params[1]] : '='); } if (isset($data['key']) && $data['key']) { if (!$this->clean_args->hasKey('meta_query') && isset($args['meta_relation'])) { $relation = $args['meta_relation']; unset($args['meta_relation']); $this->clean_args->set('meta_query.relation', $relation); } if (!isset($data['compare']) || !$data['compare']) { $data['compare'] = '='; } if (!isset($data['type']) || !$data['type']) { $data['type'] = 'CHAR'; } // Search for a value type $params = explode(':', $value); if (count($params) == 2 && array_key_exists(strtolower($params[0]), static::$value_type_map)) { $data['type'] = $params[0]; $value = $params[1]; } $data['value'] = stripslashes($value); $this->clean_args->push($data, 'meta_query'); } } unset($args[$key]); } } }
/** * Does a pre-flight check * * @return void */ public function preFlightCheck() { $this->slim->hook('slim.before', function () { $request = $this->slim->request(); $method = $request->getMethod(); $resource_uri = $request->getResourceUri(); $content_type = $request->headers->get('CONTENT_TYPE'); $request_body = $request->getBody(); if (in_array($method, array('POST', 'PUT', 'PATCH'))) { if ($request_body) { // Throw error if content-type is not 'application/json' if (!$content_type || !preg_match('/application\\/json/', $content_type)) { throw new \UnexpectedValueException("You need to send the Content-type header with 'application/json' as its value", 1); } // Validate request body as JSON string if (!Utils::isJson($request_body)) { throw new BaseException("Request body must be a valid JSON string", 400); } // Get Raw body as $input $input = json_decode($request_body, true); // Check if using json_decode($request_body, true) returns array if (!is_array($input) && !is_object($input)) { throw new BaseException("Request body must be either a JSON object or array", 400); } } } }); return $this; }