This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
PSR7 in upload form ->setData() #227
Copy link
Copy link
Closed
Description
- I was not able to find an open or closed issue matching what I'm seeing.
- This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
I'm trying latest zend-validator
2.11.0 and latest zend-inputfilter
2.9.0 which have psr7 support. I'm trying the following Form::setData()
and Form::isvalid()
. So, the following code:
// $request is an instance of \Psr\Http\Message\ServerRequestInterface
$postAndFileData = \array_merge_recursive(
$request->getParsedBody(),
$request->getUploadedFiles()
);
$form->setData($postAndFileData);
$form->isValid();
I got the following errors:
basename() expects parameter 1 to be string, object given
I have the following form specs:
use Zend\Filter\File\RenameUpload;
use Zend\Validator\File\MimeType;
use Zend\Validator\File\Size;
public function getInputFilterSpecification()
{
return [
[
'name' => 'filename',
'required' => true,
'filters' => [
[
'name' => RenameUpload::class,
'options' => [
'target' => \getcwd() . '/public/uploads',
'use_upload_extension' => true,
'use_upload_name' => true,
'overwrite' => true,
'randomize' => false,
],
],
],
'validators' => [
[
'name' => Size::class,
'options' => [
'max' => '10MB',
],
],
[
'name' => MimeType::class,
'options' => [
'mimeType' => [
'image/jpg',
'image/jpeg',
'image/png',
],
]
]
],
],
];
}
When I try remove the validators, the filters got errors:
No PSR-17 Psr\Http\Message\StreamFactoryInterface present; cannot filter file. Please pass the stream_file_factory option with a Psr\Http\Message\StreamFactoryInterface instance when creating the filter for use with PSR-7.
The current workaround is by using the zend-psr7bridge :
$zendRequest = Psr7ServerRequest::toZend($request);
$postAndFileData = \array_merge_recursive(
$zendRequest->getPost()->toArray(),
$zendRequest->getFiles()->toArray(),
);
alextech
Metadata
Metadata
Assignees
Labels
No labels