コード例 #1
0
 /**
  * Sets last message at given position.
  *
  * @param $position
  * @return \Krucas\Notification\NotificationBag
  */
 public function atPosition($position)
 {
     $this->lastPosition = $position;
     if ($this->lastMessage instanceof Message) {
         $lastMessageIndex = $this->notifications->indexOf($this->lastMessage);
         $this->lastMessage->setPosition($position);
         $this->notifications->offsetUnset($lastMessageIndex);
         $this->notifications->setAtPosition($position, $this->lastMessage);
         if ($this->lastMessage->isFlashable()) {
             $this->flash();
         }
     }
     return $this;
 }
コード例 #2
0
ファイル: Notification.php プロジェクト: hilmysyarif/phpv8
 /**
  * Create new message instance.
  *
  * @param null $message
  * @return \Krucas\Notification\Message
  */
 public function message($message = null)
 {
     $m = new Message();
     $m->setMessage($message);
     return $m;
 }
コード例 #3
0
 /**
  * Adds new notification message to one of collections.
  * If message is array, adds multiple messages.
  * Message can be string, array (array can contain string for message, or array of message and format).
  * Flashes flashable messages.
  *
  * @param $type
  * @@param string|array $message
  * @param bool $flashable
  * @param null $format
  * @return \Krucas\Notification\NotificationsBag
  */
 public function add($type, $message, $flashable = true, $format = null)
 {
     if (!$this->typeIsAvailable($type)) {
         return $this;
     }
     if (is_array($message)) {
         $this->addArray($type, $message, $flashable, $format);
     } else {
         if ($message instanceof \Krucas\Notification\Message) {
             $m = $message;
             $m->setType($type);
             if ($m->isFlashable() != $flashable) {
                 $m->setFlashable($flashable);
             }
             if (is_null($m->getFormat())) {
                 $m->setFormat($this->getFormat($type));
             }
             if (!is_null($format)) {
                 $m->setFormat($this->checkFormat($format, $type));
             }
         } else {
             $m = new Message($type, $message, $flashable, $this->checkFormat($format, $type));
         }
         if (!$m->isFlashable()) {
             if (!is_null($m->getAlias())) {
                 $this->addAliased($m);
             } else {
                 if (!is_null($m->getPosition())) {
                     $this->notifications->setAtPosition($m->getPosition(), $message);
                 } else {
                     $this->notifications->addUnique($m);
                 }
             }
             $this->fireEvent('added', $m);
         } else {
             $this->fireEvent('flash', $m);
         }
     }
     return $this;
 }
コード例 #4
0
 /**
  * Add message by instance.
  *
  * @param \Krucas\Notification\Message $message
  * @param string $type
  * @param bool $flash
  * @param null $format
  */
 protected function addInstance(Message $message, $type, $flash = true, $format = null)
 {
     $message->setType($type);
     if ($message->isFlash() != $flash) {
         $message->setFlash($flash);
     }
     if (is_null($message->getFormat())) {
         $message->setFormat($this->getFormat($type));
     }
     if (!is_null($format)) {
         $message->setFormat($this->checkFormat($format, $type));
     }
 }