Class
RequestTransformer
Translate and transform from PSR7 requests into CakePHP requests.
This is an important step for maintaining backwards compatibility with existing CakePHP applications, which depend on the CakePHP request object.
There is no reverse transform as the 'application' cannot return a mutated request object.
Method Summary
-
convertFile() protected static
Convert a single file back into an array.
-
convertFiles() protected static
Convert a nested array of files to arrays.
-
getFiles() protected static
Extract the uploaded files out of the request object.
-
getParams() protected static
Extract the routing parameters out of the request object.
-
toCake() public static
Transform a PSR7 request into a CakePHP one.
Method Detail
convertFile() ¶ protected static
convertFile(Psr\Http\Message\UploadedFileInterface $file): array
Convert a single file back into an array.
Parameters
-
Psr\Http\Message\UploadedFileInterface
$file The file to convert.
Returns
array
convertFiles() ¶ protected static
convertFiles(array $data, array $files, string $path = ''): array
Convert a nested array of files to arrays.
Parameters
-
array
$data The data to add files to.
-
array
$files The file objects to convert.
-
string
$path optional The current array path.
Returns
array
getFiles() ¶ protected static
getFiles(Psr\Http\Message\ServerRequestInterface $request): array
Extract the uploaded files out of the request object.
CakePHP expects to get arrays of file information and not the parsed objects that PSR7 requests contain. Downsample the data here.
Parameters
-
Psr\Http\Message\ServerRequestInterface
$request The request to extract files from.
Returns
array
getParams() ¶ protected static
getParams(Psr\Http\Message\ServerRequestInterface $request): array
Extract the routing parameters out of the request object.
Parameters
-
Psr\Http\Message\ServerRequestInterface
$request The request to extract params from.
Returns
array
toCake() ¶ public static
toCake(Psr\Http\Message\ServerRequestInterface $request): Cake\Http\ServerRequest
Transform a PSR7 request into a CakePHP one.
Parameters
-
Psr\Http\Message\ServerRequestInterface
$request The PSR7 request.
Returns
Cake\Http\ServerRequest