joomla/joomla-cms — pull request #3098 by nonumber (2014-02-13 15:22:56+00:00)
Title: Add ability to empty the message queue

This PR makes it possible to empty the message queue.

#### The issue
Since Joomla 3, the ```_messageQueue``` in the ```JApplicationCms``` is private, so it cannot be overwritten.
In Joomla 2.5, if you want to reset/empty the message queue, you can simply do:
```
JFactory::getApplication()->set('_messageQueue', '');
```
In Joomla 3 that is not possible.

#### The solution
This PR adds a (smart) public method to be able to clear the message queue.
To clear the entire message queue, you can now simply do:
```
JFactory::getApplication()->clearMessageQueue();
```
You can also give an array of types to clear. So if you only want to clear the messages and notices, but not the errors, you can do:
```
JFactory::getApplication()->clearMessageQueue(array('message', 'notice'));
```

#### Some fool-proofing
There are some extra checks to make it a little fool-proof.

You can also pass a string instead of an array if you only want to clear 1 type:
So these do the same:
```
JFactory::getApplication()->clearMessageQueue('message');
JFactory::getApplication()->clearMessageQueue(array('message'));
```

It will also check if you put the plural form of the type(s) instead. So if you give ```messsages``` instead of ```message```, or ```errors``` instead of ```error```.
So these do the same:
```
JFactory::getApplication()->clearMessageQueue('message');
JFactory::getApplication()->clearMessageQueue('messages');
```

The entire queue will also get cleared if the given types include ```all```.
So these all do the same:
```
JFactory::getApplication()->clearMessageQueue();
JFactory::getApplication()->clearMessageQueue('all');
JFactory::getApplication()->clearMessageQueue(array('all'));
JFactory::getApplication()->clearMessageQueue(array('all', 'message'));
```

#### Why need this?
Well, sometimes you want to be able to clear the messages and only show an error.
Or if some error occurs, you want to only show that error, and not anything else in the error queue.
Think for example the long lists of (nearly) the same errors you sometimes get when installing something because a bunch of folders are not writable.
With this you could catch that and just return a single error.