Download the PHP package eftec/messagecontainer without Composer

On this page you can find all versions of the php package eftec/messagecontainer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package messagecontainer

MessageContainer

It is a Message Container for PHP, similar in functionality MessageBag for Laravel. However, this is aimed for speed and usability, and it doesn't have any dependency.

This class is simple: 2 classes, no dependency and nothing more. You can use in any PHP project.

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

What is the objective?

This library stores messages (strings) in different lockers and each locker could contain different messages with different levels (error, warning, info and success). The goal of this library:

It is an example from where we could use it, the validation of a form (this library does not validate or show values it only stores the information)

In this example, we have :

If we use plain-PHP, we could show some messages of the password:

But what if the id password does not contain any message, or if there is no error? of if there is more than error?

So we could re-define something like that: (but it will still fail if there is more than one error)

Vanilla PHP:

And with our library

How to use it

Definitions

Let's say the next example of container that shows every part of the Container.

We have 3 levels of spaces.

Messages are leveled as follows

id Description Example
error The message is an error, and it must be solved. It is our show stopper. Database is down
warning The message is a warning that maybe it could be ignored. However, the class MessageContainer could allow to group Error and Warning as the same. The registry was stored but with warnings
info The message is information. For example, to log or debug an operation. Log is stored
success The message is a successful operation Order Accepted

Example #2

Example of form and MessageContainer

examples/formexample.php

Example #3:

Adding a new message

To add a new message inside a locker, we use the method addItem()

Where

Note: We could add one or many messages to a locker. In the later example, the locker locker2 stores 3 messages.

Note: The message is evaluated when we call the method addItem()

Getting the messages

MessageContainer stores a list of lockers of messages. It's aimed at convenience, so it features many methods to access the information in different ways.

Messages are ranked as follows

id Description Example
error The message is an error, and it must be solved. It is a show stopper. Database is down
warning The message is a warning that maybe it could be ignored. The registry was stored but with warnings
info The message is information Log is stored
success The message is a successful operation Order Accepted

Sometimes, both errors are warning are considered as equals. So the system allows reading an error or warning.

Error always has the priority, then warning, info and success. If you want to read the first message, then it starts searching for errors.

You can obtain a message as an array of objects of the type MessageLocker, as an array of string, or as a single string (first message)

MessageContainer

Count of messages of all lockers

Name of the field Type Description
$errorCount int Get the number of errors in all lockers
$warningCount int Get the number of warnings in all lockers
$errorOrWarning int Get the number of errors or warnings in all lockers
$infoCount int Get the number of information messages.
$successCount int Get the number of success messages.

Example:

Obtain messages or text of all lockers

Name Type Description Example of result
firstErrorText() method Returns the first message of error of all lockers "Error in field"
firstWarningText() method Returns the first message of warning of all lockers "warning in field"
firstInfoText() method Returns the first message of info of all lockers "info: log"
firstSuccessText() method Returns the first message of success of all lockers "Operation successful"
lastErrorText() method Returns the last message of error of all lockers "Error in field"
lastWarningText() method Returns the last message of warning of all lockers "warning in field"
lastInfoText() method Returns the last message of info of all lockers "info: log"
lastSuccessText() method Returns the last message of success of all lockers "Operation successful"
allError() method Returns all errors of all lockers (as an array of objects of the type MessageLocker) MessageLocker[]
allWarning() method Returns all warning of all lockers (as an array of objects of the type MessageLocker) MessageLocker[]
allInfo() method Returns all info of all lockers (as an array of objects of the type MessageLocker) MessageLocker[]
allSuccess() method Returns all success of all lockers (as an array of objects of the type MessageLocker) MessageLocker[]
allErrorArray() method Returns all errors of all lockers (as an array of texts) ["Error in field1","Error in field2"]
allWarningArray() method Returns all warning of all lockers (as an array of texts) ["Warning in field1","Warning in field2"]
allInfoArray() method Returns all info of all lockers (as an array of texts) ["Info in field1","Info in field2"]
allSuccessArray method Returns all success of all lockers (as an array of texts) ["Info in field1","Info in field2"]

