-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUploadValidatorWrapBehavior.php
More file actions
266 lines (246 loc) · 8.33 KB
/
UploadValidatorWrapBehavior.php
File metadata and controls
266 lines (246 loc) · 8.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/**
* UploadValidatorWrapBehavior
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
/**
* Class UploadValidatorWrapBehavior
*
* UploadBehaviorのバリデータだけをwrapしたビヘイビア
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class UploadValidatorWrapBehavior extends ModelBehavior {
/**
* SetUp Attachment behavior
*
* @param Model $model instance of model
* @param array $config array of configuration settings.
* @throws CakeException 先にOriginalKeyが登録されてないと例外
* @return void
*/
public function setup(Model $model, $config = array()) {
$this->UploadFile = ClassRegistry::init('Files.UploadFile');
}
/**
* Check that the file does not exceed the max
* file size specified by PHP
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @return bool Success
*/
public function isUnderPhpSizeLimit(Model $model, $check) {
return $this->UploadFile->isUnderPhpSizeLimit($check);
}
/**
* Check that the file does not exceed the max
* file size specified in the HTML Form
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @return bool Success
*/
public function isUnderFormSizeLimit(Model $model, $check) {
return $this->UploadFile->isUnderFormSizeLimit($check);
}
/**
* Check that the file was completely uploaded
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @return bool Success
*/
public function isCompletedUpload(Model $model, $check) {
return $this->UploadFile->isCompletedUpload($check);
}
/**
* Check that a file was uploaded
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @return bool Success
*/
public function isFileUpload(Model $model, $check) {
return $this->UploadFile->isFileUpload($check);
}
/**
* Check that either a file was uploaded,
* or the existing value in the database is not blank.
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @return bool Success
*/
public function isFileUploadOrHasExistingValue(Model $model, $check) {
return $this->UploadFile->isFileUploadOrHasExistingValue($check);
}
/**
* Check that the PHP temporary directory is missing
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function tempDirExists(Model $model, $check, $requireUpload = true) {
return $this->UploadFile->tempDirExists($check, $requireUpload);
}
/**
* Check that the file was successfully written to the server
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isSuccessfulWrite(Model $model, $check, $requireUpload = true) {
return $this->UploadFile->isSuccessfulWrite($check, $requireUpload);
}
/**
* Check that a PHP extension did not cause an error
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function noPhpExtensionErrors(Model $model, $check, $requireUpload = true) {
return $this->UploadFile->noPhpExtensionErrors($check, $requireUpload);
}
/**
* Check that the file is of a valid mimetype
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param array $mimetypes file mimetypes to allow
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isValidMimeType(Model $model, $check, $mimetypes = array(),
$requireUpload = true) {
return $this->UploadFile->isValidMimeType($check, $mimetypes, $requireUpload);
}
/**
* Check that the upload directory is writable
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isWritable(Model $model, $check, $requireUpload = true) {
return $this->UploadFile->isWritable($check, $requireUpload);
}
/**
* Check that the upload directory exists
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isValidDir(Model $model, $check, $requireUpload = true) {
return $this->UploadFile->isValidDir($check, $requireUpload);
}
/**
* Check that the file is below the maximum file upload size
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param int $size Maximum file size
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isBelowMaxSize(Model $model, $check, $size = null, $requireUpload = true) {
return $this->UploadFile->isBelowMaxSize($check, $size, $requireUpload);
}
/**
* Check that the file is above the minimum file upload size
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param int $size Minimum file size
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isAboveMinSize(Model $model, $check, $size = null, $requireUpload = true) {
return $this->UploadFile->isAboveMinSize($check, $size, $requireUpload);
}
/**
* Check that the file has a valid extension
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param array $extensions file extenstions to allow
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isValidExtension(Model $model, $check, $extensions = array(),
$requireUpload = true) {
return $this->UploadFile->isValidExtension($check, $extensions, $requireUpload);
}
/**
* Check that the file is above the minimum height requirement
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param int $height Height of Image
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isAboveMinHeight(Model $model, $check, $height = null, $requireUpload = true) {
return $this->UploadFile->isAboveMinHeight($check, $height, $requireUpload);
}
/**
* Check that the file is below the maximum height requirement
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param int $height Height of Image
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isBelowMaxHeight(Model $model, $check, $height = null, $requireUpload = true) {
return $this->UploadFile->isBelowMaxHeight($check, $height, $requireUpload);
}
/**
* Check that the file is above the minimum width requirement
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param int $width Width of Image
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isAboveMinWidth(Model $model, $check, $width = null, $requireUpload = true) {
return $this->UploadFile->isAboveMinWidth($check, $width, $requireUpload);
}
/**
* Check that the file is below the maximum width requirement
*
* @param Model $model Model instance
* @param mixed $check Value to check
* @param int $width Width of Image
* @param bool $requireUpload Whether or not to require a file upload
* @return bool Success
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function isBelowMaxWidth(Model $model, $check, $width = null, $requireUpload = true) {
return $this->UploadFile->isBelowMaxWidth($check, $width, $requireUpload);
}
}