Created
July 13, 2015 22:22
-
-
Save destinydriven/7df10047a6eb65a3af80 to your computer and use it in GitHub Desktop.
FlashComponent::_call()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Magic method for verbose flash methods based on element names. | |
* | |
* For example: $this->Flash->success('My message') would use the | |
* success.ctp element under `app/View/Element/Flash` for rendering the | |
* flash message. | |
* | |
* @param string $name Element name to use. | |
* @param array $args Parameters to pass when calling `FlashComponent::set()`. | |
* @return void | |
* @throws InternalErrorException If missing the flash message. | |
*/ | |
public function __call($name, $args) { | |
$options = array('element' => Inflector::underscore($name)); | |
if (count($args) < 1) { | |
throw new InternalErrorException('Flash message missing.'); | |
} | |
if (!empty($args[1])) { | |
if (!empty($args[1]['plugin'])) { | |
$options = ['element' => $args[1]['plugin'] . '.' . $options['element']]; | |
unset($args[1]['plugin']); | |
} | |
$options += (array)$args[1]; | |
} | |
$this->set($args[0], $options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment