Commit b71ecb43 by Taylor Otwell

removed packages directory. refactoring.

parent 80f810de
...@@ -25,7 +25,6 @@ function constants($constants) ...@@ -25,7 +25,6 @@ function constants($constants)
$constants = array( $constants = array(
'APP_PATH' => realpath($application).'/', 'APP_PATH' => realpath($application).'/',
'BASE_PATH' => realpath("$laravel/..").'/', 'BASE_PATH' => realpath("$laravel/..").'/',
'PACKAGE_PATH' => realpath($packages).'/',
'PUBLIC_PATH' => realpath($public).'/', 'PUBLIC_PATH' => realpath($public).'/',
'STORAGE_PATH' => realpath($storage).'/', 'STORAGE_PATH' => realpath($storage).'/',
'SYS_PATH' => realpath($laravel).'/', 'SYS_PATH' => realpath($laravel).'/',
...@@ -33,6 +32,8 @@ $constants = array( ...@@ -33,6 +32,8 @@ $constants = array(
constants($constants); constants($constants);
unset($application, $public, $storage, $laravel);
/** /**
* Register all of the other framework paths. All of these paths * Register all of the other framework paths. All of these paths
* are built on top of the core paths above. We still allow the * are built on top of the core paths above. We still allow the
......
...@@ -9,7 +9,6 @@ require 'constants.php'; ...@@ -9,7 +9,6 @@ require 'constants.php';
*/ */
require SYS_PATH.'arr'.EXT; require SYS_PATH.'arr'.EXT;
require SYS_PATH.'config'.EXT; require SYS_PATH.'config'.EXT;
require SYS_PATH.'loader'.EXT;
/** /**
* Load some core configuration files by default so we don't have to * Load some core configuration files by default so we don't have to
...@@ -35,18 +34,36 @@ IoC::$container = $container; ...@@ -35,18 +34,36 @@ IoC::$container = $container;
unset($container); unset($container);
/** /**
* Register the application auto-loader. The auto-loader is responsible * Register the application auto-loader. The auto-loader closure
* for the lazy-loading of all of the Laravel core classes, as well as * is responsible for the lazy-loading of all of the Laravel core
* the developer created libraries and models. * classes, as well as the developer created libraries and models.
*/ */
spl_autoload_register(array('Laravel\\Loader', 'load')); $aliases = Config::$items['application']['aliases'];
Loader::$aliases = Config::$items['application']['aliases']; spl_autoload_register(function($class) use ($aliases)
{
if (array_key_exists($class, $aliases))
{
return class_alias($aliases[$class], $class);
}
$file = strtolower(str_replace('\\', '/', $class));
foreach (array(BASE_PATH, MODEL_PATH, LIBRARY_PATH) as $path)
{
if (file_exists($path = $path.$file.EXT))
{
require_once $path;
return;
}
}
});
unset($aliases);
/** /**
* Define a few convenient global functions. These functions primarily * Define a few convenient global functions.
* exists to provide a short way of accessing functions commonly used
* in views, allowing the reduction of code noise.
*/ */
function e($value) function e($value)
{ {
......
...@@ -104,6 +104,10 @@ class Cookie { ...@@ -104,6 +104,10 @@ class Cookie {
* been modified by the user, since they serve as a fingerprint of the cookie * been modified by the user, since they serve as a fingerprint of the cookie
* contents. The application key is used to salt the salts. * contents. The application key is used to salt the salts.
* *
* When the cookie is read using the "get" method, the value will be extracted
* from the cookie and hashed, if the hash in the cookie and the hashed value
* do not match, we know the cookie has been changed on the client.
*
* @param string $name * @param string $name
* @param string $value * @param string $value
* @return string * @return string
......
...@@ -139,8 +139,6 @@ class Connection { ...@@ -139,8 +139,6 @@ class Connection {
*/ */
public function query($sql, $bindings = array()) public function query($sql, $bindings = array())
{ {
// Remove expressions from the bindings since they injected into
// the query as raw strings and are not bound parameters.
foreach ($bindings as $key => $value) foreach ($bindings as $key => $value)
{ {
if ($value instanceof Expression) unset($bindings[$key]); if ($value instanceof Expression) unset($bindings[$key]);
......
...@@ -24,8 +24,7 @@ class Query { ...@@ -24,8 +24,7 @@ class Query {
public $selects; public $selects;
/** /**
* If the query is performing an aggregate function, this will contain * The aggregating column and function.
* the column and and function to use when aggregating.
* *
* @var array * @var array
*/ */
......
...@@ -3,41 +3,41 @@ ...@@ -3,41 +3,41 @@
class Lang { class Lang {
/** /**
* All of the loaded language lines. * The key of the language line being retrieved.
*
* The array is keyed by [$language.$file].
* *
* @var array * @var string
*/ */
protected static $lines = array(); protected $key;
/** /**
* The paths containing the language files. * The replacements that should be made on the language line.
* *
* @var array * @var array
*/ */
protected static $paths = array(LANG_PATH); protected $replacements;
/** /**
* The key of the language line being retrieved. * The language in which the line should be retrieved.
* *
* @var string * @var string
*/ */
protected $key; protected $language;
/** /**
* The replacements that should be made on the language line. * All of the loaded language lines.
*
* The array is keyed by [$language.$file].
* *
* @var array * @var array
*/ */
protected $replacements; protected static $lines = array();
/** /**
* The language in which the line should be retrieved. * The paths containing the language files.
* *
* @var string * @var array
*/ */
protected $language; protected static $paths = array(LANG_PATH);
/** /**
* Create a new Lang instance. * Create a new Lang instance.
......
<?php namespace Laravel;
class Loader {
/**
* The paths that will be searched by the loader.
*
* @var array
*/
public static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH, APP_PATH);
/**
* The class aliases defined for the application.
*
* @var array
*/
public static $aliases = array();
/**
* Load the file for a given class.
*
* <code>
* // Load the file for the "User" class
* Loader::load('User');
*
* // Load the file for the "Repositories\User" class
* Loader::load('Repositories\\User');
* </code>
*
* @param string $class
* @return void
*/
public static function load($class)
{
// All Laravel core classes follow a namespace to directory convention.
// We will replace all of the namespace slashes with directory slashes.
$file = strtolower(str_replace('\\', '/', $class));
// Check to determine if an alias exists. If it does, we will define the
// alias and bail out. Aliases are defined for most used core classes.
if (array_key_exists($class, static::$aliases))
{
return class_alias(static::$aliases[$class], $class);
}
foreach (static::$paths as $path)
{
if (file_exists($path = $path.$file.EXT))
{
require_once $path;
return;
}
}
}
/**
* Register a class alias with the auto-loader.
*
* @param string $alias
* @param string $class
* @return void
*/
public static function alias($alias, $class)
{
static::$aliases[$alias] = $class;
}
/**
* Register a path with the auto-loader.
*
* @param string $path
* @return void
*/
public static function path($path)
{
static::$paths[] = rtrim($path, '/').'/';
}
/**
* Remove an alias from the auto-loader's alias registrations.
*
* @param string $alias
* @return void
*/
public static function forget_alias($alias)
{
unset(static::$aliases[$alias]);
}
}
\ No newline at end of file
...@@ -89,7 +89,11 @@ class Paginator { ...@@ -89,7 +89,11 @@ class Paginator {
*/ */
public static function make($results, $total, $per_page) public static function make($results, $total, $per_page)
{ {
return new static($results, static::page($total, $per_page), $total, $per_page, ceil($total / $per_page)); $page = static::page($total, $per_page);
$last_page = ceil($total / $per_page);
return new static($results, $page, $total, $per_page, $last_page);
} }
/** /**
...@@ -202,7 +206,9 @@ class Paginator { ...@@ -202,7 +206,9 @@ class Paginator {
*/ */
protected function backwards($element, $text, $last) protected function backwards($element, $text, $last)
{ {
return $this->element($element, $text, $last, function($page) { return $page <= 1; }); $disabler = function($page) { return $page <= 1; };
return $this->element($element, $text, $last, $disabler);
} }
/** /**
...@@ -217,7 +223,9 @@ class Paginator { ...@@ -217,7 +223,9 @@ class Paginator {
*/ */
protected function forwards($element, $text, $last) protected function forwards($element, $text, $last)
{ {
return $this->element($element, $text, $last, function($page, $last) { return $page >= $last; }); $disabler = function($page, $last) { return $page >= $last; };
return $this->element($element, $text, $last, $disabler);
} }
/** /**
...@@ -257,9 +265,6 @@ class Paginator { ...@@ -257,9 +265,6 @@ class Paginator {
*/ */
protected function appendage($element, $page) protected function appendage($element, $page)
{ {
// The appendage string contains the query string, but it also contains a
// place-holder for the page number. This will be used to insert the
// correct page number based on the element being created.
if (is_null($this->appendage)) if (is_null($this->appendage))
{ {
$this->appendage = '?page=%s'.http_build_query((array) $this->appends); $this->appendage = '?page=%s'.http_build_query((array) $this->appends);
......
...@@ -24,8 +24,11 @@ class Crypter { ...@@ -24,8 +24,11 @@ class Crypter {
/** /**
* Encrypt a string using Mcrypt. * Encrypt a string using Mcrypt.
* *
* The string will be encrypted using the cipher and mode specified when the * The given string will be encrypted using AES-256 encryption for a high
* crypter instance was created, and the final result will be base64 encoded. * degree of security. The returned string will also be base64 encoded.
*
* Mcrypt must be installed on your machine before using this method, and
* an application key must be specified in the application configuration.
* *
* <code> * <code>
* // Encrypt a string using the Mcrypt PHP extension * // Encrypt a string using the Mcrypt PHP extension
...@@ -47,31 +50,34 @@ class Crypter { ...@@ -47,31 +50,34 @@ class Crypter {
/** /**
* Decrypt a string using Mcrypt. * Decrypt a string using Mcrypt.
* *
* The given encrypted value must have been encrypted using Laravel and
* the application key specified in the application configuration file.
*
* Mcrypt must be installed on your machine before using this method.
*
* @param string $value * @param string $value
* @return string * @return string
*/ */
public static function decrypt($value) public static function decrypt($value)
{ {
list($iv, $value) = static::parse(base64_decode($value, true)); if (($value = base64_decode($value)) === false)
{
throw new \Exception('Decryption error. Input value is not valid base64 data.');
}
$value = mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv); list($iv, $value) = static::parse($value);
return rtrim($value, "\0"); return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
} }
/** /**
* Parse an encrypted value into the input vector and the actual value. * Parse an encrypted string into its input vector and value segments.
* *
* @param string $value * @param string $value
* @return array * @return array
*/ */
protected static function parse($value) protected static function parse($value)
{ {
if ($value === false)
{
throw new \Exception('Decryption error. Input value is not valid base64 data.');
}
return array(substr($value, 0, static::iv_size()), substr($value, static::iv_size())); return array(substr($value, 0, static::iv_size()), substr($value, static::iv_size()));
} }
......
...@@ -20,10 +20,6 @@ class URL { ...@@ -20,10 +20,6 @@ class URL {
{ {
if (filter_var($url, FILTER_VALIDATE_URL) !== false) return $url; if (filter_var($url, FILTER_VALIDATE_URL) !== false) return $url;
// First, we build the base URL for the application, as well as handle the generation
// of links using SSL. It is possible for the developer to disable the generation
// of SSL links throughout the application, making it more convenient to create
// applications without SSL on the development box.
$base = Config::$items['application']['url'].'/'.Config::$items['application']['index']; $base = Config::$items['application']['url'].'/'.Config::$items['application']['index'];
if ($https and Config::$items['application']['ssl']) if ($https and Config::$items['application']['ssl'])
...@@ -99,8 +95,9 @@ class URL { ...@@ -99,8 +95,9 @@ class URL {
$uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1); $uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1);
} }
// Before generating the route URL, we will replace all remaining optional // Replace all remaining optional segments with spaces. Since the
// wildcard segments that were not replaced by parameters with spaces. // segments are, obviously, optional, some of them may not have
// been assigned values from the parameter array.
return static::to(str_replace(array('/(:any?)', '/(:num?)'), '', $uri), $https); return static::to(str_replace(array('/(:any?)', '/(:num?)'), '', $uri), $https);
} }
......
...@@ -163,11 +163,11 @@ class Validator { ...@@ -163,11 +163,11 @@ class Validator {
{ {
list($rule, $parameters) = $this->parse($rule); list($rule, $parameters) = $this->parse($rule);
// Verify that the attribute and rule combination is actually validatable before // Verify that the attribute and rule combination is actually
// attempting to call the validation rule. Unless the rule implicitly requires // validatable before attempting to call the validation rule.
// the attribute to exist, we will not call any rules for attributes that are $value = Arr::get($this->attributes, $attribute);
// not in the validator's attribute array.
if ( ! $this->validatable($rule, $attribute, $value = Arr::get($this->attributes, $attribute))) return; if ( ! $this->validatable($rule, $attribute, $value)) return;
if ( ! $this->{'validate_'.$rule}($attribute, $value, $parameters, $this)) if ( ! $this->{'validate_'.$rule}($attribute, $value, $parameters, $this))
{ {
...@@ -178,9 +178,9 @@ class Validator { ...@@ -178,9 +178,9 @@ class Validator {
/** /**
* Determine if an attribute is validatable. * Determine if an attribute is validatable.
* *
* To be considered validatable, the attribute must either exist, or the rule being * To be considered validatable, the attribute must either exist, or the
* checked must implicitly validate "required", such as the "required" rule or the * rule being checked must implicitly validate "required", such as the
* "accepted" rule. No other rules have implicit "required" validation. * "required" rule or the "accepted" rule.
* *
* @param string $rule * @param string $rule
* @param string $attribute * @param string $attribute
...@@ -508,25 +508,25 @@ class Validator { ...@@ -508,25 +508,25 @@ class Validator {
*/ */
protected function message($attribute, $rule) protected function message($attribute, $rule)
{ {
// First we'll check for developer specified, attribute specific messages. These messages // First we'll check for developer specified, attribute specific messages.
// take first priority if they have been specified. They allow the fine-grained tuning // These messages take first priority. They allow the fine-grained tuning
// of error messages for each rule. // of error messages for each rule.
if (array_key_exists($attribute.'_'.$rule, $this->messages)) if (array_key_exists($attribute.'_'.$rule, $this->messages))
{ {
return $this->messages[$attribute.'_'.$rule]; return $this->messages[$attribute.'_'.$rule];
} }
// Next we'll check for developer specified, rule specific messages. These allow the // Next we'll check for developer specified, rule specific error messages.
// developer to override the error message for an entire rule, regardless of the // These allow the developer to override the error message for an entire
// attribute being validated by that rule. // rule, regardless of the attribute being validated by that rule.
elseif (array_key_exists($rule, $this->messages)) elseif (array_key_exists($rule, $this->messages))
{ {
return $this->messages[$rule]; return $this->messages[$rule];
} }
// If the rule being validated is a "size" rule and the attribute is not a number, // If the rule being validated is a "size" rule and the attribute is not
// we will need to gather the specific size message for the type of attribute // a number, we will need to gather the specific size message for the
// being validated, either a file or a string. // type of attribute being validated, either a file or a string.
elseif (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, $this->numeric_rules)) elseif (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, $this->numeric_rules))
{ {
$line = (array_key_exists($attribute, Input::file())) ? "file" : "string"; $line = (array_key_exists($attribute, Input::file())) ? "file" : "string";
...@@ -534,9 +534,9 @@ class Validator { ...@@ -534,9 +534,9 @@ class Validator {
return Lang::line("validation.{$rule}.{$line}")->get($this->language); return Lang::line("validation.{$rule}.{$line}")->get($this->language);
} }
// If no developer specified messages have been set, and no other special messages // If no developer specified messages have been set, and no other special
// apply to the rule, we will just pull the default validation message from the // messages apply to the rule, we will just pull the default validation
// validation language file. // message from the validation language file.
else else
{ {
return Lang::line("validation.{$rule}")->get($this->language); return Lang::line("validation.{$rule}")->get($this->language);
...@@ -558,9 +558,10 @@ class Validator { ...@@ -558,9 +558,10 @@ class Validator {
if (in_array($rule, $this->size_rules)) if (in_array($rule, $this->size_rules))
{ {
// Even though every size rule will not have a place-holder for min, max, and size, // Even though every size rule will not have a place-holder for min,
// we will go ahead and make replacements for all of them just for convenience. // max, and size, we will go ahead and make replacements for all of
// Except for "between" every replacement should be the first parameter. // them just for convenience. Except for "between" every replacement
// should be the first parameter.
$max = ($rule == 'between') ? $parameters[1] : $parameters[0]; $max = ($rule == 'between') ? $parameters[1] : $parameters[0];
$replace = array($parameters[0], $parameters[0], $max); $replace = array($parameters[0], $parameters[0], $max);
...@@ -621,10 +622,15 @@ class Validator { ...@@ -621,10 +622,15 @@ class Validator {
*/ */
protected function parse($rule) protected function parse($rule)
{ {
$parameters = array();
// The format for specifying validation rules and parameters follows // The format for specifying validation rules and parameters follows
// a {rule}:{parameters} convention. For instance, "max:3" specifies // a {rule}:{parameters} convention. For instance, "max:3" specifies
// that the value may only be 3 characters in length. // that the value may only be 3 characters in length.
$parameters = (($colon = strpos($rule, ':')) !== false) ? explode(',', substr($rule, $colon + 1)) : array(); if (($colon = strpos($rule, ':')) !== false)
{
$parameters = explode(',', substr($rule, $colon + 1));
}
return array(is_numeric($colon) ? substr($rule, 0, $colon) : $rule, $parameters); return array(is_numeric($colon) ? substr($rule, 0, $colon) : $rule, $parameters);
} }
......
...@@ -33,8 +33,6 @@ $application = '../application'; ...@@ -33,8 +33,6 @@ $application = '../application';
$laravel = '../laravel'; $laravel = '../laravel';
$packages = '../packages';
$storage = '../storage'; $storage = '../storage';
$public = __DIR__; $public = __DIR__;
......
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