/** * Deserialize the content passed as the request. * * Supported media types for the deserialization are: * - 'application/json' * - 'application/xml' * - 'text/xml' * - 'application/x-www-form-urlencoded' * - 'multipart/form-data' * - 'text/yaml' * - 'text/x-yaml' * - 'application/yaml' * - 'application/x-yaml' * * @return SerializableCollection the deserialized body * @throw RuntimeException the error preventing the deserialization */ public function getDeserializedBody() { if ($this->cachedDeserializedBody) { return $this->cachedDeserializedBody; } //get the media type that gives the serializator to be used $mediaType = $this->getMediaType(); //get the body or something invalid $body = $this->body ? (string) $this->getBody() : null; //get the serializer $serializer = null; //this is what will be deserialized $data = null; switch ($mediaType) { case 'application/json': $data = $body; $serializer = SerializableCollection::JSON; break; case 'application/xml': case 'text/xml': $serializer = SerializableCollection::XML; $data = $body; break; case 'text/yaml': case 'text/x-yaml': case 'application/yaml': case 'application/x-yaml': $serializer = SerializableCollection::YAML; $data = $body; break; case 'application/x-www-form-urlencoded': case 'multipart/form-data': $data = $this->getParsedBody(); break; default: $data = []; $serializer = null; } //return the serialization result try { return $this->cachedDeserializedBody = SerializableCollection::deserialize($data, $serializer); } catch (Gishiki\Algorithms\Collections\DeserializationException $ex) { throw new RuntimeException('The HTTP request is malformed'); } }
/** * Read the application configuration (settings.json) and return the * parsing result. * * @return array the application configuration */ public static function getApplicationSettings() { //get the json encoded application settings $config = file_get_contents(APPLICATION_DIR . 'settings.json'); //parse the settings file $appConfiguration = SerializableCollection::deserialize($config)->all(); //complete settings $appCompletedConfiguration = self::getValueFromEnvironment($appConfiguration); //return the application configuration return $appCompletedConfiguration; }