Css for a specific container

It is possible to obtain a CSS class based in the current level or state of a container.

Misc

Name Type Description
$items field We get all lockers (array of the type MessageLocker). Each container could contain many messages.
resetAll() method $array=$this-messageList->items; $this-messageList->items['id'];Delete all lockers and reset counters
addItem() method It adds a new message to a container
allIds() method Get all the id of the lockers
get() method Get a container (as an object of the type MessageLocker). You can also use items[]
hasError() method Returns true if there is an error.

MessageLocker

Inside MessageContainer we could have one or many lockers( MessageLocker ).

Obtain messages of a specific container

Name Type Description Example of result
firstErrorText() method Returns the first message of error of a container "Error in field"
firstWarningText() method Returns the first message of warning of a container "warning in field"
firstInfoText() method Returns the first message of info of a container "info: log"
firstSuccessText() method Returns the first message of success of a container "Operation successful"
lastErrorText() method Returns the last message of error of a container "Error in field"
lastWarningText() method Returns the last message of warning of a container "warning in field"
lastInfoText() method Returns the last message of info of a container "info: log"
lastSuccessText() method Returns the last message of success of a container "Operation successful"
allError() method Returns all errors of a container (as an array of texts) ["Error in field1","Error in field2"]
allWarning() method Returns all warning of a container (as an array of texts) ["Warning in field1","Warning in field2"]
allInfo() method Returns all info of a container (as an array of texts) ["Info in field1","Info in field2"]
allSuccess() method Returns all success of a container (as an array of texts) ["Info in field1","Info in field2"]

Definitions of the classes

Table of contents


MessageContainer

Class MessageList

Field items (MessageLocker[])

Array of containers

Field errorCount (int)

Number of errors stored globally

Field warningCount (int)

Number of warnings stored globally

Field errorOrWarningCount (int)

Number of errors or warning stored globally

Field infoCount (int)

Number of information stored globally

Field successCount (int)

Number of success stored globally

Field cssClasses (string[])

Used to convert a type of message to a css class

Method __construct()

MessageList constructor.

Method resetAll()

It resets all the container and flush all the results.

Method addItem()

You could add a message (including errors,warning..) and store it in a $idLocker

Parameters:

Method allIds()

It obtains all the ids for all the lockers.

Method get()

Alias of $this->getMessage()

Parameters:

Method getLocker()

It returns a MessageLocker containing a locker.
If the locker doesn't exist then it returns an empty object (not null)

Parameters:

Method cssClass()

It returns a css class associated with the type of errors inside a locker
If the locker contains more than one message, then it uses the most severe one (error,warning,etc.)
The method uses the field $this->cssClasses, so you can change the CSS classes.

$this->clsssClasses=['error'=>'class-red','warning'=>'class-yellow','info'=>'class-green','success'=>'class-blue'];
$css=$this->cssClass('customerId');

Parameters:

Method firstErrorOrWarning()

It returns the first message of error or empty if none
If not, then it returns the first message of warning or empty if none

Parameters:

Method firstErrorText()

It returns the first message of error or empty if none

Parameters:

Method firstWarningText()

It returns the first message of warning or empty if none

Parameters:

Method firstInfoText()

It returns the first message of information or empty if none

Parameters:

Method firstSuccessText()

It returns the first message of success or empty if none

Parameters:

Method lastErrorOrWarning()

It returns the last message of error or empty if none
If not, then it returns the last message of warning or empty if none

Parameters:

Method lastErrorText()

It returns the last message of error or empty if none

Parameters:

Method lastWarningText()

It returns the last message of warning or empty if none

Parameters:

Method lastInfoText()

It returns the last message of information or empty if none

Parameters:

Method lastSuccessText()

It returns the last message of success or empty if none

Parameters:

Method allArray()

It returns an array with all messages of any type of all lockers

Parameters:

Method allErrorArray()

It returns an array with all messages of error of all lockers.

Parameters:

Method allWarningArray()

It returns an array with all messages of warning of all lockers.

Method allErrorOrWarningArray()

It returns an array with all messages of errors and warnings of all lockers.

