mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
trimmed comment bloat. returning boolean on eloquent save.
This commit is contained in:
parent
b66be283d4
commit
f7bb0c5510
@ -92,6 +92,7 @@ return array(
|
||||
'Response' => 'System\\Response',
|
||||
'Session' => 'System\\Session',
|
||||
'Str' => 'System\\Str',
|
||||
'Test' => 'System\\Test',
|
||||
'Text' => 'System\\Text',
|
||||
'View' => 'System\View',
|
||||
),
|
||||
|
@ -41,9 +41,6 @@ class Auth {
|
||||
throw new \Exception("You must specify a session driver before using the Auth class.");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Get the authentication model.
|
||||
// -----------------------------------------------------
|
||||
$model = static::model();
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -65,9 +62,6 @@ class Auth {
|
||||
*/
|
||||
public static function login($username, $password)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Get the authentication model.
|
||||
// -----------------------------------------------------
|
||||
$model = static::model();
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -82,19 +76,10 @@ class Auth {
|
||||
// -----------------------------------------------------
|
||||
$password = (isset($user->salt)) ? Hash::make($password, $user->salt)->value : sha1($password);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Verify that the passwords match.
|
||||
// -----------------------------------------------------
|
||||
if ($user->password == $password)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Set the user property.
|
||||
// -----------------------------------------------------
|
||||
static::$user = $user;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Store the user ID in the session.
|
||||
// -----------------------------------------------------
|
||||
Session::put(static::$key, $user->id);
|
||||
|
||||
return true;
|
||||
@ -111,14 +96,7 @@ class Auth {
|
||||
*/
|
||||
public static function logout()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Remove the user ID from the session.
|
||||
// -----------------------------------------------------
|
||||
Session::forget(static::$key);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Clear the current user variable.
|
||||
// -----------------------------------------------------
|
||||
static::$user = null;
|
||||
}
|
||||
|
||||
|
9
system/cache/driver/file.php
vendored
9
system/cache/driver/file.php
vendored
@ -38,16 +38,13 @@ class File implements \System\Cache\Driver {
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Verify that the cache file exists.
|
||||
// Does the cache item even exist?
|
||||
// --------------------------------------------------
|
||||
if ( ! file_exists(APP_PATH.'cache/'.$key))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Read the contents of the cache file.
|
||||
// --------------------------------------------------
|
||||
$cache = file_get_contents(APP_PATH.'cache/'.$key);
|
||||
|
||||
// --------------------------------------------------
|
||||
@ -74,10 +71,6 @@ class File implements \System\Cache\Driver {
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
// --------------------------------------------------
|
||||
// The expiration time is stored as a UNIX timestamp
|
||||
// at the beginning of the cache file.
|
||||
// --------------------------------------------------
|
||||
file_put_contents(APP_PATH.'cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX);
|
||||
}
|
||||
|
||||
|
@ -17,19 +17,10 @@ class Config {
|
||||
*/
|
||||
public static function get($key)
|
||||
{
|
||||
// ---------------------------------------------
|
||||
// Parse the configuration key.
|
||||
// ---------------------------------------------
|
||||
list($file, $key) = static::parse($key);
|
||||
|
||||
// ---------------------------------------------
|
||||
// Load the configuration file.
|
||||
// ---------------------------------------------
|
||||
static::load($file);
|
||||
|
||||
// ---------------------------------------------
|
||||
// Return the requested item.
|
||||
// ---------------------------------------------
|
||||
return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : null;
|
||||
}
|
||||
|
||||
@ -42,19 +33,10 @@ class Config {
|
||||
*/
|
||||
public static function set($file, $value)
|
||||
{
|
||||
// ---------------------------------------------
|
||||
// Parse the configuration key.
|
||||
// ---------------------------------------------
|
||||
list($file, $key) = static::parse($key);
|
||||
|
||||
// ---------------------------------------------
|
||||
// Load the configuration file.
|
||||
// ---------------------------------------------
|
||||
static::load($file);
|
||||
|
||||
// ---------------------------------------------
|
||||
// Set the item's value.
|
||||
// ---------------------------------------------
|
||||
static::$items[$file][$key] = $value;
|
||||
}
|
||||
|
||||
@ -66,22 +48,13 @@ class Config {
|
||||
*/
|
||||
private static function parse($key)
|
||||
{
|
||||
// ---------------------------------------------
|
||||
// Get the key segments.
|
||||
// ---------------------------------------------
|
||||
$segments = explode('.', $key);
|
||||
|
||||
// ---------------------------------------------
|
||||
// Validate the key format.
|
||||
// ---------------------------------------------
|
||||
if (count($segments) < 2)
|
||||
{
|
||||
throw new \Exception("Invalid configuration key [$key].");
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Return the file and item name.
|
||||
// ---------------------------------------------
|
||||
return array($segments[0], implode('.', array_slice($segments, 1)));
|
||||
}
|
||||
|
||||
@ -93,25 +66,16 @@ class Config {
|
||||
*/
|
||||
public static function load($file)
|
||||
{
|
||||
// ---------------------------------------------
|
||||
// If the file has already been loaded, bail.
|
||||
// ---------------------------------------------
|
||||
if (array_key_exists($file, static::$items))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Verify that the configuration file exists.
|
||||
// ---------------------------------------------
|
||||
if ( ! file_exists($path = APP_PATH.'config/'.$file.EXT))
|
||||
{
|
||||
throw new \Exception("Configuration file [$file] does not exist.");
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Load the configuration file.
|
||||
// ---------------------------------------------
|
||||
static::$items[$file] = require $path;
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,6 @@ class Cookie {
|
||||
*/
|
||||
public static function put($key, $value, $minutes = 0, $path = '/', $domain = null, $secure = false)
|
||||
{
|
||||
// ----------------------------------------------------------
|
||||
// If the lifetime is less than zero, delete the cookie.
|
||||
// ----------------------------------------------------------
|
||||
if ($minutes < 0)
|
||||
{
|
||||
unset($_COOKIE[$key]);
|
||||
|
@ -48,14 +48,7 @@ class Crypt {
|
||||
mt_srand();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Create the input vector.
|
||||
// -----------------------------------------------------
|
||||
$iv = mcrypt_create_iv(static::iv_size(), $random);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Encrypt the value using MCrypt.
|
||||
// -----------------------------------------------------
|
||||
$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -72,14 +65,8 @@ class Crypt {
|
||||
*/
|
||||
public static function decrypt($value)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Decode the base64 value.
|
||||
// -----------------------------------------------------
|
||||
$value = base64_decode($value, true);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Validate the base64 conversion.
|
||||
// -----------------------------------------------------
|
||||
if ( ! $value)
|
||||
{
|
||||
throw new \Exception('Decryption error. Input value is not valid base64 data.');
|
||||
@ -95,9 +82,6 @@ class Crypt {
|
||||
// -----------------------------------------------------
|
||||
$value = substr($value, static::iv_size());
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Decrypt the value using MCrypt.
|
||||
// -----------------------------------------------------
|
||||
return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
|
||||
}
|
||||
|
||||
@ -108,9 +92,6 @@ class Crypt {
|
||||
*/
|
||||
private static function key()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Validate the application key.
|
||||
// -----------------------------------------------------
|
||||
if (is_null($key = Config::get('application.key')) or $key == '')
|
||||
{
|
||||
throw new \Exception("The encryption class can not be used without an encryption key.");
|
||||
|
@ -17,9 +17,6 @@ class DB {
|
||||
*/
|
||||
public static function connection($connection = null)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// If no connection was given, use the default.
|
||||
// ---------------------------------------------------
|
||||
if (is_null($connection))
|
||||
{
|
||||
$connection = Config::get('db.default');
|
||||
@ -31,14 +28,8 @@ class DB {
|
||||
// ---------------------------------------------------
|
||||
if ( ! array_key_exists($connection, static::$connections))
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Get the database configurations.
|
||||
// ---------------------------------------------------
|
||||
$config = Config::get('db.connections');
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Verify the connection has been defined.
|
||||
// ---------------------------------------------------
|
||||
if ( ! array_key_exists($connection, $config))
|
||||
{
|
||||
throw new \Exception("Database connection [$connection] is not defined.");
|
||||
@ -63,14 +54,8 @@ class DB {
|
||||
*/
|
||||
public static function query($sql, $bindings = array(), $connection = null)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Create a new PDO statement from the SQL.
|
||||
// ---------------------------------------------------
|
||||
$query = static::connection($connection)->prepare($sql);
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Execute the query with the bindings.
|
||||
// ---------------------------------------------------
|
||||
$result = $query->execute($bindings);
|
||||
|
||||
// ---------------------------------------------------
|
||||
|
@ -36,9 +36,6 @@ class Connector {
|
||||
{
|
||||
$connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options);
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Set the correct character set.
|
||||
// ---------------------------------------------------
|
||||
if (isset($config->charset))
|
||||
{
|
||||
$connection->prepare("SET NAMES '".$config->charset."'")->execute();
|
||||
@ -46,9 +43,6 @@ class Connector {
|
||||
|
||||
return $connection;
|
||||
}
|
||||
// ---------------------------------------------------
|
||||
// If the driver isn't supported, bail out.
|
||||
// ---------------------------------------------------
|
||||
else
|
||||
{
|
||||
throw new \Exception('Database driver '.$config->driver.' is not supported.');
|
||||
|
@ -76,14 +76,7 @@ abstract class Eloquent {
|
||||
*/
|
||||
public static function with()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Create a new model instance.
|
||||
// -----------------------------------------------------
|
||||
$model = Eloquent\Factory::make(get_called_class());
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the eager relationships.
|
||||
// -----------------------------------------------------
|
||||
$model->includes = func_get_args();
|
||||
|
||||
return $model;
|
||||
@ -117,14 +110,8 @@ abstract class Eloquent {
|
||||
*/
|
||||
private function _first()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Load the hydrated models.
|
||||
// -----------------------------------------------------
|
||||
$results = Eloquent\Hydrate::from($this->take(1));
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the first result.
|
||||
// -----------------------------------------------------
|
||||
if (count($results) > 0)
|
||||
{
|
||||
reset($results);
|
||||
@ -185,11 +172,16 @@ abstract class Eloquent {
|
||||
/**
|
||||
* Save the model to the database.
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
Eloquent\Warehouse::store($this);
|
||||
if ($this->exists and count($this->dirty) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Eloquent\Warehouse::store($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,17 +207,11 @@ abstract class Eloquent {
|
||||
// -----------------------------------------------------
|
||||
$model = $this->$key();
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the relationship results.
|
||||
// -----------------------------------------------------
|
||||
return ($this->relating == 'has_one' or $this->relating == 'belongs_to')
|
||||
? $this->ignore[$key] = $model->first()
|
||||
: $this->ignore[$key] = $model->get();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Check the "regular" attributes.
|
||||
// -----------------------------------------------------
|
||||
return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null;
|
||||
}
|
||||
|
||||
@ -243,9 +229,6 @@ abstract class Eloquent {
|
||||
}
|
||||
else
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Add the value to the attributes.
|
||||
// -----------------------------------------------------
|
||||
$this->attributes[$key] = $value;
|
||||
$this->dirty[$key] = $value;
|
||||
}
|
||||
@ -274,17 +257,11 @@ abstract class Eloquent {
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Is the "get" method being called?
|
||||
// -----------------------------------------------------
|
||||
if ($method == 'get')
|
||||
{
|
||||
return $this->_get();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Is the "first" method being called?
|
||||
// -----------------------------------------------------
|
||||
if ($method == 'first')
|
||||
{
|
||||
return $this->_first();
|
||||
@ -312,22 +289,13 @@ abstract class Eloquent {
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Create a new model instance.
|
||||
// -----------------------------------------------------
|
||||
$model = Eloquent\Factory::make(get_called_class());
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Do we need to return the entire table?
|
||||
// -----------------------------------------------------
|
||||
if ($method == 'get')
|
||||
{
|
||||
return $model->_get();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Do we need to return the first model from the table?
|
||||
// -----------------------------------------------------
|
||||
if ($method == 'first')
|
||||
{
|
||||
return $model->_first();
|
||||
|
@ -10,13 +10,10 @@ class Factory {
|
||||
*/
|
||||
public static function make($class)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Create a new model instance.
|
||||
// -----------------------------------------------------
|
||||
$model = new $class;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the active query instance on the model.
|
||||
// Set the fluent query builder on the model.
|
||||
// -----------------------------------------------------
|
||||
$model->query = \System\DB\Query::table(Meta::table($class));
|
||||
|
||||
|
@ -22,17 +22,11 @@ class Hydrate {
|
||||
{
|
||||
foreach ($eloquent->includes as $include)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Verify the relationship is defined.
|
||||
// -----------------------------------------------------
|
||||
if ( ! method_exists($eloquent, $include))
|
||||
{
|
||||
throw new \Exception("Attempting to eager load [$include], but the relationship is not defined.");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Eagerly load the relationship.
|
||||
// -----------------------------------------------------
|
||||
static::eagerly($eloquent, $include, $results);
|
||||
}
|
||||
}
|
||||
@ -49,34 +43,17 @@ class Hydrate {
|
||||
*/
|
||||
private static function base($class, $models)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Initialize the hydrated model array.
|
||||
// -----------------------------------------------------
|
||||
$results = array();
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Hydrate the models from the results.
|
||||
// -----------------------------------------------------
|
||||
foreach ($models as $model)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Instantiate a new model instance.
|
||||
// -----------------------------------------------------
|
||||
$result = new $class;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the model's attributes.
|
||||
// -----------------------------------------------------
|
||||
$result->attributes = (array) $model;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Indicate that the model already exists.
|
||||
// -----------------------------------------------------
|
||||
$result->exists = true;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Add the hydrated model to the array of models.
|
||||
// The array is keyed by the primary keys of the models.
|
||||
// The results are keyed by the ID on the record.
|
||||
// -----------------------------------------------------
|
||||
$results[$result->id] = $result;
|
||||
}
|
||||
@ -107,13 +84,9 @@ class Hydrate {
|
||||
unset($eloquent->attributes[$spoof]);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Reset the WHERE clause on the query.
|
||||
// Reset the WHERE clause and bindings on the query.
|
||||
// -----------------------------------------------------
|
||||
$model->query->where = 'WHERE 1 = 1';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Reset the bindings on the query.
|
||||
// -----------------------------------------------------
|
||||
$model->query->bindings = array();
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -124,23 +97,14 @@ class Hydrate {
|
||||
$result->ignore[$include] = (strpos($eloquent->relating, 'has_many') === 0) ? array() : null;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Eagerly load a 1:1 or 1:* relationship.
|
||||
// -----------------------------------------------------
|
||||
if ($eloquent->relating == 'has_one' or $eloquent->relating == 'has_many')
|
||||
{
|
||||
static::eagerly_load_one_or_many($eloquent->relating_key, $eloquent->relating, $include, $model, $results);
|
||||
}
|
||||
// -----------------------------------------------------
|
||||
// Eagerly load a 1:1 (belonging) relationship.
|
||||
// -----------------------------------------------------
|
||||
elseif ($eloquent->relating == 'belongs_to')
|
||||
{
|
||||
static::eagerly_load_belonging($eloquent->relating_key, $include, $model, $results);
|
||||
}
|
||||
// -----------------------------------------------------
|
||||
// Eagerly load a *:* relationship.
|
||||
// -----------------------------------------------------
|
||||
else
|
||||
{
|
||||
static::eagerly_load_many_to_many($eloquent->relating_key, $eloquent->relating_table, strtolower(get_class($eloquent)).'_id', $include, $model, $results);
|
||||
|
@ -11,14 +11,7 @@ class Relate {
|
||||
*/
|
||||
public static function has_one($model, $eloquent)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Set the relating type.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating = __FUNCTION__;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the Eloquent model.
|
||||
// -----------------------------------------------------
|
||||
return static::has_one_or_many($model, $eloquent);
|
||||
}
|
||||
|
||||
@ -31,14 +24,7 @@ class Relate {
|
||||
*/
|
||||
public static function has_many($model, $eloquent)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Set the relating type.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating = __FUNCTION__;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the Eloquent model.
|
||||
// -----------------------------------------------------
|
||||
return static::has_one_or_many($model, $eloquent);
|
||||
}
|
||||
|
||||
@ -51,11 +37,7 @@ class Relate {
|
||||
*/
|
||||
private static function has_one_or_many($model, $eloquent)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Set the relating key.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating_key = \System\Str::lower(get_class($eloquent)).'_id';
|
||||
|
||||
return Factory::make($model)->where($eloquent->relating_key, '=', $eloquent->id);
|
||||
}
|
||||
|
||||
@ -69,19 +51,9 @@ class Relate {
|
||||
*/
|
||||
public static function belongs_to($caller, $model, $eloquent)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Set the relating type.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating = __FUNCTION__;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the relating key.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating_key = $caller['function'].'_id';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the Eloquent model.
|
||||
// -----------------------------------------------------
|
||||
return Factory::make($model)->where('id', '=', $eloquent->attributes[$eloquent->relating_key]);
|
||||
}
|
||||
|
||||
@ -98,31 +70,12 @@ class Relate {
|
||||
// Get the models involved in the relationship.
|
||||
// -----------------------------------------------------
|
||||
$models = array(\System\Str::lower($model), \System\Str::lower(get_class($eloquent)));
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Sort the model names involved in the relationship.
|
||||
// -----------------------------------------------------
|
||||
sort($models);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Get the intermediate table name, which is the names
|
||||
// of the two related models alphabetized.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating_table = implode('_', $models);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the relating type.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating = __FUNCTION__;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the relating key.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->relating_key = $eloquent->relating_table.'.'.\System\Str::lower(get_class($eloquent)).'_id';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the Eloquent model.
|
||||
// -----------------------------------------------------
|
||||
return Factory::make($model)
|
||||
->select(Meta::table($model).'.*')
|
||||
->join($eloquent->relating_table, Meta::table($model).'.id', '=', $eloquent->relating_table.'.'.\System\Str::lower($model).'_id')
|
||||
|
@ -6,13 +6,10 @@ class Warehouse {
|
||||
* Save an Eloquent model to the database.
|
||||
*
|
||||
* @param object $eloquent
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public static function store($eloquent)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Get the model name.
|
||||
// -----------------------------------------------------
|
||||
$model = get_class($eloquent);
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -21,30 +18,25 @@ class Warehouse {
|
||||
$eloquent->query = \System\DB\Query::table(Meta::table($model));
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the activity timestamps.
|
||||
// Set the creation and update timestamps.
|
||||
// -----------------------------------------------------
|
||||
if (property_exists($model, 'timestamps') and $model::$timestamps)
|
||||
{
|
||||
static::timestamp($eloquent);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// If the model exists in the database, update it.
|
||||
// Otherwise, insert the model and set the ID.
|
||||
// -----------------------------------------------------
|
||||
if ($eloquent->exists)
|
||||
{
|
||||
return $eloquent->query->where('id', '=', $eloquent->attributes['id'])->update($eloquent->dirty);
|
||||
return ($eloquent->query->where('id', '=', $eloquent->attributes['id'])->update($eloquent->dirty) == 1) ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$eloquent->attributes['id'] = $eloquent->query->insert_get_id($eloquent->attributes);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the existence flag to true.
|
||||
// -----------------------------------------------------
|
||||
$eloquent->exists = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,14 +81,7 @@ class Query {
|
||||
*/
|
||||
public function __construct($table, $connection = null)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Set the database connection name.
|
||||
// ---------------------------------------------------
|
||||
$this->connection = (is_null($connection)) ? \System\Config::get('db.default') : $connection;
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Build the FROM clause.
|
||||
// ---------------------------------------------------
|
||||
$this->from = 'FROM '.$this->wrap($this->table = $table);
|
||||
}
|
||||
|
||||
@ -122,9 +115,6 @@ class Query {
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Handle DISTINCT selections.
|
||||
// ---------------------------------------------------
|
||||
$this->select = ($this->distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
|
||||
|
||||
// ---------------------------------------------------
|
||||
@ -372,15 +362,7 @@ class Query {
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Set the primary key.
|
||||
// ---------------------------------------------------
|
||||
$this->where('id', '=', $id);
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Get the first result.
|
||||
// ---------------------------------------------------
|
||||
return $this->first();
|
||||
return $this->where('id', '=', $id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -400,9 +382,6 @@ class Query {
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Initialize the SELECT clause if it's null.
|
||||
// ---------------------------------------------------
|
||||
if (is_null($this->select))
|
||||
{
|
||||
call_user_func_array(array($this, 'select'), (count(func_get_args()) > 0) ? func_get_args() : array('*'));
|
||||
@ -420,14 +399,8 @@ class Query {
|
||||
*/
|
||||
private function aggregate($aggregator, $column)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Build the SELECT clause.
|
||||
// ---------------------------------------------------
|
||||
$this->select = 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate');
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Execute the statement.
|
||||
// ---------------------------------------------------
|
||||
$results = \System\DB::query(Query\Compiler::select($this), $this->bindings);
|
||||
|
||||
return $results[0]->aggregate;
|
||||
@ -452,54 +425,28 @@ class Query {
|
||||
*/
|
||||
public function insert_get_id($values)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Compile the SQL statement.
|
||||
// ---------------------------------------------------
|
||||
$sql = Query\Compiler::insert($this, $values);
|
||||
|
||||
// ---------------------------------------------------
|
||||
// The Postgres PDO implementation does not cleanly
|
||||
// implement the last insert ID function. So, we'll
|
||||
// use the RETURNING clause available in Postgres.
|
||||
// Postgres.
|
||||
// ---------------------------------------------------
|
||||
if (\System\DB::connection($this->connection)->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql')
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Add the RETURNING clause to the SQL.
|
||||
// ---------------------------------------------------
|
||||
$sql .= ' RETURNING '.$this->wrap('id');
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Prepare the PDO statement.
|
||||
// ---------------------------------------------------
|
||||
$query = \System\DB::connection($this->connection)->prepare($sql);
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Execute the PDO statement.
|
||||
// ---------------------------------------------------
|
||||
$query->execute(array_values($values));
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Fetch the insert ID from the results.
|
||||
// ---------------------------------------------------
|
||||
$result = $query->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
return $result['id'];
|
||||
}
|
||||
// ---------------------------------------------------
|
||||
// When using MySQL or SQLite, we can just use the PDO
|
||||
// last insert ID function.
|
||||
// MySQL and SQLite.
|
||||
// ---------------------------------------------------
|
||||
else
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Execute the statement.
|
||||
// ---------------------------------------------------
|
||||
\System\DB::query($sql, array_values($values), $this->connection);
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Get the last insert ID.
|
||||
// ---------------------------------------------------
|
||||
return \System\DB::connection($this->connection)->lastInsertId();
|
||||
}
|
||||
}
|
||||
@ -523,17 +470,11 @@ class Query {
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Set the primary key.
|
||||
// ---------------------------------------------------
|
||||
if ( ! is_null($id))
|
||||
{
|
||||
$this->where('id', '=', $id);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Execute the statement.
|
||||
// ---------------------------------------------------
|
||||
return \System\DB::query(Query\Compiler::delete($this), $this->bindings, $this->connection);
|
||||
}
|
||||
|
||||
@ -555,9 +496,6 @@ class Query {
|
||||
$wrap = '`';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Wrap the element in keyword identifiers.
|
||||
// ---------------------------------------------------
|
||||
return implode('.', array_map(function($segment) use ($wrap) {return ($segment != '*') ? $wrap.$segment.$wrap : $segment;}, explode('.', $value)));
|
||||
}
|
||||
|
||||
|
@ -10,30 +10,18 @@ class Compiler {
|
||||
*/
|
||||
public static function select($query)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Add the SELECT, FROM, and WHERE clauses.
|
||||
// ---------------------------------------------------
|
||||
$sql = $query->select.' '.$query->from.' '.$query->where;
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Add the ORDER BY clause.
|
||||
// ---------------------------------------------------
|
||||
if (count($query->orderings) > 0)
|
||||
{
|
||||
$sql .= ' ORDER BY '.implode(', ', $query->orderings);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Add the LIMIT.
|
||||
// ---------------------------------------------------
|
||||
if ( ! is_null($query->limit))
|
||||
{
|
||||
$sql .= ' LIMIT '.$query->limit;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Add the OFFSET.
|
||||
// ---------------------------------------------------
|
||||
if ( ! is_null($query->offset))
|
||||
{
|
||||
$sql .= ' OFFSET '.$query->offset;
|
||||
@ -51,9 +39,6 @@ class Compiler {
|
||||
*/
|
||||
public static function insert($query, $values)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Start the query. Add the table name.
|
||||
// ---------------------------------------------------
|
||||
$sql = 'INSERT INTO '.$query->table.' (';
|
||||
|
||||
// ---------------------------------------------------
|
||||
@ -66,9 +51,6 @@ class Compiler {
|
||||
$columns[] = $query->wrap($column);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Concatenate the column names and values.
|
||||
// ---------------------------------------------------
|
||||
return $sql .= implode(', ', $columns).') VALUES ('.$query->parameterize($values).')';
|
||||
}
|
||||
|
||||
@ -81,13 +63,10 @@ class Compiler {
|
||||
*/
|
||||
public static function update($query, $values)
|
||||
{
|
||||
// ---------------------------------------------------
|
||||
// Start the query. Add the table name.
|
||||
// ---------------------------------------------------
|
||||
$sql = 'UPDATE '.$query->table.' SET ';
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Wrap each column name in keyword identifiers.
|
||||
// Add each column set the query.
|
||||
// ---------------------------------------------------
|
||||
$columns = array();
|
||||
|
||||
@ -96,9 +75,6 @@ class Compiler {
|
||||
$columns[] = $query->wrap($column).' = ?';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// Concatenate the column names and the WHERE clause.
|
||||
// ---------------------------------------------------
|
||||
return $sql .= implode(', ', $columns).' '.$query->where;
|
||||
}
|
||||
|
||||
|
@ -109,17 +109,11 @@ class Download {
|
||||
*/
|
||||
public static function file($path, $name = null)
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// If no name was specified, just use the basename.
|
||||
// -------------------------------------------------
|
||||
if (is_null($name))
|
||||
{
|
||||
$name = basename($path);
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// Set the headers to force the download to occur.
|
||||
// -------------------------------------------------
|
||||
return Response::make(file_get_contents($path))->header('Content-Description', 'File Transfer')
|
||||
->header('Content-Type', static::mime(pathinfo($path, PATHINFO_EXTENSION)))
|
||||
->header('Content-Disposition', 'attachment; filename="'.$name.'"')
|
||||
|
@ -72,9 +72,6 @@ class Error {
|
||||
|
||||
if (Config::get('error.detail'))
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Build the error view.
|
||||
// -----------------------------------------------------
|
||||
$view = View::make('error/exception')
|
||||
->bind('severity', $severity)
|
||||
->bind('message', $message)
|
||||
@ -83,16 +80,10 @@ class Error {
|
||||
->bind('trace', $e->getTraceAsString())
|
||||
->bind('contexts', static::context($file, $e->getLine()));
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Send the detailed error response.
|
||||
// -----------------------------------------------------
|
||||
Response::make($view, 500)->send();
|
||||
}
|
||||
else
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Send the generic error response.
|
||||
// -----------------------------------------------------
|
||||
Response::make(View::make('error/500'), 500)->send();
|
||||
}
|
||||
|
||||
@ -109,19 +100,10 @@ class Error {
|
||||
*/
|
||||
private static function context($path, $line, $padding = 5)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Verify that the file exists.
|
||||
// -----------------------------------------------------
|
||||
if (file_exists($path))
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Get the contents of the file.
|
||||
// -----------------------------------------------------
|
||||
$file = file($path, FILE_IGNORE_NEW_LINES);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Unshift the array.
|
||||
// -----------------------------------------------------
|
||||
array_unshift($file, '');
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -144,9 +126,6 @@ class Error {
|
||||
$length = null;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Return the context.
|
||||
// -----------------------------------------------------
|
||||
return array_slice($file, $start, $length, true);
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,6 @@ class Filter {
|
||||
*/
|
||||
public static function call($filters, $parameters = array())
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Load the route filters.
|
||||
// --------------------------------------------------------------
|
||||
if (is_null(static::$filters))
|
||||
{
|
||||
static::$filters = require APP_PATH.'filters'.EXT;
|
||||
@ -28,9 +25,6 @@ class Filter {
|
||||
|
||||
foreach (explode(', ', $filters) as $filter)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Verify that the filter is defined.
|
||||
// --------------------------------------------------------------
|
||||
if ( ! isset(static::$filters[$filter]))
|
||||
{
|
||||
throw new \Exception("Route filter [$filter] is not defined.");
|
||||
@ -39,7 +33,8 @@ class Filter {
|
||||
$response = call_user_func_array(static::$filters[$filter], $parameters);
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// If the filter returned a response, return it.
|
||||
// If the filter returned a response, return it since route
|
||||
// filters can override route methods.
|
||||
// --------------------------------------------------------------
|
||||
if ( ! is_null($response))
|
||||
{
|
||||
|
@ -20,32 +20,16 @@ class Form {
|
||||
$action = Request::uri();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Prepare the action URL.
|
||||
// -------------------------------------------------------
|
||||
$action = URL::to($action);
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the action attribute.
|
||||
// -------------------------------------------------------
|
||||
$attributes['action'] = $action;
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the method attribute.
|
||||
// -------------------------------------------------------
|
||||
$attributes['method'] = ($method == 'GET' or $method == 'POST') ? $method : 'POST';
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the default character set.
|
||||
// -------------------------------------------------------
|
||||
if ( ! array_key_exists('accept-charset', $attributes))
|
||||
{
|
||||
$attributes['accept-charset'] = 'UTF-8';
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Build the form tag.
|
||||
// -------------------------------------------------------
|
||||
$html = '<form'.HTML::attributes($attributes).'>';
|
||||
|
||||
// -------------------------------------------------------
|
||||
@ -79,9 +63,6 @@ class Form {
|
||||
*/
|
||||
public static function raw_token()
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Verify that sessions are enabled.
|
||||
// -------------------------------------------------------
|
||||
if (Config::get('session.driver') == '')
|
||||
{
|
||||
throw new \Exception('Sessions must be enabled to retrieve a CSRF token.');
|
||||
@ -204,9 +185,6 @@ class Form {
|
||||
*/
|
||||
private static function checkable($type, $name, $value, $checked, $attributes)
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Set the checked attribute.
|
||||
// -------------------------------------------------------
|
||||
if ($checked === true)
|
||||
{
|
||||
$attributes['checked'] = 'checked';
|
||||
@ -225,9 +203,6 @@ class Form {
|
||||
*/
|
||||
public static function textarea($name, $value = '', $attributes = array())
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Add the name to the attributes.
|
||||
// -------------------------------------------------------
|
||||
$attributes['name'] = $name;
|
||||
|
||||
// -------------------------------------------------------
|
||||
@ -260,36 +235,17 @@ class Form {
|
||||
*/
|
||||
public static function select($name, $options = array(), $selected = null, $attributes = array())
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Set the name attribute.
|
||||
// -------------------------------------------------------
|
||||
$attributes['name'] = $name;
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Initialize the options array.
|
||||
// -------------------------------------------------------
|
||||
$html_options = array();
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Build the options in HTML.
|
||||
// -------------------------------------------------------
|
||||
foreach ($options as $value => $display)
|
||||
{
|
||||
$option_attributes = array();
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the value attribute.
|
||||
// -------------------------------------------------------
|
||||
$option_attributes['value'] = $value;
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the selected attribute.
|
||||
// -------------------------------------------------------
|
||||
$option_attributes['selected'] = ($value == $selected) ? 'selected' : null;
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Add the option HTML to the array of options.
|
||||
// -------------------------------------------------------
|
||||
$html_options[] = '<option'.HTML::attributes($option_attributes).'>'.$display.'</option>';
|
||||
}
|
||||
|
||||
@ -306,19 +262,8 @@ class Form {
|
||||
*/
|
||||
private static function input($type, $name, $value = null, $attributes = array())
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Set the type attribute.
|
||||
// -------------------------------------------------------
|
||||
$attributes['type'] = $type;
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the name attribute.
|
||||
// -------------------------------------------------------
|
||||
$attributes['name'] = $name;
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Set the value attribute.
|
||||
// -------------------------------------------------------
|
||||
$attributes['value'] = $value;
|
||||
|
||||
return '<input'.HTML::attributes($attributes).' />'.PHP_EOL;
|
||||
|
@ -25,14 +25,7 @@ class Hash {
|
||||
*/
|
||||
public function __construct($value, $salt = null)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Get a random salt to hash the value with.
|
||||
// --------------------------------------------------------------
|
||||
$this->salt = (is_null($salt)) ? Str::random(16) : $salt;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Perform a salted, SHA-1 hash on the value.
|
||||
// --------------------------------------------------------------
|
||||
$this->value = sha1($value.$this->salt);
|
||||
}
|
||||
|
||||
|
@ -66,9 +66,6 @@ class HTML {
|
||||
// -------------------------------------------------------
|
||||
$email = static::email($email);
|
||||
|
||||
// -------------------------------------------------------
|
||||
// If no title is specified, just use the e-mail address.
|
||||
// -------------------------------------------------------
|
||||
if (is_null($title))
|
||||
{
|
||||
$title = $email;
|
||||
@ -98,11 +95,7 @@ class HTML {
|
||||
*/
|
||||
public static function image($url, $alt = '', $attributes = array())
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Add the "alt" tag to the attributes.
|
||||
// -------------------------------------------------------
|
||||
$attributes['alt'] = Str::entities($alt);
|
||||
|
||||
return '<img src="'.URL::to($url).'"'.static::attributes($attributes).' />';
|
||||
}
|
||||
|
||||
@ -162,33 +155,19 @@ class HTML {
|
||||
*/
|
||||
private static function list_elements($type, $list, $attributes)
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Verify the list is an array.
|
||||
// -------------------------------------------------------
|
||||
if ( ! is_array($list))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Initialize the output value.
|
||||
// -------------------------------------------------------
|
||||
$html = '';
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Add the list items.
|
||||
// -------------------------------------------------------
|
||||
foreach ($list as $key => $value)
|
||||
{
|
||||
$html .= '<li>'.Str::entities($value).'</li>';
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Build the list opening tag.
|
||||
// -------------------------------------------------------
|
||||
$start = '<'.$type.static::attributes($attributes).'>';
|
||||
|
||||
return $start.$html.'</'.$type.'>';
|
||||
return '<'.$type.static::attributes($attributes).'>'.$html.'</'.$type.'>';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,23 +182,12 @@ class HTML {
|
||||
|
||||
foreach ($attributes as $key => $value)
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// If the value is null, skip it.
|
||||
// -------------------------------------------------------
|
||||
if (is_null($value))
|
||||
if ( ! is_null($value))
|
||||
{
|
||||
continue;
|
||||
$html[] = $key.'="'.Str::entities($value).'"';
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Add the HTML attribute to the array of attributes.
|
||||
// -------------------------------------------------------
|
||||
$html[] = $key.'="'.Str::entities($value).'"';
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Concatenate all of the attributes together.
|
||||
// -------------------------------------------------------
|
||||
if (count($html) > 0)
|
||||
{
|
||||
return ' '.implode(' ', $html);
|
||||
|
@ -121,9 +121,6 @@ class Inflector {
|
||||
*/
|
||||
public static function plural($value)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Have we already converted this word?
|
||||
// -----------------------------------------------------
|
||||
if (array_key_exists($value, static::$plural_cache))
|
||||
{
|
||||
return static::$plural_cache[$value];
|
||||
@ -172,9 +169,6 @@ class Inflector {
|
||||
*/
|
||||
public static function singular($value)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Have we already converted this word?
|
||||
// -----------------------------------------------------
|
||||
if (array_key_exists($value, static::$singular_cache))
|
||||
{
|
||||
return static::$singular_cache[$value];
|
||||
|
@ -40,11 +40,7 @@ class Input {
|
||||
*/
|
||||
public static function get($key = null, $default = null)
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// Hydrate the input data for the request.
|
||||
// -------------------------------------------------
|
||||
static::hydrate();
|
||||
|
||||
return static::from_array(static::$input, $key, $default);
|
||||
}
|
||||
|
||||
@ -57,9 +53,6 @@ class Input {
|
||||
*/
|
||||
public static function old($key = null, $default = null)
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// Verify that sessions are enabled.
|
||||
// -------------------------------------------------
|
||||
if (Config::get('session.driver') == '')
|
||||
{
|
||||
throw new \Exception("Sessions must be enabled to retrieve old input data.");
|
||||
@ -69,7 +62,7 @@ class Input {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an array.
|
||||
* Get an item from an array. If no key is specified, the entire array will be returned.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
@ -78,9 +71,6 @@ class Input {
|
||||
*/
|
||||
private static function from_array($array, $key, $default)
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// If no key is given, return the entire array.
|
||||
// -------------------------------------------------
|
||||
if (is_null($key))
|
||||
{
|
||||
return $array;
|
||||
|
@ -60,22 +60,13 @@ class Lang {
|
||||
*/
|
||||
public function get($language = null)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// If no language was specified, use the default language.
|
||||
// --------------------------------------------------------------
|
||||
if (is_null($language))
|
||||
{
|
||||
$language = Config::get('application.language');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Extract the file and item from the key.
|
||||
// --------------------------------------------------------------
|
||||
list($file, $line) = $this->parse($this->key);
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Load the language file.
|
||||
// --------------------------------------------------------------
|
||||
$this->load($file, $language);
|
||||
|
||||
// --------------------------------------------------------------
|
||||
@ -109,22 +100,13 @@ class Lang {
|
||||
*/
|
||||
private function parse($key)
|
||||
{
|
||||
// ---------------------------------------------
|
||||
// Get the key segments.
|
||||
// ---------------------------------------------
|
||||
$segments = explode('.', $key);
|
||||
|
||||
// ---------------------------------------------
|
||||
// Validate the key format.
|
||||
// ---------------------------------------------
|
||||
if (count($segments) < 2)
|
||||
{
|
||||
throw new \Exception("Invalid language key [$key].");
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
// Return the file and item name.
|
||||
// ---------------------------------------------
|
||||
return array($segments[0], implode('.', array_slice($segments, 1)));
|
||||
}
|
||||
|
||||
@ -137,16 +119,13 @@ class Lang {
|
||||
*/
|
||||
private function load($file, $language)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Do not load the file if it has already been loaded.
|
||||
// --------------------------------------------------------------
|
||||
if (in_array($language.$file, static::$loaded))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Does the language file exist?
|
||||
// Load the language file into the array of lines.
|
||||
// --------------------------------------------------------------
|
||||
if (file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT))
|
||||
{
|
||||
@ -157,9 +136,6 @@ class Lang {
|
||||
throw new \Exception("Language file [$file] does not exist for language [$language].");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Add the file to the array of loaded files.
|
||||
// --------------------------------------------------------------
|
||||
static::$loaded[] = $language.$file;
|
||||
}
|
||||
|
||||
|
@ -18,30 +18,18 @@ return function($class) {
|
||||
return class_alias($aliases[$class], $class);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Check for the class in the system directory.
|
||||
// ----------------------------------------------------------
|
||||
if (file_exists($path = BASE_PATH.$file.EXT))
|
||||
{
|
||||
require $path;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
// Check for the class in the models directory.
|
||||
// ----------------------------------------------------------
|
||||
elseif (file_exists($path = APP_PATH.'models/'.$file.EXT))
|
||||
{
|
||||
require $path;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
// Check for the class in the packages directory.
|
||||
// ----------------------------------------------------------
|
||||
elseif (file_exists($path = APP_PATH.'packages/'.$file.EXT))
|
||||
{
|
||||
require $path;
|
||||
}
|
||||
// ----------------------------------------------------------
|
||||
// Check for the class in the application directory.
|
||||
// ----------------------------------------------------------
|
||||
elseif (file_exists($path = APP_PATH.$file.EXT))
|
||||
{
|
||||
require $path;
|
||||
|
@ -69,14 +69,7 @@ class Log {
|
||||
// -----------------------------------------------------
|
||||
$file = $directory.'/'.date('d').EXT;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Write the message to the log.
|
||||
// -----------------------------------------------------
|
||||
file_put_contents($file, date('Y-m-d H:i:s').' '.$type.' - '.$message.PHP_EOL, LOCK_EX | FILE_APPEND);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the log file permissions.
|
||||
// -----------------------------------------------------
|
||||
chmod($file, 0666);
|
||||
}
|
||||
|
||||
@ -88,14 +81,7 @@ class Log {
|
||||
*/
|
||||
private static function make_directory($directory)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Create the directory.
|
||||
// -----------------------------------------------------
|
||||
mkdir($directory, 02777);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the directory permissions.
|
||||
// -----------------------------------------------------
|
||||
chmod($directory, 02777);
|
||||
}
|
||||
|
||||
|
@ -18,17 +18,11 @@ class Memcached {
|
||||
{
|
||||
if (is_null(static::$instance))
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Verify that the Memcache extension is installed.
|
||||
// -----------------------------------------------------
|
||||
if ( ! class_exists('Memcache'))
|
||||
{
|
||||
throw new \Exception('Attempting to use Memcached, but the Memcached PHP extension is not installed on this server.');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Instantiate the Memcache class.
|
||||
// -----------------------------------------------------
|
||||
$memcache = new \Memcache;
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
@ -13,14 +13,8 @@ class Redirect {
|
||||
*/
|
||||
public static function to($url, $method = 'location', $status = 302, $https = false)
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// Prepare the URL.
|
||||
// -------------------------------------------------
|
||||
$url = URL::to($url, $https);
|
||||
|
||||
// -------------------------------------------------
|
||||
// Return the redirect response.
|
||||
// -------------------------------------------------
|
||||
return ($method == 'refresh')
|
||||
? Response::make('', $status)->header('Refresh', '0;url='.$url)
|
||||
: Response::make('', $status)->header('Location', $url);
|
||||
|
@ -16,33 +16,21 @@ class Request {
|
||||
*/
|
||||
public static function uri()
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Have we already determined the URI?
|
||||
// --------------------------------------------------------------
|
||||
if ( ! is_null(static::$uri))
|
||||
{
|
||||
return static::$uri;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Use the PATH_INFO variable if it is available.
|
||||
// --------------------------------------------------------------
|
||||
if (isset($_SERVER['PATH_INFO']))
|
||||
{
|
||||
return static::$uri = static::tidy($_SERVER['PATH_INFO']);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// If the server REQUEST_URI variable is not available, bail out.
|
||||
// --------------------------------------------------------------
|
||||
if ( ! isset($_SERVER['REQUEST_URI']))
|
||||
{
|
||||
throw new \Exception('Unable to determine the request URI.');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Get the PHP_URL_PATH of the request URI.
|
||||
// --------------------------------------------------------------
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
@ -120,9 +120,6 @@ class Response {
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// Set the content type if it has not been set.
|
||||
// -------------------------------------------------
|
||||
if ( ! array_key_exists('Content-Type', $this->headers))
|
||||
{
|
||||
$this->header('Content-Type', 'text/html; charset=utf-8');
|
||||
@ -133,16 +130,10 @@ class Response {
|
||||
// -------------------------------------------------
|
||||
if ( ! headers_sent())
|
||||
{
|
||||
// -------------------------------------------------
|
||||
// Send the HTTP protocol and status code.
|
||||
// -------------------------------------------------
|
||||
$protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
|
||||
|
||||
header($protocol.' '.$this->status.' '.$this->statuses[$this->status]);
|
||||
|
||||
// -------------------------------------------------
|
||||
// Send the rest of the headers.
|
||||
// -------------------------------------------------
|
||||
foreach ($this->headers as $name => $value)
|
||||
{
|
||||
header($name.': '.$value, true);
|
||||
|
@ -66,9 +66,6 @@ class Route {
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Make sure the response is a Response instance.
|
||||
// --------------------------------------------------------------
|
||||
$response = ( ! $response instanceof Response) ? new Response($response) : $response;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
@ -26,13 +26,10 @@ class Router {
|
||||
public static function route($method, $uri)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Add a forward slash to the URI if necessary.
|
||||
// Force the URI to have a forward slash.
|
||||
// --------------------------------------------------------------
|
||||
$uri = ($uri != '/') ? '/'.$uri : $uri;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Load all of the application routes.
|
||||
// --------------------------------------------------------------
|
||||
static::$routes = require APP_PATH.'routes'.EXT;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
@ -54,19 +51,10 @@ class Router {
|
||||
// --------------------------------------------------------------
|
||||
if (strpos($keys, '(') !== false or strpos($keys, ',') !== false )
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Multiple routes can be assigned to a callback using commas.
|
||||
// --------------------------------------------------------------
|
||||
foreach (explode(', ', $keys) as $route)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
// Change wildcards into regular expressions.
|
||||
// --------------------------------------------------------------
|
||||
$route = str_replace(':num', '[0-9]+', str_replace(':any', '.+', $route));
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Test the route for a match.
|
||||
// --------------------------------------------------------------
|
||||
if (preg_match('#^'.$route.'$#', $method.' '.$uri))
|
||||
{
|
||||
return new Route($callback, static::parameters(explode('/', $uri), explode('/', $route)));
|
||||
@ -84,28 +72,14 @@ class Router {
|
||||
*/
|
||||
public static function find($name)
|
||||
{
|
||||
// ----------------------------------------------------
|
||||
// Have we already looked up this named route?
|
||||
// ----------------------------------------------------
|
||||
if (array_key_exists($name, static::$names))
|
||||
{
|
||||
return static::$names[$name];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Instantiate the recursive array iterator.
|
||||
// ----------------------------------------------------
|
||||
$arrayIterator = new \RecursiveArrayIterator(static::$routes);
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Instantiate the recursive iterator iterator.
|
||||
// ----------------------------------------------------
|
||||
$recursiveIterator = new \RecursiveIteratorIterator($arrayIterator);
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Iterate through the routes searching for a route
|
||||
// name that matches the given name.
|
||||
// ----------------------------------------------------
|
||||
foreach ($recursiveIterator as $iterator)
|
||||
{
|
||||
$route = $recursiveIterator->getSubIterator();
|
||||
@ -128,9 +102,6 @@ class Router {
|
||||
{
|
||||
$parameters = array();
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// Spin through the route segments looking for parameters.
|
||||
// --------------------------------------------------------------
|
||||
for ($i = 0; $i < count($route_segments); $i++)
|
||||
{
|
||||
// --------------------------------------------------------------
|
||||
|
@ -63,9 +63,6 @@ class Session {
|
||||
static::put('csrf_token', Str::random(16));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the last activity timestamp for the user.
|
||||
// -----------------------------------------------------
|
||||
static::$session['last_activity'] = time();
|
||||
}
|
||||
|
||||
@ -120,14 +117,8 @@ class Session {
|
||||
*/
|
||||
public static function once($key, $default = null)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Get the item from the session.
|
||||
// -----------------------------------------------------
|
||||
$value = static::get($key, $default);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Delete the item from the session.
|
||||
// -----------------------------------------------------
|
||||
static::forget($key);
|
||||
|
||||
return $value;
|
||||
@ -185,14 +176,7 @@ class Session {
|
||||
*/
|
||||
public static function regenerate()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Delete the old session from storage.
|
||||
// -----------------------------------------------------
|
||||
static::driver()->delete(static::$session['id']);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Create a new session ID.
|
||||
// -----------------------------------------------------
|
||||
static::$session['id'] = Str::random(40);
|
||||
}
|
||||
|
||||
@ -203,31 +187,17 @@ class Session {
|
||||
*/
|
||||
public static function close()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Flash the old input data to the session.
|
||||
// -----------------------------------------------------
|
||||
static::flash('laravel_old_input', Input::get());
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Age the session flash data.
|
||||
// -----------------------------------------------------
|
||||
static::age_flash();
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Save the session to storage.
|
||||
// -----------------------------------------------------
|
||||
static::driver()->save(static::$session);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Set the session cookie.
|
||||
// -----------------------------------------------------
|
||||
if ( ! headers_sent())
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Calculate the cookie lifetime.
|
||||
// -----------------------------------------------------
|
||||
$lifetime = (Config::get('session.expire_on_close')) ? 0 : Config::get('session.lifetime');
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Write the session cookie.
|
||||
// -----------------------------------------------------
|
||||
Cookie::put('laravel_session', static::$session['id'], $lifetime, Config::get('session.path'), Config::get('session.domain'), Config::get('session.https'));
|
||||
}
|
||||
|
||||
|
@ -10,14 +10,8 @@ class DB implements \System\Session\Driver {
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Find the session in the database.
|
||||
// -----------------------------------------------------
|
||||
$session = $this->query()->find($id);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// If the session was found, return it.
|
||||
// -----------------------------------------------------
|
||||
if ( ! is_null($session))
|
||||
{
|
||||
return array('id' => $session->id, 'last_activity' => $session->last_activity, 'data' => unserialize($session->data));
|
||||
@ -32,14 +26,7 @@ class DB implements \System\Session\Driver {
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Delete the existing session row.
|
||||
// -----------------------------------------------------
|
||||
$this->delete($session['id']);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Insert a new session row.
|
||||
// -----------------------------------------------------
|
||||
$this->query()->insert(array('id' => $session['id'], 'last_activity' => $session['last_activity'], 'data' => serialize($session['data'])));
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,6 @@ class File implements \System\Session\Driver {
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Look for the session on the file system.
|
||||
// -----------------------------------------------------
|
||||
if (file_exists($path = APP_PATH.'sessions/'.$id))
|
||||
{
|
||||
return unserialize(file_get_contents($path));
|
||||
@ -51,9 +48,6 @@ class File implements \System\Session\Driver {
|
||||
{
|
||||
foreach (glob(APP_PATH.'sessions/*') as $file)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// If the session file has expired, delete it.
|
||||
// -----------------------------------------------------
|
||||
if (filetype($file) == 'file' and filemtime($file) < $expiration)
|
||||
{
|
||||
@unlink($file);
|
||||
|
@ -61,19 +61,10 @@ class Str {
|
||||
*/
|
||||
public static function random($length = 16)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Split the character pool into an array.
|
||||
// -----------------------------------------------------
|
||||
$pool = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 1);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Initialize the return value.
|
||||
// -----------------------------------------------------
|
||||
$value = '';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Build the random string.
|
||||
// -----------------------------------------------------
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$value .= $pool[mt_rand(0, 61)];
|
||||
|
65
system/test.php
Normal file
65
system/test.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php namespace System;
|
||||
|
||||
class Test {
|
||||
|
||||
/**
|
||||
* All of the test results.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $results = array();
|
||||
|
||||
/**
|
||||
* Total number of tests being run.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $total = 0;
|
||||
|
||||
/**
|
||||
* Total number of passed tests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $passed = 0;
|
||||
|
||||
/**
|
||||
* Run a test suite.
|
||||
*
|
||||
* @param string $suite
|
||||
* @param array $tests
|
||||
* @return void
|
||||
*/
|
||||
public static function run($suite, $tests)
|
||||
{
|
||||
static::$total = static::$total + count($tests);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Run each test in the suite.
|
||||
// -----------------------------------------------------
|
||||
foreach ($tests as $name => $test)
|
||||
{
|
||||
if ( ! is_callable($test))
|
||||
{
|
||||
throw new \Exception("Test [$name] in suite [$suite] is not callable.");
|
||||
}
|
||||
|
||||
static::$passed = ($result = call_user_func($test)) ? static::$passed + 1 : static::$passed;
|
||||
static::$results[$suite][] = array('name' => $name, 'result' => $result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the test report view.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public static function report()
|
||||
{
|
||||
return View::make('test/report')
|
||||
->bind('results', static::$results)
|
||||
->bind('passed', static::$passed)
|
||||
->bind('total', static::$total);
|
||||
}
|
||||
|
||||
}
|
0
system/tests/.gitignore
vendored
Normal file
0
system/tests/.gitignore
vendored
Normal file
@ -12,9 +12,6 @@ class Text {
|
||||
*/
|
||||
public static function words($value, $limit, $end = '…')
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// If the value is an empty string, bail out.
|
||||
// -----------------------------------------------------
|
||||
if (trim($value) == '')
|
||||
{
|
||||
return $value;
|
||||
@ -34,9 +31,6 @@ class Text {
|
||||
$end = '';
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Add the ending character to the string.
|
||||
// -----------------------------------------------------
|
||||
return rtrim($matches[0]).$end;
|
||||
}
|
||||
|
||||
@ -50,9 +44,6 @@ class Text {
|
||||
*/
|
||||
public static function characters($value, $limit, $end = '…')
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// If the value does not exceed the limit, bail out.
|
||||
// -----------------------------------------------------
|
||||
if (strlen($value) < $limit)
|
||||
{
|
||||
return $value;
|
||||
@ -63,17 +54,11 @@ class Text {
|
||||
// -----------------------------------------------------
|
||||
$value = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $value));
|
||||
|
||||
// -----------------------------------------------------
|
||||
// If the value does not exceed the limit, bail out.
|
||||
// -----------------------------------------------------
|
||||
if (strlen($value) <= $limit)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Initialize the output string.
|
||||
// -----------------------------------------------------
|
||||
$out = '';
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -82,24 +67,12 @@ class Text {
|
||||
// -----------------------------------------------------
|
||||
foreach (explode(' ', trim($value)) as $val)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Add the word to the output.
|
||||
// -----------------------------------------------------
|
||||
$out .= $val.' ';
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Check the output length.
|
||||
// -----------------------------------------------------
|
||||
if (strlen($out) >= $limit)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Trim the output.
|
||||
// -----------------------------------------------------
|
||||
$out = trim($out);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Add the ending character to the string.
|
||||
// -----------------------------------------------------
|
||||
return (strlen($out) == strlen($value)) ? $out : $out.$end;
|
||||
}
|
||||
}
|
||||
@ -115,9 +88,6 @@ class Text {
|
||||
*/
|
||||
public static function censor($value, $censored, $replacement = '####')
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Pad the value with spaces.
|
||||
// -----------------------------------------------------
|
||||
$value = ' '.$value.' ';
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
@ -18,9 +18,6 @@ class URL {
|
||||
return $url;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Get the base URL of the application.
|
||||
// ----------------------------------------------------
|
||||
$base = Config::get('application.url');
|
||||
|
||||
// ----------------------------------------------------
|
||||
@ -55,9 +52,6 @@ class URL {
|
||||
*/
|
||||
public static function to_route($name, $parameters = array(), $https = false)
|
||||
{
|
||||
// ----------------------------------------------------
|
||||
// Does the named route exist?
|
||||
// ----------------------------------------------------
|
||||
if ( ! is_null($route = Router::find($name)))
|
||||
{
|
||||
$uris = explode(', ', key($route));
|
||||
|
@ -41,10 +41,6 @@ class View {
|
||||
{
|
||||
$this->view = $view;
|
||||
$this->data = $data;
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Get the contents of the view from the file system.
|
||||
// -----------------------------------------------------
|
||||
$this->content = $this->load($view);
|
||||
}
|
||||
|
||||
@ -68,23 +64,14 @@ class View {
|
||||
*/
|
||||
private function load($view)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Is the view in the application directory?
|
||||
// -----------------------------------------------------
|
||||
if (file_exists($path = APP_PATH.'views/'.$view.EXT))
|
||||
{
|
||||
return file_get_contents($path);
|
||||
}
|
||||
// -----------------------------------------------------
|
||||
// Is the view in the system directory?
|
||||
// -----------------------------------------------------
|
||||
elseif (file_exists($path = SYS_PATH.'views/'.$view.EXT))
|
||||
{
|
||||
return file_get_contents($path);
|
||||
}
|
||||
// -----------------------------------------------------
|
||||
// Could not locate the view... bail out.
|
||||
// -----------------------------------------------------
|
||||
else
|
||||
{
|
||||
throw new \Exception("View [$view] doesn't exist.");
|
||||
@ -111,9 +98,6 @@ class View {
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Set the name of the last rendered view.
|
||||
// -----------------------------------------------------
|
||||
static::$last = $this->view;
|
||||
|
||||
// -----------------------------------------------------
|
||||
@ -127,24 +111,12 @@ class View {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Extract the view data into the local scope.
|
||||
// -----------------------------------------------------
|
||||
extract($this->data, EXTR_SKIP);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Start an output buffer to catch the content.
|
||||
// -----------------------------------------------------
|
||||
ob_start();
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Echo the content of the view.
|
||||
// -----------------------------------------------------
|
||||
echo eval('?>'.$this->content);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Get the contents of the output buffer.
|
||||
// -----------------------------------------------------
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
font-size: 45px;
|
||||
color: #6d6d6d;
|
||||
margin: 0 0 10px 0;
|
||||
text-shadow: 1px 1px #000;
|
||||
}
|
||||
|
||||
h3 {
|
||||
|
80
system/views/test/report.php
Normal file
80
system/views/test/report.php
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Laravel - Test Report</title>
|
||||
|
||||
<link href='http://fonts.googleapis.com/css?family=Ubuntu&subset=latin' rel='stylesheet' type='text/css'>
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-color: #fff;
|
||||
font-family: 'Ubuntu', sans-serif;
|
||||
font-size: 18px;
|
||||
color: #3f3f3f;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 35px;
|
||||
color: #6d6d6d;
|
||||
margin: 0 0 10px 0;
|
||||
text-shadow: 1px 1px #000;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 25px;
|
||||
color: #6d6d6d;
|
||||
text-shadow: 1px 1px #000;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 20px;
|
||||
color: #6d6d6d;
|
||||
text-shadow: 1px 1px #000;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.content {
|
||||
padding: 10px 10px 10px 10px;
|
||||
background-color: #eee;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
div.basic {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
div.passed {
|
||||
background-color: #d8f5cf;
|
||||
}
|
||||
|
||||
div.failed {
|
||||
background-color: #ffebe8;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<h1>Test Report</h1>
|
||||
|
||||
<h2>Passed <?php echo $passed; ?> / <?php echo $total; ?> Tests</h2>
|
||||
|
||||
<?php foreach ($results as $suite => $results): ?>
|
||||
<h3><?php echo $suite; ?></h3>
|
||||
|
||||
<?php foreach ($results as $result): ?>
|
||||
|
||||
<div class="content <?php echo ($result['result']) ? 'passed' : 'failed'; ?>">
|
||||
<strong><?php echo ($result['result']) ? 'Passed' : 'Failed'; ?>:</strong> <?php echo $result['name']; ?>
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user