Download the PHP package werx/messages without Composer
On this page you can find all versions of the php package werx/messages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download werx/messages
More information about werx/messages
Files in werx/messages
Package messages
Short Description Simple package for building and displaying various types of messages in a web app.
License MIT
Informations about the package messages
werx\messages
Simple package for displaying various types of messages in a web app.
Usage
Now you can add some messages. Valid messages types are error, info, warning, and success.
You can also use printf
compatible format codes in your message strings along with an array as the 2nd parameter containing string replacements to make it easier to embed dynamic data in your messages without doing a lot of string concatenation.
If you are only using one replacement, you can pass a string as the 2nd param instead of an array.
Furthermore, you can add messages as an array:
Once you've added the messages to the stack, you have a couple options.
1) Fetch all the messages back as an array.
2) Display the messages using a decorator
The above renders something like this:
Decorators
By default, a simple decorator will be used that wraps the messages in a series of unordered lists as shown above. The <ul>
for each type of message (error
, info
, success
) will be classed with the name of the message type.
If you are using Bootstrap for your design, you can specify that messages should be decorated using the Bootstrap Alert HTML Markup instead.
If you want to create your own decorator, just create a class that implements werx\Messages\Decorators\DecoratorInterface
and pass an instance to Messages::setDecorator()
.
Renders:
Sessions
By storing messages in session, they can persist across multiple page loads until you either display or delete them.
By default, this library will create a new instance of the Symfony Native Session Storage object for storage of messages. If you already have an instance of a Symfony Session Interface, you can pass that to Messages::getInstance()
.
Installation
This package is installable and autoloadable via Composer as werx/messages. If you aren't familiar with the Composer Dependency Manager for PHP, you should read this first.
Contributing
Unit Testing
Coding Standards
This library uses PHP_CodeSniffer to ensure coding standards are followed.
I have adopted the PHP FIG PSR-2 Coding Standard EXCEPT for the tabs vs spaces for indentation rule. PSR-2 says 4 spaces. I use tabs. No discussion.
To support indenting with tabs, I've defined a custom PSR-2 ruleset that extends the standard PSR-2 ruleset used by PHP_CodeSniffer. You can find this ruleset in the root of this project at PSR2Tabs.xml
Executing the codesniffer command from the root of this project to run the sniffer using these custom rules.
$ ./codesniffer