Commit 319dcbe7 by Taylor Otwell

Merge branch 'develop' of github.com:taylorotwell/laravel into develop

parents 3392971c d7aca820
......@@ -78,8 +78,9 @@ class Hydrator {
// -----------------------------------------------------
// Get the relationship Eloquent model.
//
// We temporarily spoof the "belongs_to" key to allow
// the query to be fetched without any problems.
// We temporarily spoof the belongs_to key to allow the
// query to be fetched without any problems, since the
// belongs_to method actually gets the attribute.
// -----------------------------------------------------
$eloquent->attributes[$spoof = $include.'_id'] = 0;
......
......@@ -3,13 +3,6 @@
class Lang {
/**
* All of the loaded language files.
*
* @var array
*/
private static $loaded = array();
/**
* All of the loaded language lines.
*
* The array is keyed by [$language.$file].
......@@ -55,24 +48,30 @@ class Lang {
}
/**
* Get the language line for a given language.
* Get the language line.
*
* @param string $language
* @param mixed $default
* @return string
*/
public function get($language = null)
{
if (is_null($language))
public function get($default = null)
{
$language = Config::get('application.language');
}
list($file, $line) = $this->parse($this->key);
$this->load($file, $language);
// --------------------------------------------------------------
// If the language file did not exist, return the default value.
// --------------------------------------------------------------
if ( ! array_key_exists($language.$file, static::$lines))
{
return $default;
}
// --------------------------------------------------------------
// Get the language line from the appropriate file array.
// If the line doesn't exist, return the default value.
// --------------------------------------------------------------
if (array_key_exists($line, static::$lines[$language.$file]))
{
......@@ -80,7 +79,7 @@ class Lang {
}
else
{
throw new \Exception("Language line [$line] does not exist for language [$language]");
return $default;
}
// --------------------------------------------------------------
......@@ -127,28 +126,16 @@ class Lang {
private function load($file, $language)
{
// --------------------------------------------------------------
// If we have already loaded the language file, bail out.
// If we have already loaded the language file or the file
// doesn't exist, bail out.
// --------------------------------------------------------------
if (in_array($language.$file, static::$loaded))
if (array_key_exists($language.$file, static::$lines) or ! file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT))
{
return;
}
// --------------------------------------------------------------
// Load the language file into the array of lines. The array
// is keyed by the language and file name.
// --------------------------------------------------------------
if (file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT))
{
static::$lines[$language.$file] = require $path;
}
else
{
throw new \Exception("Language file [$file] does not exist for language [$language].");
}
static::$loaded[] = $language.$file;
}
/**
* Set the place-holder replacements.
......
......@@ -5,7 +5,7 @@ use System\Lang;
abstract class Rule {
/**
* The attributes being validated.
* The attributes being validated by the rule.
*
* @var array
*/
......@@ -22,7 +22,6 @@ abstract class Rule {
* Create a new validation Rule instance.
*
* @param array $attributes
* @param Validator $class
* @return void
*/
public function __construct($attributes)
......@@ -39,11 +38,6 @@ abstract class Rule {
*/
public function validate($attributes, $errors)
{
if (is_null($this->message))
{
throw new \Exception("An error message must be specified for every Eloquent validation rule.");
}
foreach ($this->attributes as $attribute)
{
if ( ! $this->check($attribute, $attributes))
......@@ -56,18 +50,28 @@ abstract class Rule {
/**
* Prepare the message to be added to the error collector.
*
* Attribute and size place-holders will replace with their actual values.
*
* @param string $attribute
* @return string
*/
private function prepare_message($attribute)
{
if (is_null($this->message))
{
throw new \Exception("An error message must be specified for every Eloquent validation rule.");
}
$message = $this->message;
// ---------------------------------------------------------
// Replace any place-holders with their actual values.
//
// Attribute place-holders are loaded from the language
// directory. If the line doesn't exist, the attribute
// name will be used instead.
// ---------------------------------------------------------
if (strpos($message, ':attribute'))
{
$message = str_replace(':attribute', Lang::line('attributes.'.$attribute)->get(), $message);
$message = str_replace(':attribute', Lang::line('attributes.'.$attribute)->get($attribute), $message);
}
if ($this instanceof Rules\Size_Of)
......
......@@ -5,7 +5,7 @@ use System\Validation\Rule;
class Format_Of extends Rule {
/**
* The regular expression that will be used to evaluate the attribute.
* The regular expression that will be used to validate the attribute.
*
* @var string
*/
......
......@@ -12,7 +12,7 @@ class Presence_Of extends Rule {
public $allow_empty = false;
/**
* Indicates a null should be considered present.
* Indicates null should be considered present.
*
* @var bool
*/
......
......@@ -119,7 +119,7 @@ class Size_Of extends Rule {
}
/**
* Set the minimum and maximize size of the attribute.
* Set the minimum and maximum size of the attribute.
*
* @param int $minimum
* @param int $maximum
......
<?php namespace System\Validation\Rules;
use System\DB;
use System\DB\Eloquent;
use System\Validation\Rule;
class Uniqueness_Of extends Rule {
......
......@@ -5,7 +5,7 @@ use System\Validation\Rule;
class With_Callback extends Rule {
/**
* The callback.
* The callback that will be used to validate the attribute.
*
* @var function
*/
......@@ -27,7 +27,7 @@ class With_Callback extends Rule {
if ( ! is_callable($this->callback))
{
throw new \Exception("A validation callback for the [$attribute] attribute is not callable.");
throw new \Exception("The validation callback for the [$attribute] attribute is not callable.");
}
return call_user_func($this->callback, $attributes[$attribute]);
......
......@@ -24,7 +24,7 @@ class Validator {
public $rules = array();
/**
* Create a new Eloquent validator instance.
* Create a new Validator instance.
*
* @param mixed $target
* @return void
......@@ -41,7 +41,7 @@ class Validator {
}
/**
* Create a new Eloquent validator instance.
* Create a new Validator instance.
*
* @param mixed $target
* @return Validator
......@@ -52,7 +52,7 @@ class Validator {
}
/**
* Determine if the model passes all of the validation rules.
* Determine if the attributes pass all of the validation rules.
*
* @return bool
*/
......
......@@ -95,6 +95,9 @@ class View {
// We include the view into the local scope within a
// try / catch block to catch any exceptions that may
// occur while the view is rendering.
//
// Otherwise, a white screen of death will be shown
// if an exception occurs while rendering the view.
// -----------------------------------------------------
try
{
......@@ -111,9 +114,8 @@ class View {
/**
* Get the full path to the view.
*
* Views are cascaded, so the application directory views
* will take precedence over the system directory's views
* of the same name.
* Views are cascaded, so the application directory views will take
* precedence over system directory views of the same name.
*
* @return string
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment