Skip to content

Commit d2389b7

Browse files
committed
/ Redesigned the Notification class
/ Redesigned the NotificationCollection class + Added Classes for Notification attributes + Added support for PSR-3 list of logger interface levels + Created a class that extends Notification class, for each logger level: * Emergency * Critical * Alert * Error * Warning * Notice * Info * Debug + Created a Notification factory + Created a Notification Factory facade: Notif + Created a Presentable Interface for toString, toArray, toOutput, toJson methods + Created a Presentable Trait for basic implementations of toOutput and toJson methods
1 parent a76ac2a commit d2389b7

57 files changed

Lines changed: 3637 additions & 119 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
"require": {
1313
"php": ">=5.4.0",
14+
"psr/log": "1.*",
1415
"xqddd/exceptions": "0.*"
1516
},
1617
"require-dev": {

composer.lock

Lines changed: 47 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Alert.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Xqddd\Notifications;
3+
4+
/**
5+
* Alert class
6+
*
7+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
8+
* @package Xqddd\Notifications
9+
*/
10+
class Alert extends Notification
11+
{
12+
13+
/**
14+
* Alert constructor.
15+
*
16+
* @param Label $label
17+
* @param Message $message
18+
*/
19+
public function __construct(Label $label, Message $message)
20+
{
21+
$type = new Type(TypeList::ALERT);
22+
23+
parent::__construct($label, $message, $type);
24+
}
25+
}

src/Critical.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Xqddd\Notifications;
3+
4+
/**
5+
* Critical class
6+
*
7+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
8+
* @package Xqddd\Notifications
9+
*/
10+
class Critical extends Notification
11+
{
12+
13+
/**
14+
* Critical constructor.
15+
*
16+
* @param Label $label
17+
* @param Message $message
18+
*/
19+
public function __construct(Label $label, Message $message)
20+
{
21+
$type = new Type(TypeList::CRITICAL);
22+
23+
parent::__construct($label, $message, $type);
24+
}
25+
}

src/Debug.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Xqddd\Notifications;
3+
4+
/**
5+
* Debug class
6+
*
7+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
8+
* @package Xqddd\Notifications
9+
*/
10+
class Debug extends Notification
11+
{
12+
13+
/**
14+
* Debug constructor.
15+
*
16+
* @param Label $label
17+
* @param Message $message
18+
*/
19+
public function __construct(Label $label, Message $message)
20+
{
21+
$type = new Type(TypeList::DEBUG);
22+
23+
parent::__construct($label, $message, $type);
24+
}
25+
}

src/Emergency.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Xqddd\Notifications;
3+
4+
/**
5+
* Emergency class
6+
*
7+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
8+
* @package Xqddd\Notifications
9+
*/
10+
class Emergency extends Notification
11+
{
12+
13+
/**
14+
* Emergency constructor.
15+
*
16+
* @param Label $label
17+
* @param Message $message
18+
*/
19+
public function __construct(Label $label, Message $message)
20+
{
21+
$type = new Type(TypeList::EMERGENCY);
22+
23+
parent::__construct($label, $message, $type);
24+
}
25+
}

src/Error.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Xqddd\Notifications;
3+
4+
/**
5+
* Error class
6+
*
7+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
8+
* @package Xqddd\Notifications
9+
*/
10+
class Error extends Notification
11+
{
12+
13+
/**
14+
* Error constructor.
15+
*
16+
* @param Label $label
17+
* @param Message $message
18+
*/
19+
public function __construct(Label $label, Message $message)
20+
{
21+
$type = new Type(TypeList::ERROR);
22+
23+
parent::__construct($label, $message, $type);
24+
}
25+
}

src/Exceptions/Codes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ class Codes extends BaseCodes
1515
const INVALID_NOTIFICATION_LABEL = 102;
1616

1717
const INVALID_NOTIFICATION_MESSAGE = 202;
18+
19+
const NOTIFICATION_TYPE_DOMAIN = 301;
20+
21+
const INVALID_NOTIFICATION_TYPE = 302;
1822
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Xqddd\Notifications\Exceptions;
3+
4+
use Xqddd\Exceptions\InvalidArgumentException;
5+
6+
/**
7+
* Exception for invalid notification type
8+
*
9+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
10+
* @package Xqddd\Notifications\Exceptions
11+
*/
12+
class InvalidNotificationTypeException extends InvalidArgumentException
13+
{
14+
15+
/**
16+
* The exception message
17+
*
18+
* @var string
19+
*/
20+
protected $message = 'Invalid [%s] notification type: [%s] expected - [%s] given.';
21+
22+
/**
23+
* The exception code
24+
*
25+
* @var int
26+
*/
27+
protected $code = Codes::INVALID_NOTIFICATION_TYPE;
28+
29+
/**
30+
* The exception string code
31+
*
32+
* @var string
33+
*/
34+
protected $stringCode = 'INVALID_NOTIFICATION_TYPE';
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Xqddd\Notifications\Exceptions;
3+
4+
use Xqddd\Exceptions\DomainException;
5+
6+
/**
7+
* Exception for an inappropriate notification type
8+
*
9+
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
10+
* @package Xqddd\Notifications\Exceptions
11+
*/
12+
class NotificationTypeDomainException extends DomainException
13+
{
14+
15+
/**
16+
* The exception message
17+
*
18+
* @var string
19+
*/
20+
protected $message = 'The provided notification type [%s] does not exist or does not belong to the current domain [%s].';
21+
22+
/**
23+
* The exception code
24+
*
25+
* @var int
26+
*/
27+
protected $code = Codes::NOTIFICATION_TYPE_DOMAIN;
28+
29+
/**
30+
* The exception string code
31+
*
32+
* @var string
33+
*/
34+
protected $stringCode = 'NOTIFICATION_TYPE_DOMAIN';
35+
}

0 commit comments

Comments
 (0)