Commit b71ecb43 by Taylor Otwell

removed packages directory. refactoring.

parent 80f810de
......@@ -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 @@ $constants = array(
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
......
......@@ -9,7 +9,6 @@ require 'constants.php';
*/
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 @@ IoC::$container = $container;
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)
{
......
......@@ -104,6 +104,10 @@ class 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.
*
* 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
......
......@@ -139,8 +139,6 @@ class Connection {
*/
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]);
......
......@@ -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
*/
......
......@@ -3,41 +3,41 @@
class Lang {
/**
* All of the loaded language lines.
*
* The array is keyed by [$language.$file].
* The key of the language line being retrieved.
*
* @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
*/
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
*/
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
*/
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.
......
<?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 {
*/
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 {
*/
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 {
*/
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 {
*/
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);
......
......@@ -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.
*
* <code>
* // Encrypt a string using the Mcrypt PHP extension
......@@ -47,31 +50,34 @@ class Crypter {
/**
* 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()));
}
......
......@@ -20,10 +20,6 @@ class 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'];
if ($https and Config::$items['application']['ssl'])
......@@ -99,8 +95,9 @@ class URL {
$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);
}
......
......@@ -163,11 +163,11 @@ class Validator {
{
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 @@ class Validator {
/**
* 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 @@ class Validator {
*/
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 @@ class Validator {
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 @@ class Validator {
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 @@ class Validator {
*/
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);
}
......
......@@ -33,8 +33,6 @@ $application = '../application';
$laravel = '../laravel';
$packages = '../packages';
$storage = '../storage';
$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