|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sirius\Upload\Result; |
|
4
|
|
|
|
|
5
|
|
|
use Sirius\Upload\Container\ContainerInterface; |
|
6
|
|
|
|
|
7
|
|
|
class File |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Array containing the details of the uploaded file: |
|
12
|
|
|
* - name (uploaded name) |
|
13
|
|
|
* - original name |
|
14
|
|
|
* - tmp_name |
|
15
|
|
|
* etc |
|
16
|
|
|
* |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $file; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The container to which this file belongs to |
|
23
|
|
|
* @var \Sirius\Upload\Container\ContainerInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $container; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param $file |
|
29
|
|
|
* @param ContainerInterface $container |
|
30
|
|
|
*/ |
|
31
|
11 |
|
public function __construct($file, ContainerInterface $container) |
|
32
|
|
|
{ |
|
33
|
11 |
|
$this->file = $file; |
|
34
|
11 |
|
$this->container = $container; |
|
35
|
11 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns if the uploaded file is valid |
|
39
|
|
|
* |
|
40
|
|
|
* @return bool |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function isValid() |
|
43
|
|
|
{ |
|
44
|
1 |
|
return $this->file['name'] && count($this->getMessages()) === 0; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns the validation error messages |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function getMessages() |
|
53
|
|
|
{ |
|
54
|
3 |
|
if (isset($this->file['messages'])) { |
|
55
|
2 |
|
return $this->file['messages']; |
|
56
|
|
|
} else { |
|
57
|
1 |
|
return array(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* The file that was saved during process() and has a .lock file attached |
|
63
|
|
|
* will be cleared, in case the form processing fails |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function clear() |
|
66
|
|
|
{ |
|
67
|
2 |
|
$this->container->delete($this->name); |
|
|
|
|
|
|
68
|
2 |
|
$this->container->delete($this->name . '.lock'); |
|
|
|
|
|
|
69
|
2 |
|
$this->file['name'] = null; |
|
70
|
2 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Remove the .lock file attached to the file that was saved during process() |
|
74
|
|
|
* This should happen if the form fails validation/processing |
|
75
|
|
|
*/ |
|
76
|
3 |
|
public function confirm() |
|
77
|
|
|
{ |
|
78
|
3 |
|
$this->container->delete($this->name . '.lock'); |
|
|
|
|
|
|
79
|
3 |
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* File attribute getter |
|
83
|
|
|
* |
|
84
|
|
|
* @param $name |
|
85
|
|
|
* @return mixed |
|
86
|
|
|
*/ |
|
87
|
8 |
|
public function __get($name) |
|
88
|
|
|
{ |
|
89
|
8 |
|
if (isset($this->file[$name])) { |
|
90
|
7 |
|
return $this->file[$name]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
2 |
|
return null; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.