Skip to content

Commit

Permalink
/ Redesigned the Notification class
Browse files Browse the repository at this point in the history
/ 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
  • Loading branch information
neneaX committed Jan 31, 2016
1 parent a76ac2a commit d2389b7
Show file tree
Hide file tree
Showing 57 changed files with 3,637 additions and 119 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"require": {
"php": ">=5.4.0",
"psr/log": "1.*",
"xqddd/exceptions": "0.*"
},
"require-dev": {
Expand Down
56 changes: 47 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/Alert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Xqddd\Notifications;

/**
* Alert class
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications
*/
class Alert extends Notification
{

/**
* Alert constructor.
*
* @param Label $label
* @param Message $message
*/
public function __construct(Label $label, Message $message)
{
$type = new Type(TypeList::ALERT);

parent::__construct($label, $message, $type);
}
}
25 changes: 25 additions & 0 deletions src/Critical.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Xqddd\Notifications;

/**
* Critical class
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications
*/
class Critical extends Notification
{

/**
* Critical constructor.
*
* @param Label $label
* @param Message $message
*/
public function __construct(Label $label, Message $message)
{
$type = new Type(TypeList::CRITICAL);

parent::__construct($label, $message, $type);
}
}
25 changes: 25 additions & 0 deletions src/Debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Xqddd\Notifications;

/**
* Debug class
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications
*/
class Debug extends Notification
{

/**
* Debug constructor.
*
* @param Label $label
* @param Message $message
*/
public function __construct(Label $label, Message $message)
{
$type = new Type(TypeList::DEBUG);

parent::__construct($label, $message, $type);
}
}
25 changes: 25 additions & 0 deletions src/Emergency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Xqddd\Notifications;

/**
* Emergency class
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications
*/
class Emergency extends Notification
{

/**
* Emergency constructor.
*
* @param Label $label
* @param Message $message
*/
public function __construct(Label $label, Message $message)
{
$type = new Type(TypeList::EMERGENCY);

parent::__construct($label, $message, $type);
}
}
25 changes: 25 additions & 0 deletions src/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Xqddd\Notifications;

/**
* Error class
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications
*/
class Error extends Notification
{

/**
* Error constructor.
*
* @param Label $label
* @param Message $message
*/
public function __construct(Label $label, Message $message)
{
$type = new Type(TypeList::ERROR);

parent::__construct($label, $message, $type);
}
}
4 changes: 4 additions & 0 deletions src/Exceptions/Codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ class Codes extends BaseCodes
const INVALID_NOTIFICATION_LABEL = 102;

const INVALID_NOTIFICATION_MESSAGE = 202;

const NOTIFICATION_TYPE_DOMAIN = 301;

const INVALID_NOTIFICATION_TYPE = 302;
}
35 changes: 35 additions & 0 deletions src/Exceptions/InvalidNotificationTypeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Xqddd\Notifications\Exceptions;

use Xqddd\Exceptions\InvalidArgumentException;

/**
* Exception for invalid notification type
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications\Exceptions
*/
class InvalidNotificationTypeException extends InvalidArgumentException
{

/**
* The exception message
*
* @var string
*/
protected $message = 'Invalid [%s] notification type: [%s] expected - [%s] given.';

/**
* The exception code
*
* @var int
*/
protected $code = Codes::INVALID_NOTIFICATION_TYPE;

/**
* The exception string code
*
* @var string
*/
protected $stringCode = 'INVALID_NOTIFICATION_TYPE';
}
35 changes: 35 additions & 0 deletions src/Exceptions/NotificationTypeDomainException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Xqddd\Notifications\Exceptions;

use Xqddd\Exceptions\DomainException;

/**
* Exception for an inappropriate notification type
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications\Exceptions
*/
class NotificationTypeDomainException extends DomainException
{

/**
* The exception message
*
* @var string
*/
protected $message = 'The provided notification type [%s] does not exist or does not belong to the current domain [%s].';

/**
* The exception code
*
* @var int
*/
protected $code = Codes::NOTIFICATION_TYPE_DOMAIN;

/**
* The exception string code
*
* @var string
*/
protected $stringCode = 'NOTIFICATION_TYPE_DOMAIN';
}
25 changes: 25 additions & 0 deletions src/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Xqddd\Notifications;

/**
* Info class
*
* @author Andrei Pirjoleanu <andreipirjoleanu@gmail.com>
* @package Xqddd\Notifications
*/
class Info extends Notification
{

/**
* Info constructor.
*
* @param Label $label
* @param Message $message
*/
public function __construct(Label $label, Message $message)
{
$type = new Type(TypeList::INFO);

parent::__construct($label, $message, $type);
}
}

0 comments on commit d2389b7

Please sign in to comment.