@ -17,9 +28,9 @@ class HttpRequest implements ArrayAccess {
/**
/**
* Creates a new HttpRequest instance, and ensures that the given request data validates the given schema.
* Creates a new HttpRequest instance, and ensures that the given request data validates the given schema.
* This is a simple function that only supports flat schemas (non-composed, the data must only be a k/v array pair.)
* This is a simple function that only supports flat schemas (non-composed, the data must only be a k/v array pair.)
* @param array $request the request's data
* @param array<string,mixed> $request the request's data
* @param array $fails a reference to a failure array, that will contain the reported validation failures.
* @param array<string,ValidationFail> $fails a reference to a failure array, that will contain the reported validation failures.
* @param array $schema the schema to satisfy. a schema is a simple array with a string key (which is the top-level field name), and a set of validators
* @param array<string,array<int,Validator>> $schema the schema to satisfy. a schema is a simple array with a string key (which is the top-level field name), and a set of validators
* @return HttpRequest|null the built HttpRequest instance, or null if a field is missing, or if any of the schema validator failed
* @return HttpRequest|null the built HttpRequest instance, or null if a field is missing, or if any of the schema validator failed
*/
*/
public static function from(array $request, array &$fails, array $schema): ?HttpRequest {
public static function from(array $request, array &$fails, array $schema): ?HttpRequest {
@ -43,14 +54,28 @@ class HttpRequest implements ArrayAccess {
return isset($this->data[$offset]);
return isset($this->data[$offset]);
}
}
/**
* @param $offset
* @return mixed
*/
public function offsetGet($offset) {
public function offsetGet($offset) {
return $this->data[$offset];
return $this->data[$offset];
}
}
/**
* @param $offset
* @param $value
* @return mixed
* @throws Exception
*/
public function offsetSet($offset, $value) {
public function offsetSet($offset, $value) {
throw new Exception("requests are immutable objects.");
throw new Exception("requests are immutable objects.");
}
}
/**
* @param $offset
* @throws Exception
*/
public function offsetUnset($offset) {
public function offsetUnset($offset) {
throw new Exception("requests are immutable objects.");
throw new Exception("requests are immutable objects.");