Download the PHP package tobento/service-message without Composer
On this page you can find all versions of the php package tobento/service-message. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package service-message
Message Service
Messages for PHP applications.
Table of Contents
- Getting started
- Requirements
- Highlights
- Documentation
- Message
- Create Message
- Message Factory
- Message Interface
- Render Message
- Messages
- Create Messages
- Messages Factory
- Add Messages
- Filter Messages
- Get Messages
- Messages Aware
- Modifiers
- Modifier
- Pluralization
- Parameter Replacer
- Limit Length
- Translator
- Parameter Translator
- Message
- Credits
Getting started
Add the latest version of the Message service project running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
Documentation
Message
Create Message
Parameters explanation
Parameter | Description |
---|---|
level | Any level. It's up to you. |
message | The message. |
context | Any context for the message. |
key | A key which might be used for an identifier for input data for instance. |
parameters | Any parameters used for Modifiers. |
logged | Used as to know if message has been logged already as not to log muliple times. |
Message Factory
createMessage
createMessageFromArray
Message Interface
The message interface has the following methods:
With methods
You may use the with prefixed methods returning a new instance.
Render Message
Messages
Create Messages
Parameters explanation
Parameter | Description |
---|---|
messageFactory | Used for creating messages. |
modifiers | Used for modifying message. See Modifiers for more detail. |
logger | If a logger is set, messages will be logged right after messages are added and log parameter is set to true. |
withMessageFactory
withModifiers
withLogger
Messages Factory
You might want to use the message factory to create the messages.
Add Messages
By using the addMessage method:
By using the add method:
By using the push method:
By using the withMessage method returning a new instance:
Filter Messages
Filter methods always returning a new instance.
filter
key
Filters messages by its key:
only
Filters messages only with the levels specified:
except
Filters messages except with the levels specified:
Get Messages
all
first
Get the first message:
last
Get the last message:
column
has
Messages Aware
You might support messages in any class by using the HasMessages trait:
Modifiers
Modifiers can be used for modifying the message such as translating.
Create Modifiers
Add Modifier
Prepend Modifier
Adds a modifier to the beginning.
Modify Message
Get Modifiers
Modifier
Pluralization
Parameter Replacer
Limit Length
Translator
For more information about the translator, check out the Translation Service documentation.
Parameter Translator
Sometimes you might need to translate message parameters:
Credits
- Tobias Strub
- All Contributors
All versions of service-message with dependencies
tobento/service-collection Version ^1.0
tobento/service-support Version ^1.0
psr/log Version ^1.1 || ^2.0 || ^3.0