PHP Class Krucas\Notification\NotificationsBag

Inheritance: implements Illuminate\Support\Contracts\ArrayableInterface, implements Illuminate\Support\Contracts\JsonableInterface, implements Countabl\Countable
Mostra file Open project: edvinaskrucas/notification Class Usage Examples

Protected Properties

Property Type Description
$container string NotificationBag container name.
$defaultFormat string Default format for all message types.
$formats array Default formats for types.
$groupForRender array Sequence of how messages should be rendered by its type.
$matcher array Array of matcher for extracting types.
$notification Krucas\Notification\Notification Notification library instance.
$notifications Krucas\Notification\Collection | null Collection to store all instant notification messages.
$types array Available message types in container.

Public Methods

Method Description
__call ( $name, $arguments ) : NotificationsBag | string Execute short version of function calls.
__construct ( $container, array $types = [], null $defaultFormat = null, array $formats = [] ) Creates new NotificationBag object.
__toString ( ) : string Convert the Bag to its string representation.
add ( $type, string | Krucas\Notification\Message | Closure $message, boolean $flash = true, null $format = null ) : NotificationsBag Adds new notification message to one of collections.
addToGrouping ( $type ) : NotificationsBag Adds type for rendering.
addType ( $type ) : NotificationsBag Add new available type of message to bag.
all ( ) : Krucas\Notification\Collection Returns all messages in bag.
clear ( null $type = null ) : NotificationsBag Clears message for a given type.
clearAll ( ) : NotificationsBag Clears all messages.
clearFormat ( $type ) : NotificationsBag Clear format for a given type.
clearFormats ( ) : NotificationsBag Clear all formats.
clearTypes ( ) : NotificationsBag Resets types values.
count ( ) : integer Count the number of colections.
first ( ) : Krucas\Notification\Message Returns first message object for given type.
get ( $type ) : Krucas\Notification\Collection Returns all messages for given type.
getDefaultFormat ( ) : string Return default format.
getFormat ( $type ) : boolean | string Return format for a given type.
getGroupingForRender ( ) : array Return array with groups list for rendering.
getName ( ) : string Returns assigned container name.
getNotification ( ) : Krucas\Notification\Notification Get notification instance.
getTypes ( ) : array Return available types of messages in container.
group ( ) : NotificationsBag Set order to render types.
has ( $type = null ) : boolean Check if a message is set for given type.
removeFromGrouping ( $type ) : NotificationsBag Removes type from rendering.
setDefaultFormat ( $format ) : NotificationsBag Set default format for all message types.
setFormat ( $type, $format ) : NotificationsBag Set format for a given type.
setFormats ( $formats ) : NotificationsBag Set formats for a given types.
setNotification ( Krucas\Notification\Notification $notification ) : void Set notification instance.
show ( null $type = null, null $format = null ) : string Returns generated output of non flash messages.
showAll ( null $format = null ) : string Renders all messages.
toArray ( ) : array Get the instance as an array.
toJson ( integer $options ) : string Convert the object to its JSON representation.
typeIsAvailable ( $type ) : boolean Determines if type is available in container.
unsetNotification ( ) : void Unset notification instance.

Protected Methods

Method Description
addInstance ( Krucas\Notification\Message $message, string $type, boolean $flash = true, null $format = null ) Add message by instance.
checkFormat ( $format, null $type = null ) : null Returns valid format.
extractType ( $name ) : boolean | array Extract type from a given string.
fireEvent ( $event, $message ) : boolean Fire event for a given message.
getMessagesForRender ( null $type = null ) : Krucas\Notification\Collection Resolves which messages should be returned for rendering.

Method Details

__call() public method

Execute short version of function calls.
public __call ( $name, $arguments ) : NotificationsBag | string
$name
$arguments
return NotificationsBag | string

__construct() public method

Creates new NotificationBag object.
public __construct ( $container, array $types = [], null $defaultFormat = null, array $formats = [] )
$container
$types array
$defaultFormat null
$formats array

__toString() public method

Convert the Bag to its string representation.
public __toString ( ) : string
return string

add() public method

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.
public add ( $type, string | Krucas\Notification\Message | Closure $message, boolean $flash = true, null $format = null ) : NotificationsBag
$type
$message string | Krucas\Notification\Message | Closure
$flash boolean
$format null
return NotificationsBag

addInstance() protected method

Add message by instance.
protected addInstance ( Krucas\Notification\Message $message, string $type, boolean $flash = true, null $format = null )
$message Krucas\Notification\Message
$type string
$flash boolean
$format null

addToGrouping() public method

Adds type for rendering.
public addToGrouping ( $type ) : NotificationsBag
$type
return NotificationsBag

addType() public method

