Skip to content

Commit c2caf62

Browse files
committed
added php-doc comments
1 parent 020397d commit c2caf62

5 files changed

Lines changed: 62 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ tests/_support/_generated
3131

3232
# any root PHP files
3333
/*.php
34-
/examples/attachments/
34+
/examples/attachments/*
35+
!examples/attachments/.gitkeep

examples/attachments/.gitkeep

Whitespace-only changes.

examples/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'file' => [
2626
'fields' => ['cv_file', 'image_file'],
2727
'allowType' => ['jpeg', 'jpg', 'pdf', 'png'],
28-
'allowSize' => 10000
28+
'allowSize' => 10000000 //10 MB
2929
]
3030
], // acoording to Valitron doc.
3131
'labels' => [

src/DataObjects/File.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,50 @@
55

66
class File extends DataObject
77
{
8+
/**
9+
* @var string
10+
*/
811
public $name;
912

13+
/**
14+
* @var string
15+
*/
1016
public $type;
1117

18+
/**
19+
* @var string
20+
*/
1221
public $tmp_name;
1322

23+
/**
24+
* @var int
25+
*/
1426
public $error;
1527

28+
/**
29+
* @var int
30+
*/
1631
public $size;
1732

33+
/**
34+
* @var string
35+
*/
1836
public $uniqName;
1937

38+
/**
39+
* File constructor.
40+
* @param array $config
41+
*/
2042
public function __construct(array $config)
2143
{
2244
parent::__construct($config);
2345

2446
$this->uniqName = sha1(uniqid(mt_rand(), true)) . '.' . $this->getExtension();
2547
}
2648

49+
/**
50+
* @return mixed
51+
*/
2752
public function getExtension()
2853
{
2954
return pathinfo($this->name, PATHINFO_EXTENSION);

src/DataObjects/MailMessage.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class MailMessage extends DataObject
66
{
7-
const ATTACHMENTS_SIZE_LIMIT = 10;
7+
const ATTACHMENTS_SIZE_LIMIT = 8000000;
88

99
/**
1010
* @var EmailAddress
@@ -186,52 +186,83 @@ public function getAltBody()
186186

187187
public function setFiles()
188188
{
189+
$uploadFolder = $this->getFullPathOfUploadFolder();
190+
191+
if (!file_exists($uploadFolder)) {
192+
mkdir($uploadFolder, 0777, true);
193+
}
194+
189195
foreach ($this->attachments as $file)
190196
{
191-
$path = $this->getFullPathOfUploadFolder() . DIRECTORY_SEPARATOR . $file->name;
192197
/** @var File $file */
198+
$path = $this->getFullPathOfUploadFolder() . DIRECTORY_SEPARATOR . $file->uniqName;
199+
@chmod($path, 0666 & ~umask());
200+
193201
if (move_uploaded_file($file->tmp_name, $path)) {
194202

195203
if ($file->size > self::ATTACHMENTS_SIZE_LIMIT) {
196-
$domainPath = $_SERVER['HTTP_ORIGIN'] . $this->getWebUploadFolder() .DIRECTORY_SEPARATOR . $file->name;
204+
$domainPath = $_SERVER['HTTP_ORIGIN'] . $this->getWebUploadFolder() .DIRECTORY_SEPARATOR . $file->uniqName;
197205
$this->addFileLink([$domainPath => $file->name]);
198206
} else {
199207
$this->addFile([$path => $file->name]);
200208
}
201209
}
202210
}
211+
212+
return true;
203213
}
204214

215+
/**
216+
* @return array
217+
*/
205218
public function getFiles()
206219
{
207220
return $this->files;
208221
}
209222

223+
/**
224+
* @param $data
225+
*/
210226
protected function addFile($data)
211227
{
212228
$this->files[] = new EmailAttachment($data);
213229
}
214230

231+
/**
232+
* @param $data
233+
*/
215234
protected function addFileLink($data)
216235
{
217236
$this->fileLinks[] = new EmailAttachment($data);
218237
}
219238

239+
/**
240+
* @return array
241+
*/
220242
public function getFileLinks()
221243
{
222244
return $this->fileLinks;
223245
}
224246

247+
/**
248+
* @return string
249+
*/
225250
protected function getFullPathOfUploadFolder()
226251
{
227252
return __DIR__ . $this->getUploadFolder();
228253
}
229254

255+
/**
256+
* @return string
257+
*/
230258
protected function getUploadFolder()
231259
{
232260
return '/../../examples' . $this->getWebUploadFolder();
233261
}
234262

263+
/**
264+
* @return string
265+
*/
235266
protected function getWebUploadFolder()
236267
{
237268
return '/attachments';

0 commit comments

Comments
 (0)