refactored set_format to foromat.

This commit is contained in:
Taylor Otwell 2012-05-30 08:41:03 -05:00
parent c2ad6a8126
commit 5f97030ce8
1 changed files with 8 additions and 5 deletions

View File

@ -80,12 +80,12 @@ public function has($key = null)
*
* <code>
* // Apply a new default format.
* $messages->set_format('email', '<p>this is my :message</p>');
* $messages->format('email', '<p>this is my :message</p>');
* </code>
*
* @param string $format
*/
public function set_format($format = ':message')
public function format($format = ':message')
{
$this->format = $format;
}
@ -111,6 +111,7 @@ public function set_format($format = ':message')
public function first($key = null, $format = null)
{
$format = ($format === null) ? $this->format : $format;
$messages = is_null($key) ? $this->all($format) : $this->get($key, $format);
return (count($messages) > 0) ? $messages[0] : '';
@ -134,9 +135,10 @@ public function first($key = null, $format = null)
public function get($key, $format = null)
{
$format = ($format === null) ? $this->format : $format;
if (array_key_exists($key, $this->messages))
{
return $this->format($this->messages[$key], $format);
return $this->transform($this->messages[$key], $format);
}
return array();
@ -159,11 +161,12 @@ public function get($key, $format = null)
public function all($format = null)
{
$format = ($format === null) ? $this->format : $format;
$all = array();
foreach ($this->messages as $messages)
{
$all = array_merge($all, $this->format($messages, $format));
$all = array_merge($all, $this->transform($messages, $format));
}
return $all;
@ -176,7 +179,7 @@ public function all($format = null)
* @param string $format
* @return array
*/
protected function format($messages, $format)
protected function transform($messages, $format)
{
$messages = (array) $messages;