Skip to content

Commit f661a73

Browse files
committed
Add new messages
1 parent 841707c commit f661a73

File tree

6 files changed

+315
-16
lines changed

6 files changed

+315
-16
lines changed

src/Validation/AlertMessage.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Odan\Validation;
4+
5+
/**
6+
* StatusMessage.
7+
*
8+
* Represents a alert status (success, danger, warning, info) and a status message.
9+
*/
10+
class AlertMessage
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $status;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $message;
21+
22+
/**
23+
* Constructor.
24+
*
25+
* @param string $status Alert status
26+
* @param string $message The message
27+
*/
28+
public function __construct(string $status, string $message)
29+
{
30+
$this->status = $status;
31+
$this->message = $message;
32+
}
33+
34+
/**
35+
* Clone object.
36+
*
37+
* @param string $status Status code
38+
* @param string $message The message
39+
*
40+
* @return self
41+
*/
42+
public function with(string $status, string $message): self
43+
{
44+
return new self($status, $message);
45+
}
46+
47+
/**
48+
* Returns the message.
49+
*
50+
* @return string The message
51+
*/
52+
public function message(): string
53+
{
54+
return $this->message;
55+
}
56+
57+
/**
58+
* Returns the status code.
59+
*
60+
* @return string The status
61+
*/
62+
public function status(): string
63+
{
64+
return $this->status;
65+
}
66+
67+
/**
68+
* Convert to array.
69+
*
70+
* @return array Data
71+
*/
72+
public function toArray(): array
73+
{
74+
return [
75+
'status' => $this->status(),
76+
'message' => $this->message(),
77+
];
78+
}
79+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Odan\Validation;
4+
5+
/**
6+
* AlertStatus.
7+
*
8+
* Can be used in combination with AlertMessage.
9+
*/
10+
class AlertMessageStatus
11+
{
12+
// Bootstrap
13+
const PRIMARY = 'primary';
14+
15+
// Bootstrap
16+
const SECONDARY = 'secondary';
17+
18+
// Bootstrap
19+
const SUCCESS = 'success';
20+
21+
// Bootstrap
22+
const DANGER = 'danger';
23+
24+
// Bootstrap
25+
const LIGHT = 'light';
26+
27+
// Bootstrap
28+
const DARK = 'dark';
29+
30+
// RFC 5424
31+
const DEBUG = 'debug';
32+
33+
// RFC 5424 and Bootstrap
34+
const INFO = 'info';
35+
36+
const NOTICE = 'notice';
37+
38+
// RFC 5424 and Bootstrap
39+
const WARNING = 'warning';
40+
41+
// RFC 5424
42+
const ERROR = 'error';
43+
44+
// RFC 5424
45+
const CRITICAL = 'critical';
46+
47+
// RFC 5424
48+
const ALERT = 'alert';
49+
50+
// RFC 5424
51+
const EMERGENCY = 'emergency';
52+
}

src/Validation/StatusMessage.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Odan\Validation;
4+
5+
/**
6+
* StatusMessage.
7+
*
8+
* Represents a numeric status code and a status message.
9+
*/
10+
class StatusMessage
11+
{
12+
/**
13+
* @var int
14+
*/
15+
protected $status = 0;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $message;
21+
22+
/**
23+
* Constructor.
24+
*
25+
* @param int $status Status code
26+
* @param string $message The message
27+
*/
28+
public function __construct(int $status, string $message)
29+
{
30+
$this->status = $status;
31+
$this->message = $message;
32+
}
33+
34+
/**
35+
* Clone object.
36+
*
37+
* @param int $status Status code
38+
* @param string $message The message
39+
*
40+
* @return self
41+
*/
42+
public function with(int $status, string $message): self
43+
{
44+
return new self($status, $message);
45+
}
46+
47+
/**
48+
* Returns the message.
49+
*
50+
* @return string The message
51+
*/
52+
public function message(): string
53+
{
54+
return $this->message;
55+
}
56+
57+
/**
58+
* Returns the status code.
59+
*
60+
* @return int The status code
61+
*/
62+
public function status(): int
63+
{
64+
return $this->status;
65+
}
66+
67+
/**
68+
* Convert to array.
69+
*
70+
* @return array Data
71+
*/
72+
public function toArray(): array
73+
{
74+
return [
75+
'status' => $this->status(),
76+
'message' => $this->message(),
77+
];
78+
}
79+
}

src/Validation/SuccessMessage.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace Odan\Validation;
4+
5+
/**
6+
* SuccessMessage.
7+
*
8+
* Represents a boolean success status and a success message.
9+
*/
10+
class SuccessMessage
11+
{
12+
/**
13+
* @var bool
14+
*/
15+
protected $success = false;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $message = null;
21+
22+
/**
23+
* Constructor.
24+
*
25+
* @param bool $success Success
26+
* @param string $message Message
27+
*/
28+
public function __construct(bool $success, string $message)
29+
{
30+
$this->success = $success;
31+
$this->message = $message;
32+
}
33+
34+
/**
35+
* Get message.
36+
*
37+
* @param bool $success
38+
* @param string $message
39+
*
40+
* @return self
41+
*/
42+
public function with(bool $success, string $message): self
43+
{
44+
return new self($success, $message);
45+
}
46+
47+
/**
48+
* Returns the message.
49+
*
50+
* @return string
51+
*/
52+
public function message(): string
53+
{
54+
return $this->message;
55+
}
56+
57+
/**
58+
* Returns the success status.
59+
*
60+
* @return bool The success status
61+
*/
62+
public function success(): bool
63+
{
64+
return $this->success;
65+
}
66+
67+
/**
68+
* Returns the failed status.
69+
*
70+
* @return bool The failed status
71+
*/
72+
public function failed(): bool
73+
{
74+
return !$this->success;
75+
}
76+
77+
/**
78+
* Convert to array.
79+
*
80+
* @return array Data
81+
*/
82+
public function toArray(): array
83+
{
84+
return [
85+
'success' => $this->success(),
86+
'message' => $this->message(),
87+
];
88+
}
89+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace Odan\Validation;
44

55
/**
6-
* ValidationResult.
6+
* ValidationMessage.
77
*
88
* Represents a container for the results of a validation request.
99
*/
10-
class ValidationResult
10+
class ValidationMessage
1111
{
1212
/**
1313
* @var array

0 commit comments

Comments
 (0)