Skip to content

Commit c666a2e

Browse files
committed
added php doc
1 parent efdec2c commit c666a2e

15 files changed

Lines changed: 494 additions & 198 deletions

examples/form.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
'fields' => ['email'],
2323
'message' => '{field} is not a valid email address'
2424
],
25-
'file' => [
26-
'fields' => ['cv_file', 'image_file'],
27-
'allowType' => ['jpeg', 'jpg', 'pdf', 'png'],
28-
'allowSize' => 10000000 //10 MB
29-
]
30-
], // acoording to Valitron doc.
25+
'file' => [
26+
'fields' => ['cv_file', 'image_file'],
27+
'allowType' => ['jpeg', 'jpg', 'pdf', 'png'],
28+
'allowSize' => 10000000 // 10 MB
29+
]
30+
], // according to Valitron doc.
3131
'labels' => [
3232
'name' => 'Name',
3333
'email' => 'Email address'
34-
] // acoording to Valitron doc.
34+
] // according to Valitron doc.
3535
];
3636

3737
$mailerConfig = [
@@ -44,22 +44,21 @@
4444
];
4545

4646
$fileManager = new FileManager([
47-
'uploadPath' => __DIR__ . '/attachments',
48-
'uploadUrl' => $_SERVER['HTTP_ORIGIN'] . '/attachments',
49-
]
50-
);
47+
'uploadPath' => __DIR__ . '/attachments',
48+
'uploadUrl' => $_SERVER['HTTP_ORIGIN'] . '/attachments',
49+
]);
5150

5251
$message = [
53-
'from' => ['hello@justcoded.co.uk' => 'FROM NAME'],
54-
'to' => ['kostant21@yahoo.com' => 'TO NAME'],
52+
'from' => ['hello@justcoded.co.uk' => 'FROM NAME'],
53+
'to' => ['kostant21@yahoo.com' => 'TO NAME'],
5554
// 'cc' => ['email' => 'name'],
5655
// 'bcc' => ['email' => 'name'],
5756
'subject' => 'Contact request from {name}',
58-
'bodyTemplate' => __DIR__ . '/template-html.php',
57+
'bodyTemplate' => __DIR__ . '/template-html.php',
5958
'altBodyTemplate' => __DIR__ . '/template-plain.php',
60-
'attachments' => $fileManager->upload([
61-
'cv_file', 'image_file'
62-
])
59+
'attachments' => $fileManager->upload([
60+
'cv_file', 'image_file'
61+
])
6362
];
6463

6564

@@ -71,4 +70,3 @@
7170
}
7271

7372
echo json_encode($formHandler->response());
74-

src/DataObjects/DataObject.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
namespace JustCoded\FormHandler\DataObjects;
44

