1
|
|
|
<?php |
2
|
|
|
namespace Sirius\Input\Element\Input; |
3
|
|
|
|
4
|
|
|
use Sirius\Input\Element\Input as BaseInput; |
5
|
|
|
use Sirius\Input\Traits\HasUploadTrait; |
6
|
|
|
use Sirius\Input\InputFilter; |
7
|
|
|
use Sirius\Upload\Handler; |
8
|
|
|
use Sirius\Input\Specs; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* File element |
12
|
|
|
*/ |
13
|
|
|
class File extends BaseInput |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
use HasUploadTrait; |
17
|
|
|
|
18
|
3 |
|
protected function getDefaultSpecs() |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
return array( |
22
|
3 |
|
Specs::WIDGET => 'file' |
23
|
3 |
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Attaches the upload handlers to the input object |
28
|
|
|
* |
29
|
|
|
* @param InputFilter $inputFilter |
30
|
|
|
*/ |
31
|
1 |
|
protected function prepareUploadHandlers(InputFilter $inputFilter) |
32
|
|
|
{ |
33
|
1 |
|
$uploadValidator = new \Sirius\Validation\ValueValidator( |
34
|
1 |
|
$inputFilter->getValidator()->getRuleFactory(), |
35
|
1 |
|
$inputFilter->getValidator()->getErroMessagePrototype(), |
36
|
1 |
|
$this->getLabel() |
37
|
1 |
|
); |
38
|
|
|
|
39
|
|
|
// create the upload handler |
40
|
1 |
|
$uploadHandler = new Handler( |
41
|
1 |
|
$this->getUploadContainer(), |
42
|
1 |
|
$this->getUploadOptions(), |
|
|
|
|
43
|
|
|
$uploadValidator |
44
|
1 |
|
); |
45
|
1 |
|
if (is_array($this->getUploadRules())) { |
46
|
1 |
|
foreach ($this->getUploadRules() as $rule) { |
47
|
1 |
|
if ( ! is_array($rule)) { |
48
|
1 |
|
$rule = array( $rule ); |
49
|
1 |
|
} |
50
|
1 |
|
$name = $rule[0]; |
51
|
1 |
|
$options = isset($rule[1]) ? $rule[1] : null; |
52
|
1 |
|
$message = isset($rule[2]) ? $rule[2] : null; |
53
|
1 |
|
$label = $this->getLabel(); |
54
|
1 |
|
$uploadHandler->addRule($name, $options, $message, $label); |
55
|
1 |
|
} |
56
|
1 |
|
} |
57
|
1 |
|
$inputFilter->setUploadHandler($inputFilter->getUploadPrefix() . $this->getName(), $uploadHandler); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.