Commit 319dcbe7 by Taylor Otwell

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

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