5+
/**
6+
* Class DataObject
7+
*
8+
* @package JustCoded\FormHandler\DataObjects
9+
*/
510
abstract class DataObject
611
{
12+
/**
13+
* DataObject constructor.
14+
*
15+
* @param array $config Abstrct array of user config
16+
*
17+
* @throws \Exception Exception.
18+
*/
719
public function __construct(array $config)
820
{
921
foreach ($config as $key => $value) {

src/DataObjects/EmailAddress.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
<?php
22
namespace JustCoded\FormHandler\DataObjects;
33

4+
/**
5+
* Class EmailAddress
6+
*
7+
* @package JustCoded\FormHandler\DataObjects
8+
*/
49
class EmailAddress
510
{
611
/**
12+
* Email
13+
*
714
* @var string
815
*/
916
protected $email;
1017

1118
/**
19+
* Name
20+
*
1221
* @var string
1322
*/
1423
protected $name;
1524

16-
public function __construct($data)
25+
/**
26+
* EmailAddress constructor.
27+
*
28+
* @param array $data Email data
29+
*
30+
* @throws \Exception Exception if data is blank.
31+
*/
32+
public function __construct(array $data)
1733
{
1834
if (empty($data)) {
1935
throw new \Exception('Email Address can\'t be blank');
@@ -37,6 +53,8 @@ public function __construct($data)
3753
}
3854

3955
/**
56+
* Getting Email
57+
*
4058
* @return string
4159
*/
4260
public function getEmail()
@@ -45,6 +63,8 @@ public function getEmail()
4563
}
4664

4765
/**
66+
* Getting Name
67+
*
4868
* @return string
4969
*/
5070
public function getName()
@@ -53,6 +73,8 @@ public function getName()
5373
}
5474

5575
/**
76+
* Getting formatted address
77+
*
5678
* @return string
5779
*/
5880
public function getFormattedAddress()

src/DataObjects/EmailAttachment.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@
44
class EmailAttachment
55
{
66
/**
7+
* Path of file attachments
8+
*
79
* @var string
810
*/
911
protected $path;
1012

1113
/**
14+
* Name of file attachments
15+
*
1216
* @var string
1317
*/
1418
protected $name;
1519

16-
public function __construct($data)
20+
/**
21+
* EmailAttachment constructor.
22+
*
23+
* @param array $data Email attachments data
24+
*
25+
* @throws \Exception Exception.
26+
*/
27+
public function __construct(array $data)
1728
{
1829
if (empty($data)) {
1930
throw new \Exception('Attachments can\'t be blank');
@@ -37,6 +48,8 @@ public function __construct($data)
3748
}
3849

3950
/**
51+
* Getting path of attachments
52+
*
4053
* @return string
4154
*/
4255
public function getPath()
@@ -45,6 +58,8 @@ public function getPath()
4558
}
4659

4760
/**
61+
* Getting name of attachments
62+
*
4863
* @return string
4964
*/
5065
public function getName()

src/DataObjects/File.php

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,98 @@
22

33
namespace JustCoded\FormHandler\DataObjects;
44

5-
5+
/**
6+
* Class File
7+
*
8+
* @package JustCoded\FormHandler\DataObjects
9+
*/
610
class File extends DataObject
711
{
8-
/**
9-
* @var string
10-
*/
11-
public $name;
12+
/**
13+
* File name
14+
*
15+
* @var string
16+
*/
17+
public $name;
1218

13-
/**
14-
* @var string
15-
*/
16-
public $type;
19+
/**
20+
* File type
21+
*
22+
* @var string
23+
*/
24+
public $type;
1725

18-
/**
19-
* @var string
20-
*/
21-
public $tmp_name;
26+
/**
27+
* Temporary directory
28+
*
29+
* @var string
30+
*/
31+
public $tmp_name;
2232

23-
/**
24-
* @var int
25-
*/
26-
public $error;
33+
/**
34+
* Error
35+
*
36+
* @var int
37+
*/
38+
public $error;
2739

28-
/**
29-
* @var int
30-
*/
31-
public $size;
40+
/**
41+
* File size
42+
*
43+
* @var int
44+
*/
45+
public $size;
3246

33-
/**
34-
* @var string
35-
*/
36-
public $uniqName;
47+
/**
48+
* Unique file name
49+
*
50+
* @var string
51+
*/
52+
public $uniqueName;
3753

38-
/**
39-
* @var string
40-
*/
41-
public $uploadUrl;
54+
/**
55+
* Url path of file
56+
*
57+
* @var string
58+
*/
59+
public $uploadUrl;
4260

43-
/**
44-
* @var string
45-
*/
46-
public $uploadPath;
61+
/**
62+
* Upload directory of file
63+
*
64+
* @var string
65+
*/
66+
public $uploadPath;
4767

48-
/**
49-
* File constructor.
50-
* @param array $config
51-
*/
52-
public function __construct(array $config)
53-
{
54-
parent::__construct($config);
68+
/**
69+
* File constructor.
70+
*
71+
* @param array $config Array of file data
72+
*/
73+
public function __construct(array $config)
74+
{
75+
parent::__construct($config);
5576

56-
$this->uniqName = sha1(uniqid(mt_rand(), true)) . '.' . $this->getExtension();
57-
}
77+
$this->uniqueName = sha1(uniqid(mt_rand(), true)) . '.' . $this->getExtension();
78+
}
5879

59-
/**
60-
* @return mixed
61-
*/
62-
public function getExtension()
63-
{
64-
return pathinfo($this->name, PATHINFO_EXTENSION);
65-
}
80+
/**
81+
* Getting file extension
82+
*
83+
* @return mixed
84+
*/
85+
public function getExtension()
86+
{
87+
return pathinfo($this->name, PATHINFO_EXTENSION);
88+
}
6689

67-
public function __toString()
68-
{
69-
return $this->uploadUrl;
70-
}
71-
}
90+
/**
91+
* Magic method for template converting
92+
*
93+
* @return string
94+
*/
95+
public function __toString()
96+
{
97+
return $this->uploadUrl;
98+
}
99+
}

0 commit comments

Comments
 (0)