Method allInfoArray()

It returns an array with all messages of info of all lockers.

Method AllSuccessArray()

It returns an array with all messages of success of all lockers.

Method allAssocArray()

It returns an associative array of the form

[
['id'=>'', // id of the locker
'level'=>'' // level of message (error, warning, info or success)
'msg'=>'' // the message to show
]
]

Parameters:

Method hasError()

It returns true if there is an error (or error and warning).

Parameters:


MessageLocker

Class MessageLocker

Method __construct()

MessageLocker constructor.

Parameters:

Method setContext()

We set the context only if the current context is null.

Parameters:

Method addError()

It adds an error to the locker.

Parameters:

Method replaceCurlyVariable()

Replaces all variables defined between {{ }} by a variable inside the dictionary of values.
Example:
replaceCurlyVariable('hello={{var}}',['var'=>'world']) // hello=world
replaceCurlyVariable('hello={{var}}',['varx'=>'world']) // hello=
replaceCurlyVariable('hello={{var}}',['varx'=>'world'],true) // hello={{var}}

Parameters:

Method addWarning()

It adds a warning to the locker.

Parameters:

Method addInfo()

It adds an information to the locker.

Parameters:

Method addSuccess()

It adds a success to the locker.

Parameters:

Method countErrorOrWarning()

It returns the number of errors or warnings contained in the locker

Method countError()

It returns the number of errors contained in the locker

Method countWarning()

It returns the number of warnings contained in the locker

Method countInfo()

It returns the number of infos contained in the locker

Method countSuccess()

It returns the number of successes contained in the locker

Method first()

It returns the first message of any kind.
If error then it returns the first message of error
If not, if warning then it returns the first message of warning
If not, then it shows the first info message (if any)
If not, then it shows the first success message (if any)
If not, then it shows the default message.

Parameters:

Method firstError()

It returns the first message of error, if any. Otherwise, it returns the default value

Parameters:

Method firstWarning()

It returns the first message of warning, if any. Otherwise, it returns the default value

Parameters:

Method firstErrorOrWarning()

It returns the first message of error or warning (in this order), if any. Otherwise, it returns the default value

Parameters:

Method firstInfo()

It returns the first message of info, if any. Otherwise, it returns the default value

Parameters:

Method firstSuccess()

It returns the first message of success, if any. Otherwise, it returns the default value

Parameters:

Method last()

It returns the last message of any kind.
If error then it returns the last message of error
If not, if warning then it returns the last message of warning
If not, then it shows the last info message (if any)
If not, then it shows the last success message (if any)
If not, then it shows the default message.

Parameters:

Method lastError()

It returns the last message of error, if any. Otherwise, it returns the default value

Parameters:

Method lastWarning()

It returns the last message of warning, if any. Otherwise, it returns the default value

Parameters:

Method lastErrorOrWarning()

It returns the last message of error or warning (in this order), if any. Otherwise, it returns the default value

Parameters:

Method lastInfo()

It returns the last message of info, if any. Otherwise, it returns the default value

Parameters:

Method lastSuccess()

It returns the last message of success, if any. Otherwise, it returns the default value

Parameters:

Method all()

Returns all messages or an empty array if none.

Parameters:

Method allError()

Returns all messages of errors (as an array of string), or an empty array if none.

Method allWarning()

Returns all messages of warning, or an empty array if none.

Method allErrorOrWarning()

Returns all messages of errors or warnings, or an empty array if none

Method allInfo()

Returns all messages of info, or an empty array if none.

Method allSuccess()

Returns all messages of success, or an empty array if none.

Method allAssocArray()

It returns an associative array of the form:

[
['id'=>'', // id of the locker
'level'=>'' // level of message (error, warning, info or success)
'msg'=>'' // the message to show
]
]

Parameters:

Method hasError()

It returns true if there is an error (or error and warning).

Parameters:

Method throwOnError()

If we store an error then we also throw a PHP exception.

Parameters:


changelog


All versions of messagecontainer with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-ctype Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package eftec/messagecontainer contains the following files

Loading the files please wait ....