Skip to content

Instantly share code, notes, and snippets.

@destinydriven
Created July 13, 2015 22:22
Show Gist options
  • Save destinydriven/7df10047a6eb65a3af80 to your computer and use it in GitHub Desktop.
Save destinydriven/7df10047a6eb65a3af80 to your computer and use it in GitHub Desktop.
FlashComponent::_call()
/**
* 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