Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed :key (in addition to :message) #30

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Illuminate/Support/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function get($key, $format = null)
// methods is to return back an array of messages in the first place.
if (array_key_exists($key, $this->messages))
{
return $this->transform($this->messages[$key], $format);
return $this->transform($this->messages[$key], $format, $key);
}

return array();
Expand All @@ -107,9 +107,9 @@ public function all($format = null)

$all = array();

foreach ($this->messages as $messages)
foreach ($this->messages as $key => $messages)
{
$all = array_merge($all, $this->transform($messages, $format));
$all = array_merge($all, $this->transform($messages, $format, $key));
}

return $all;
Expand All @@ -122,16 +122,17 @@ public function all($format = null)
* @param string $format
* @return array
*/
protected function transform($messages, $format)
protected function transform($messages, $format, $messagesKey = null)
{
$messages = (array) $messages;

// We will simply spin through the given messages and transform each one
// replacing the :message place holder with the real message allowing
// replacing the :message place holder with the real message
// and replacing the :key place holder with the message array key
// the messages to be easily formatted to each developer's desires.
foreach ($messages as $key => &$message)
{
$message = str_replace(':message', $message, $format);
$message = str_replace(array(':message', ':key'), array($message, $messagesKey), $format);
}

return $messages;
Expand Down Expand Up @@ -198,4 +199,4 @@ public function count()
return count($this->messages);
}

}
}