diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-10-29 01:10:57 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-10-29 01:10:57 +0400 |
commit | 867da5056644d057fa74415af6b6059e188aa1c4 (patch) | |
tree | 54f2fce7b4904b62a8283ad4e3a0d8ea0154d58b /core/Notification | |
parent | c8112851f93809c8501146e0238de07682aa0756 (diff) |
refs #4179 code cleanup
Diffstat (limited to 'core/Notification')
-rw-r--r-- | core/Notification/Manager.php | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/core/Notification/Manager.php b/core/Notification/Manager.php index 686f1f7c18..27d4e090e5 100644 --- a/core/Notification/Manager.php +++ b/core/Notification/Manager.php @@ -35,8 +35,31 @@ class Manager { self::checkId($id); - $session = static::getSession(); - $session->notifications[$id] = $notification; + self::addNotification($id, $notification); + } + + /** + * Cancel a previously registered (or persistent) notification. + * @param $id + */ + public static function cancel($id) + { + self::checkId($id); + + self::removeNotification($id); + } + + /** + * Cancels all previously registered non-persist notification. Call this method after the notifications have been + * displayed to make sure all non-persistent notifications won't be displayed multiple times. + */ + public static function cancelAllNonPersistent() + { + foreach (static::getAllNotifications() as $id => $notification) { + if (Notification::TYPE_PERSISTENT != $notification->type) { + static::removeNotification($id); + } + } } /** @@ -59,18 +82,26 @@ class Manager } /** - * Cancels all previously registered non-persist notification. Call this method after the notifications have been - * displayed to make sure all non-persistent notifications won't be displayed multiple times. + * @param $id + * @throws \Exception In case id is empty or if id contains non word characters */ - public static function cancelAllNonPersistent() + private static function checkId($id) { - foreach (static::getAllNotifications() as $id => $notification) { - if (Notification::TYPE_PERSISTENT != $notification->type) { - static::cancel($id); - } + if (empty($id)) { + throw new \Exception('Notification ID is empty.'); + } + + if (!preg_match('/^(\w)*$/', $id)) { + throw new \Exception('Invalid Notification ID given. Only word characters (AlNum + underscore) allowed.'); } } + private static function addNotification($id, Notification $notification) + { + $session = static::getSession(); + $session->notifications[$id] = $notification; + } + private static function getAllNotifications() { $session = static::getSession(); @@ -78,14 +109,8 @@ class Manager return $session->notifications; } - /** - * Cancel a previously registered (or persistent) notification. - * @param $id - */ - public static function cancel($id) + private static function removeNotification($id) { - self::checkId($id); - $session = static::getSession(); if (array_key_exists($id, $session->notifications)) { unset($session->notifications[$id]); @@ -107,19 +132,4 @@ class Manager return static::$session; } - - /** - * @param $id - * @throws \Exception - */ - private static function checkId($id) - { - if (empty($id)) { - throw new \Exception('Notification ID is empty.'); - } - - if (!preg_match('/^(\w)*$/', $id)) { - throw new \Exception('Invalid Notification ID given. Only word characters (AlNum + underscore) allowed.'); - } - } }
\ No newline at end of file |