|
1
|
|
|
<?php |
|
2
|
|
|
namespace rtens\domin\delivery\web\adapters\curir; |
|
3
|
|
|
|
|
4
|
|
|
use rtens\domin\delivery\ParameterReader; |
|
5
|
|
|
use rtens\domin\Parameter; |
|
6
|
|
|
use watoki\collections\Collection; |
|
7
|
|
|
use watoki\curir\delivery\WebRequest; |
|
8
|
|
|
use watoki\curir\protocol\UploadedFile; |
|
9
|
|
|
|
|
10
|
|
|
class CurirParameterReader implements ParameterReader { |
|
11
|
|
|
|
|
12
|
|
|
/** @var WebRequest */ |
|
13
|
|
|
private $request; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(WebRequest $request) { |
|
16
|
|
|
$this->request = $request; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* IMPORTANT: files must be properly merged into the parameters |
|
21
|
|
|
* |
|
22
|
|
|
* @param Parameter $parameter |
|
23
|
|
|
* @return mixed The serialized paramater |
|
24
|
|
|
*/ |
|
25
|
|
|
public function read(Parameter $parameter) { |
|
26
|
|
|
return $this->map($this->request->getArguments()->get($parameter->getName())); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param Parameter $parameter |
|
31
|
|
|
* @return boolean |
|
32
|
|
|
*/ |
|
33
|
|
|
public function has(Parameter $parameter) { |
|
34
|
|
|
return $this->request->getArguments()->has($parameter->getName()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function map($value) { |
|
38
|
|
|
if (is_array($value) || $value instanceof Collection) { |
|
39
|
|
|
$mapped = []; |
|
40
|
|
|
foreach ($value as $key => $item) { |
|
41
|
|
|
$mapped[$key] = $this->map($item); |
|
42
|
|
|
} |
|
43
|
|
|
return $mapped; |
|
44
|
|
|
} else if ($value instanceof UploadedFile) { |
|
|
|
|
|
|
45
|
|
|
return [ |
|
46
|
|
|
'name' => $value->getName(), |
|
47
|
|
|
'tmp_name' => $value->getTemporaryName(), |
|
48
|
|
|
'error' => $value->getError(), |
|
49
|
|
|
'size' => $value->getSize(), |
|
50
|
|
|
'type' => $value->getType() |
|
51
|
|
|
]; |
|
52
|
|
|
} else { |
|
53
|
|
|
return $value; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.