aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/core/src/Alert
diff options
context:
space:
mode:
authorMarvin Borner2018-06-08 20:03:25 +0200
committerMarvin Borner2018-06-08 20:03:25 +0200
commit92b7dd3335a6572debeacfb5faa82c63a5e67888 (patch)
tree7ebbca22595d542ec5e2912a24a0400ac8f6b113 /main/app/sprinkles/core/src/Alert
parent22a1bb27f94ea33042b0bdd35bef1a5cfa96cc0d (diff)
Some minor fixes
Diffstat (limited to 'main/app/sprinkles/core/src/Alert')
-rw-r--r--main/app/sprinkles/core/src/Alert/AlertStream.php276
-rw-r--r--main/app/sprinkles/core/src/Alert/CacheAlertStream.php162
-rw-r--r--main/app/sprinkles/core/src/Alert/SessionAlertStream.php134
3 files changed, 286 insertions, 286 deletions
diff --git a/main/app/sprinkles/core/src/Alert/AlertStream.php b/main/app/sprinkles/core/src/Alert/AlertStream.php
index adb9b5b..2db441f 100644
--- a/main/app/sprinkles/core/src/Alert/AlertStream.php
+++ b/main/app/sprinkles/core/src/Alert/AlertStream.php
@@ -1,138 +1,138 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Alert;
-
-use UserFrosting\Fortress\ServerSideValidator;
-
-/**
- * AlertStream Class
- *
- * Implements an alert stream for use between HTTP requests, with i18n support via the MessageTranslator class
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- * @see http://www.userfrosting.com/components/#messages
- */
-abstract class AlertStream
-{
-
- /**
- * @var string
- */
- protected $messagesKey;
-
- /**
- * @var UserFrosting\I18n\MessageTranslator|null
- */
- protected $messageTranslator = NULL;
-
- /**
- * Create a new message stream.
- */
- public function __construct($messagesKey, $translator = NULL) {
- $this->messagesKey = $messagesKey;
-
- $this->setTranslator($translator);
- }
-
- /**
- * Set the translator to be used for all message streams. Must be done before `addMessageTranslated` can be used.
- *
- * @param UserFrosting\I18n\MessageTranslator $translator A MessageTranslator to be used to translate messages when added via `addMessageTranslated`.
- */
- public function setTranslator($translator) {
- $this->messageTranslator = $translator;
- return $this;
- }
-
- /**
- * Adds a raw text message to the cache message stream.
- *
- * @param string $type The type of message, indicating how it will be styled when outputted. Should be set to "success", "danger", "warning", or "info".
- * @param string $message The message to be added to the message stream.
- * @return MessageStream this MessageStream object.
- */
- public function addMessage($type, $message) {
- $messages = $this->messages();
- $messages[] = array(
- "type" => $type,
- "message" => $message
- );
- $this->saveMessages($messages);
- return $this;
- }
-
- /**
- * Adds a text message to the cache message stream, translated into the currently selected language.
- *
- * @param string $type The type of message, indicating how it will be styled when outputted. Should be set to "success", "danger", "warning", or "info".
- * @param string $messageId The message id for the message to be added to the message stream.
- * @param array[string] $placeholders An optional hash of placeholder names => placeholder values to substitute into the translated message.
- * @return MessageStream this MessageStream object.
- */
- public function addMessageTranslated($type, $messageId, $placeholders = array()) {
- if (!$this->messageTranslator) {
- throw new \RuntimeException("No translator has been set! Please call MessageStream::setTranslator first.");
- }
-
- $message = $this->messageTranslator->translate($messageId, $placeholders);
- return $this->addMessage($type, $message);
- }
-
- /**
- * Get the messages and then clear the message stream.
- * This function does the same thing as `messages()`, except that it also clears all messages afterwards.
- * This is useful, because typically we don't want to view the same messages more than once.
- *
- * @return array An array of messages, each of which is itself an array containing "type" and "message" fields.
- */
- public function getAndClearMessages() {
- $messages = $this->messages();
- $this->resetMessageStream();
- return $messages;
- }
-
- /**
- * Add error messages from a ServerSideValidator object to the message stream.
- *
- * @param ServerSideValidator $validator
- */
- public function addValidationErrors(ServerSideValidator $validator) {
- foreach ($validator->errors() as $idx => $field) {
- foreach ($field as $eidx => $error) {
- $this->addMessage("danger", $error);
- }
- }
- }
-
- /**
- * Return the translator for this message stream.
- *
- * @return MessageTranslator The translator for this message stream.
- */
- public function translator() {
- return $this->messageTranslator;
- }
-
- /**
- * Get the messages from this message stream.
- *
- * @return array An array of messages, each of which is itself an array containing "type" and "message" fields.
- */
- abstract public function messages();
-
- /**
- * Clear all messages from this message stream.
- */
- abstract public function resetMessageStream();
-
- /**
- * Save messages to the stream
- */
- abstract protected function saveMessages($message);
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Alert;
+
+use UserFrosting\Fortress\ServerSideValidator;
+
+/**
+ * AlertStream Class
+ *
+ * Implements an alert stream for use between HTTP requests, with i18n support via the MessageTranslator class
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ * @see http://www.userfrosting.com/components/#messages
+ */
+abstract class AlertStream
+{
+
+ /**
+ * @var string
+ */
+ protected $messagesKey;
+
+ /**
+ * @var UserFrosting\I18n\MessageTranslator|null
+ */
+ protected $messageTranslator = NULL;
+
+ /**
+ * Create a new message stream.
+ */
+ public function __construct($messagesKey, $translator = NULL) {
+ $this->messagesKey = $messagesKey;
+
+ $this->setTranslator($translator);
+ }
+
+ /**
+ * Set the translator to be used for all message streams. Must be done before `addMessageTranslated` can be used.
+ *
+ * @param UserFrosting\I18n\MessageTranslator $translator A MessageTranslator to be used to translate messages when added via `addMessageTranslated`.
+ */
+ public function setTranslator($translator) {
+ $this->messageTranslator = $translator;
+ return $this;
+ }
+
+ /**
+ * Adds a raw text message to the cache message stream.
+ *
+ * @param string $type The type of message, indicating how it will be styled when outputted. Should be set to "success", "danger", "warning", or "info".
+ * @param string $message The message to be added to the message stream.
+ * @return MessageStream this MessageStream object.
+ */
+ public function addMessage($type, $message) {
+ $messages = $this->messages();
+ $messages[] = array(
+ "type" => $type,
+ "message" => $message
+ );
+ $this->saveMessages($messages);
+ return $this;
+ }
+
+ /**
+ * Adds a text message to the cache message stream, translated into the currently selected language.
+ *
+ * @param string $type The type of message, indicating how it will be styled when outputted. Should be set to "success", "danger", "warning", or "info".
+ * @param string $messageId The message id for the message to be added to the message stream.
+ * @param array[string] $placeholders An optional hash of placeholder names => placeholder values to substitute into the translated message.
+ * @return MessageStream this MessageStream object.
+ */
+ public function addMessageTranslated($type, $messageId, $placeholders = array()) {
+ if (!$this->messageTranslator) {
+ throw new \RuntimeException("No translator has been set! Please call MessageStream::setTranslator first.");
+ }
+
+ $message = $this->messageTranslator->translate($messageId, $placeholders);
+ return $this->addMessage($type, $message);
+ }
+
+ /**
+ * Get the messages and then clear the message stream.
+ * This function does the same thing as `messages()`, except that it also clears all messages afterwards.
+ * This is useful, because typically we don't want to view the same messages more than once.
+ *
+ * @return array An array of messages, each of which is itself an array containing "type" and "message" fields.
+ */
+ public function getAndClearMessages() {
+ $messages = $this->messages();
+ $this->resetMessageStream();
+ return $messages;
+ }
+
+ /**
+ * Add error messages from a ServerSideValidator object to the message stream.
+ *
+ * @param ServerSideValidator $validator
+ */
+ public function addValidationErrors(ServerSideValidator $validator) {
+ foreach ($validator->errors() as $idx => $field) {
+ foreach ($field as $eidx => $error) {
+ $this->addMessage("danger", $error);
+ }
+ }
+ }
+
+ /**
+ * Return the translator for this message stream.
+ *
+ * @return MessageTranslator The translator for this message stream.
+ */
+ public function translator() {
+ return $this->messageTranslator;
+ }
+
+ /**
+ * Get the messages from this message stream.
+ *
+ * @return array An array of messages, each of which is itself an array containing "type" and "message" fields.
+ */
+ abstract public function messages();
+
+ /**
+ * Clear all messages from this message stream.
+ */
+ abstract public function resetMessageStream();
+
+ /**
+ * Save messages to the stream
+ */
+ abstract protected function saveMessages($message);
+}
diff --git a/main/app/sprinkles/core/src/Alert/CacheAlertStream.php b/main/app/sprinkles/core/src/Alert/CacheAlertStream.php
index f3f6489..8d31462 100644
--- a/main/app/sprinkles/core/src/Alert/CacheAlertStream.php
+++ b/main/app/sprinkles/core/src/Alert/CacheAlertStream.php
@@ -1,81 +1,81 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Alert;
-
-use Illuminate\Cache\Repository as Cache;
-use UserFrosting\I18n\MessageTranslator;
-use UserFrosting\Support\Repository\Repository;
-
-/**
- * CacheAlertStream Class
- * Implements a message stream for use between HTTP requests, with i18n
- * support via the MessageTranslator class using the cache system to store
- * the alerts. Note that the tags are added each time instead of the
- * constructor since the session_id can change when the user logs in or out
- *
- * @author Louis Charette
- */
-class CacheAlertStream extends AlertStream
-{
- /**
- * @var Cache Object We use the cache object so that added messages will automatically appear in the cache.
- */
- protected $cache;
-
- /**
- * @var Repository Object We use the cache object so that added messages will automatically appear in the cache.
- */
- protected $config;
-
- /**
- * Create a new message stream.
- *
- * @param string $messagesKey Store the messages under this key
- * @param MessageTranslator|null $translator
- * @param Cache $cache
- * @param Repository $config
- */
- public function __construct($messagesKey, MessageTranslator $translator = NULL, Cache $cache, Repository $config) {
- $this->cache = $cache;
- $this->config = $config;
- parent::__construct($messagesKey, $translator);
- }
-
- /**
- * Get the messages from this message stream.
- *
- * @return array An array of messages, each of which is itself an array containing 'type' and 'message' fields.
- */
- public function messages() {
- if ($this->cache->tags('_s' . session_id())->has($this->messagesKey)) {
- return $this->cache->tags('_s' . session_id())->get($this->messagesKey) ?: [];
- } else {
- return [];
- }
- }
-
- /**
- * Clear all messages from this message stream.
- *
- * @return void
- */
- public function resetMessageStream() {
- $this->cache->tags('_s' . session_id())->forget($this->messagesKey);
- }
-
- /**
- * Save messages to the stream
- *
- * @param string $messages The message
- * @return void
- */
- protected function saveMessages($messages) {
- $this->cache->tags('_s' . session_id())->forever($this->messagesKey, $messages);
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Alert;
+
+use Illuminate\Cache\Repository as Cache;
+use UserFrosting\I18n\MessageTranslator;
+use UserFrosting\Support\Repository\Repository;
+
+/**
+ * CacheAlertStream Class
+ * Implements a message stream for use between HTTP requests, with i18n
+ * support via the MessageTranslator class using the cache system to store
+ * the alerts. Note that the tags are added each time instead of the
+ * constructor since the session_id can change when the user logs in or out
+ *
+ * @author Louis Charette
+ */
+class CacheAlertStream extends AlertStream
+{
+ /**
+ * @var Cache Object We use the cache object so that added messages will automatically appear in the cache.
+ */
+ protected $cache;
+
+ /**
+ * @var Repository Object We use the cache object so that added messages will automatically appear in the cache.
+ */
+ protected $config;
+
+ /**
+ * Create a new message stream.
+ *
+ * @param string $messagesKey Store the messages under this key
+ * @param MessageTranslator|null $translator
+ * @param Cache $cache
+ * @param Repository $config
+ */
+ public function __construct($messagesKey, MessageTranslator $translator = NULL, Cache $cache, Repository $config) {
+ $this->cache = $cache;
+ $this->config = $config;
+ parent::__construct($messagesKey, $translator);
+ }
+
+ /**
+ * Get the messages from this message stream.
+ *
+ * @return array An array of messages, each of which is itself an array containing 'type' and 'message' fields.
+ */
+ public function messages() {
+ if ($this->cache->tags('_s' . session_id())->has($this->messagesKey)) {
+ return $this->cache->tags('_s' . session_id())->get($this->messagesKey) ?: [];
+ } else {
+ return [];
+ }
+ }
+
+ /**
+ * Clear all messages from this message stream.
+ *
+ * @return void
+ */
+ public function resetMessageStream() {
+ $this->cache->tags('_s' . session_id())->forget($this->messagesKey);
+ }
+
+ /**
+ * Save messages to the stream
+ *
+ * @param string $messages The message
+ * @return void
+ */
+ protected function saveMessages($messages) {
+ $this->cache->tags('_s' . session_id())->forever($this->messagesKey, $messages);
+ }
+}
diff --git a/main/app/sprinkles/core/src/Alert/SessionAlertStream.php b/main/app/sprinkles/core/src/Alert/SessionAlertStream.php
index fec0973..47a7ff7 100644
--- a/main/app/sprinkles/core/src/Alert/SessionAlertStream.php
+++ b/main/app/sprinkles/core/src/Alert/SessionAlertStream.php
@@ -1,67 +1,67 @@
-<?php
-/**
- * UserFrosting (http://www.userfrosting.com)
- *
- * @link https://github.com/userfrosting/UserFrosting
- * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
- */
-
-namespace UserFrosting\Sprinkle\Core\Alert;
-
-use UserFrosting\I18n\MessageTranslator;
-use UserFrosting\Session\Session;
-
-/**
- * SessionAlertStream Class
- * Implements a message stream for use between HTTP requests, with i18n support via the MessageTranslator class
- * Using the session storage to store the alerts
- *
- * @author Alex Weissman (https://alexanderweissman.com)
- */
-class SessionAlertStream extends AlertStream
-{
- /**
- * @var Session We use the session object so that added messages will automatically appear in the session.
- */
- protected $session;
-
- /**
- * Create a new message stream.
- *
- * @param string $messagesKey Store the messages under this key
- * @param MessageTranslator|null $translator
- * @param Session $session
- */
- public function __construct($messagesKey, MessageTranslator $translator = NULL, Session $session) {
- $this->session = $session;
- parent::__construct($messagesKey, $translator);
- }
-
- /**
- * Get the messages from this message stream.
- *
- * @return array An array of messages, each of which is itself an array containing "type" and "message" fields.
- */
- public function messages() {
- return $this->session[$this->messagesKey] ?: [];
- }
-
- /**
- * Clear all messages from this message stream.
- *
- * @return void
- */
- public function resetMessageStream() {
- $this->session[$this->messagesKey] = [];
- }
-
- /**
- * Save messages to the stream
- *
- * @param string $messages The message
- * @return void
- */
- protected function saveMessages($messages) {
- $this->session[$this->messagesKey] = $messages;
- }
-}
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+
+namespace UserFrosting\Sprinkle\Core\Alert;
+
+use UserFrosting\I18n\MessageTranslator;
+use UserFrosting\Session\Session;
+
+/**
+ * SessionAlertStream Class
+ * Implements a message stream for use between HTTP requests, with i18n support via the MessageTranslator class
+ * Using the session storage to store the alerts
+ *
+ * @author Alex Weissman (https://alexanderweissman.com)
+ */
+class SessionAlertStream extends AlertStream
+{
+ /**
+ * @var Session We use the session object so that added messages will automatically appear in the session.
+ */
+ protected $session;
+
+ /**
+ * Create a new message stream.
+ *
+ * @param string $messagesKey Store the messages under this key
+ * @param MessageTranslator|null $translator
+ * @param Session $session
+ */
+ public function __construct($messagesKey, MessageTranslator $translator = NULL, Session $session) {
+ $this->session = $session;
+ parent::__construct($messagesKey, $translator);
+ }
+
+ /**
+ * Get the messages from this message stream.
+ *
+ * @return array An array of messages, each of which is itself an array containing "type" and "message" fields.
+ */
+ public function messages() {
+ return $this->session[$this->messagesKey] ?: [];
+ }
+
+ /**
+ * Clear all messages from this message stream.
+ *
+ * @return void
+ */
+ public function resetMessageStream() {
+ $this->session[$this->messagesKey] = [];
+ }
+
+ /**
+ * Save messages to the stream
+ *
+ * @param string $messages The message
+ * @return void
+ */
+ protected function saveMessages($messages) {
+ $this->session[$this->messagesKey] = $messages;
+ }
+}