Add new available type of message to bag.
public addType ( $type ) : NotificationsBag
$type
return NotificationsBag

all() public method

Returns all messages in bag.
public all ( ) : Krucas\Notification\Collection
return Krucas\Notification\Collection

checkFormat() protected method

Returns valid format.
protected checkFormat ( $format, null $type = null ) : null
$format
$type null
return null

clear() public method

Clears message for a given type.
public clear ( null $type = null ) : NotificationsBag
$type null
return NotificationsBag

clearAll() public method

Alias for clear(null).
public clearAll ( ) : NotificationsBag
return NotificationsBag

clearFormat() public method

Clear format for a given type.
public clearFormat ( $type ) : NotificationsBag
$type
return NotificationsBag

clearFormats() public method

Clear all formats.
public clearFormats ( ) : NotificationsBag
return NotificationsBag

clearTypes() public method

Resets types values.
public clearTypes ( ) : NotificationsBag
return NotificationsBag

count() public method

Count the number of colections.
public count ( ) : integer
return integer

extractType() protected method

Extract type from a given string.
protected extractType ( $name ) : boolean | array
$name
return boolean | array

fireEvent() protected method

Fire event for a given message.
protected fireEvent ( $event, $message ) : boolean
$event
$message
return boolean

first() public method

Returns first message object for given type.
public first ( ) : Krucas\Notification\Message
return Krucas\Notification\Message

get() public method

Returns all messages for given type.
public get ( $type ) : Krucas\Notification\Collection
$type
return Krucas\Notification\Collection

getDefaultFormat() public method

Return default format.
public getDefaultFormat ( ) : string
return string

getFormat() public method

Return format for a given type.
public getFormat ( $type ) : boolean | string
$type
return boolean | string

getGroupingForRender() public method

Return array with groups list for rendering.
public getGroupingForRender ( ) : array
return array

getMessagesForRender() protected method

Resolves which messages should be returned for rendering.
protected getMessagesForRender ( null $type = null ) : Krucas\Notification\Collection
$type null
return Krucas\Notification\Collection

getName() public method

Returns assigned container name.
public getName ( ) : string
return string

getNotification() public method

Get notification instance.
public getNotification ( ) : Krucas\Notification\Notification
return Krucas\Notification\Notification

getTypes() public method

Return available types of messages in container.
public getTypes ( ) : array
return array

group() public method

Call this method: group('success', 'info', ...)
public group ( ) : NotificationsBag
return NotificationsBag

has() public method

Check if a message is set for given type.
public has ( $type = null ) : boolean
$type
return boolean

removeFromGrouping() public method

Removes type from rendering.
public removeFromGrouping ( $type ) : NotificationsBag
$type
return NotificationsBag

setDefaultFormat() public method

Set default format for all message types.
public setDefaultFormat ( $format ) : NotificationsBag
$format
return NotificationsBag

setFormat() public method

Set format for a given type.
public setFormat ( $type, $format ) : NotificationsBag
$type
$format
return NotificationsBag

setFormats() public method

Set formats for a given types.
public setFormats ( $formats ) : NotificationsBag
$formats
return NotificationsBag

setNotification() public method

Set notification instance.
public setNotification ( Krucas\Notification\Notification $notification ) : void
$notification Krucas\Notification\Notification
return void

show() public method

Returns generated output of non flash messages.
public show ( null $type = null, null $format = null ) : string
$type null
$format null
return string

showAll() public method

Renders all messages.
public showAll ( null $format = null ) : string
$format null
return string

toArray() public method

Get the instance as an array.
public toArray ( ) : array
return array

toJson() public method

Convert the object to its JSON representation.
public toJson ( integer $options ) : string
$options integer
return string

typeIsAvailable() public method

Determines if type is available in container.
public typeIsAvailable ( $type ) : boolean
$type
return boolean

unsetNotification() public method

Unset notification instance.
public unsetNotification ( ) : void
return void

Property Details

$container protected_oe property

NotificationBag container name.
protected string $container
return string

$defaultFormat protected_oe property

Default format for all message types.
protected string $defaultFormat
return string

$formats protected_oe property

Default formats for types.
protected array $formats
return array

$groupForRender protected_oe property

Sequence of how messages should be rendered by its type.
protected array $groupForRender
return array

$matcher protected_oe property

Array of matcher for extracting types.
protected array $matcher
return array

$notification protected_oe property

Notification library instance.
protected Notification,Krucas\Notification $notification
return Krucas\Notification\Notification

$notifications protected_oe property

Collection to store all instant notification messages.
protected Collection,Krucas\Notification|null $notifications
return Krucas\Notification\Collection | null

$types protected_oe property

Available message types in container.
protected array $types
return array