diff --git a/laravel/bootstrap/constants.php b/laravel/bootstrap/constants.php index 9c6b4446..7ec5edac 100644 --- a/laravel/bootstrap/constants.php +++ b/laravel/bootstrap/constants.php @@ -25,7 +25,6 @@ function constants($constants) $constants = array( 'APP_PATH' => realpath($application).'/', 'BASE_PATH' => realpath("$laravel/..").'/', - 'PACKAGE_PATH' => realpath($packages).'/', 'PUBLIC_PATH' => realpath($public).'/', 'STORAGE_PATH' => realpath($storage).'/', 'SYS_PATH' => realpath($laravel).'/', @@ -33,6 +32,8 @@ function constants($constants) constants($constants); +unset($application, $public, $storage, $laravel); + /** * Register all of the other framework paths. All of these paths * are built on top of the core paths above. We still allow the diff --git a/laravel/bootstrap/core.php b/laravel/bootstrap/core.php index 883c4942..03b3b690 100644 --- a/laravel/bootstrap/core.php +++ b/laravel/bootstrap/core.php @@ -9,7 +9,6 @@ */ require SYS_PATH.'arr'.EXT; require SYS_PATH.'config'.EXT; -require SYS_PATH.'loader'.EXT; /** * Load some core configuration files by default so we don't have to @@ -35,18 +34,36 @@ unset($container); /** - * Register the application auto-loader. The auto-loader is responsible - * for the lazy-loading of all of the Laravel core classes, as well as - * the developer created libraries and models. + * Register the application auto-loader. The auto-loader closure + * is responsible for the lazy-loading of all of the Laravel core + * 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 - * exists to provide a short way of accessing functions commonly used - * in views, allowing the reduction of code noise. + * Define a few convenient global functions. */ function e($value) { diff --git a/laravel/cookie.php b/laravel/cookie.php index a41fcb4e..b2670470 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -104,6 +104,10 @@ public static function put($name, $value, $minutes = 0, $path = '/', $domain = n * been modified by the user, since they serve as a fingerprint of the cookie * 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 $value * @return string diff --git a/laravel/database/connection.php b/laravel/database/connection.php index 59bd9dd7..352e2992 100644 --- a/laravel/database/connection.php +++ b/laravel/database/connection.php @@ -139,8 +139,6 @@ public function first($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) { if ($value instanceof Expression) unset($bindings[$key]); diff --git a/laravel/database/query.php b/laravel/database/query.php index eceb60c9..3fedcaf4 100644 --- a/laravel/database/query.php +++ b/laravel/database/query.php @@ -24,8 +24,7 @@ class Query { public $selects; /** - * If the query is performing an aggregate function, this will contain - * the column and and function to use when aggregating. + * The aggregating column and function. * * @var array */ diff --git a/laravel/lang.php b/laravel/lang.php index 5bf12ff5..0f24303f 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -2,22 +2,6 @@ class Lang { - /** - * All of the loaded language lines. - * - * The array is keyed by [$language.$file]. - * - * @var array - */ - protected static $lines = array(); - - /** - * The paths containing the language files. - * - * @var array - */ - protected static $paths = array(LANG_PATH); - /** * The key of the language line being retrieved. * @@ -39,6 +23,22 @@ class Lang { */ protected $language; + /** + * All of the loaded language lines. + * + * The array is keyed by [$language.$file]. + * + * @var array + */ + protected static $lines = array(); + + /** + * The paths containing the language files. + * + * @var array + */ + protected static $paths = array(LANG_PATH); + /** * Create a new Lang instance. * diff --git a/laravel/loader.php b/laravel/loader.php deleted file mode 100644 index 8127038f..00000000 --- a/laravel/loader.php +++ /dev/null @@ -1,91 +0,0 @@ - - * // Load the file for the "User" class - * Loader::load('User'); - * - * // Load the file for the "Repositories\User" class - * Loader::load('Repositories\\User'); - * - * - * @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 diff --git a/laravel/paginator.php b/laravel/paginator.php index 098be386..2a6eede1 100644 --- a/laravel/paginator.php +++ b/laravel/paginator.php @@ -89,7 +89,11 @@ protected function __construct($results, $page, $total, $per_page, $last) */ 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 @@ protected function last($text) */ 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 @@ protected function backwards($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 @@ protected function element($element, $text, $page, $disabler) */ 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)) { $this->appendage = '?page=%s'.http_build_query((array) $this->appends); diff --git a/laravel/security/crypter.php b/laravel/security/crypter.php index 98c24a06..89f8b2e0 100644 --- a/laravel/security/crypter.php +++ b/laravel/security/crypter.php @@ -24,8 +24,11 @@ class Crypter { /** * Encrypt a string using Mcrypt. * - * The string will be encrypted using the cipher and mode specified when the - * crypter instance was created, and the final result will be base64 encoded. + * The given string will be encrypted using AES-256 encryption for a high + * 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. * * * // Encrypt a string using the Mcrypt PHP extension @@ -47,31 +50,34 @@ public static function encrypt($value) /** * 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 * @return string */ 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 * @return array */ 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())); } diff --git a/laravel/url.php b/laravel/url.php index a927551b..fc2d19dd 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -20,10 +20,6 @@ public static function to($url = '', $https = false) { 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']; if ($https and Config::$items['application']['ssl']) @@ -99,8 +95,9 @@ public static function to_route($name, $parameters = array(), $https = false) $uri = preg_replace('/\(.+?\)/', $parameter, $uri, 1); } - // Before generating the route URL, we will replace all remaining optional - // wildcard segments that were not replaced by parameters with spaces. + // Replace all remaining optional segments with spaces. Since the + // 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); } diff --git a/laravel/validation/validator.php b/laravel/validation/validator.php index b622f26d..812eb2d7 100644 --- a/laravel/validation/validator.php +++ b/laravel/validation/validator.php @@ -163,11 +163,11 @@ protected function check($attribute, $rule) { list($rule, $parameters) = $this->parse($rule); - // Verify that the attribute and rule combination is actually validatable before - // attempting to call the validation rule. Unless the rule implicitly requires - // the attribute to exist, we will not call any rules for attributes that are - // not in the validator's attribute array. - if ( ! $this->validatable($rule, $attribute, $value = Arr::get($this->attributes, $attribute))) return; + // Verify that the attribute and rule combination is actually + // validatable before attempting to call the validation rule. + $value = Arr::get($this->attributes, $attribute); + + if ( ! $this->validatable($rule, $attribute, $value)) return; if ( ! $this->{'validate_'.$rule}($attribute, $value, $parameters, $this)) { @@ -178,9 +178,9 @@ protected function check($attribute, $rule) /** * Determine if an attribute is validatable. * - * To be considered validatable, the attribute must either exist, or the rule being - * checked must implicitly validate "required", such as the "required" rule or the - * "accepted" rule. No other rules have implicit "required" validation. + * To be considered validatable, the attribute must either exist, or the + * rule being checked must implicitly validate "required", such as the + * "required" rule or the "accepted" rule. * * @param string $rule * @param string $attribute @@ -508,25 +508,25 @@ protected function validate_mimes($attribute, $parameters) */ protected function message($attribute, $rule) { - // First we'll check for developer specified, attribute specific messages. These messages - // take first priority if they have been specified. They allow the fine-grained tuning + // First we'll check for developer specified, attribute specific messages. + // These messages take first priority. They allow the fine-grained tuning // of error messages for each rule. if (array_key_exists($attribute.'_'.$rule, $this->messages)) { return $this->messages[$attribute.'_'.$rule]; } - // Next we'll check for developer specified, rule specific messages. These allow the - // developer to override the error message for an entire rule, regardless of the - // attribute being validated by that rule. + // Next we'll check for developer specified, rule specific error messages. + // These allow the developer to override the error message for an entire + // rule, regardless of the attribute being validated by that rule. elseif (array_key_exists($rule, $this->messages)) { return $this->messages[$rule]; } - // If the rule being validated is a "size" rule and the attribute is not a number, - // we will need to gather the specific size message for the type of attribute - // being validated, either a file or a string. + // If the rule being validated is a "size" rule and the attribute is not + // a number, we will need to gather the specific size message for the + // 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)) { $line = (array_key_exists($attribute, Input::file())) ? "file" : "string"; @@ -534,9 +534,9 @@ protected function message($attribute, $rule) return Lang::line("validation.{$rule}.{$line}")->get($this->language); } - // If no developer specified messages have been set, and no other special messages - // apply to the rule, we will just pull the default validation message from the - // validation language file. + // If no developer specified messages have been set, and no other special + // messages apply to the rule, we will just pull the default validation + // message from the validation language file. else { return Lang::line("validation.{$rule}")->get($this->language); @@ -558,9 +558,10 @@ protected function replace($message, $attribute, $rule, $parameters) if (in_array($rule, $this->size_rules)) { - // Even though every size rule will not have a place-holder for min, max, and size, - // we will go ahead and make replacements for all of them just for convenience. - // Except for "between" every replacement should be the first parameter. + // Even though every size rule will not have a place-holder for min, + // max, and size, we will go ahead and make replacements for all of + // them just for convenience. Except for "between" every replacement + // should be the first parameter. $max = ($rule == 'between') ? $parameters[1] : $parameters[0]; $replace = array($parameters[0], $parameters[0], $max); @@ -621,10 +622,15 @@ protected function has_rule($attribute, $rules) */ protected function parse($rule) { + $parameters = array(); + // The format for specifying validation rules and parameters follows // a {rule}:{parameters} convention. For instance, "max:3" specifies // 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); } diff --git a/packages/.gitignore b/packages/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/public/index.php b/public/index.php index c39e1cd0..78aa549f 100644 --- a/public/index.php +++ b/public/index.php @@ -33,8 +33,6 @@ $laravel = '../laravel'; -$packages = '../packages'; - $storage = '../storage'; $public = __DIR__;