refactoring bootstrapping.
This commit is contained in:
parent
ca2c988274
commit
2e1fed294f
|
@ -66,25 +66,6 @@
|
|||
|
||||
'language' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Auto-Loaded Packages
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The packages that should be auto-loaded each time Laravel handles a
|
||||
| request. These should generally be packages that you use on almost every
|
||||
| request to your application.
|
||||
|
|
||||
| Each package specified here will be bootstrapped and can be conveniently
|
||||
| used by your application's routes, models, and libraries.
|
||||
|
|
||||
| Note: The package names in this array should correspond to a package
|
||||
| directory in application/packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'libraries' => array(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| SSL Link Generation
|
||||
|
|
|
@ -56,9 +56,13 @@ protected static function find($class)
|
|||
|
||||
$namespace = substr($class, 0, strpos($class, '\\'));
|
||||
|
||||
// If the namespace has been detected as a PSR-0 compliant library,
|
||||
// we will load the library according to those naming conventions.
|
||||
if (array_key_exists($namespace, static::$libraries))
|
||||
// If the namespace has been registered as a PSR-0 compliant library, we will
|
||||
// load the library according to the PSR-0 naming standards, which state that
|
||||
// namespaces and underscores indicate the directory hierarchy of the class.
|
||||
// The PSR-0 standard is exactly like the typical Laravel standard, the only
|
||||
// difference being that Laravel files are all lowercase, while PSR-0 states
|
||||
// that the file name should match the class name.
|
||||
if (isset(static::$libraries[$namespace]))
|
||||
{
|
||||
return str_replace('_', '/', $file).EXT;
|
||||
}
|
||||
|
@ -71,10 +75,12 @@ protected static function find($class)
|
|||
}
|
||||
}
|
||||
|
||||
// If the file exists according to the PSR-0 naming conventions,
|
||||
// we will add the namespace to the array of libraries and load
|
||||
// the class according to the PSR-0 conventions.
|
||||
if (file_exists($path = str_replace('_', '/', $file).EXT))
|
||||
// If we could not find the class file in any of the auto-loaded locations
|
||||
// according to the Laravel naming standard, we will search the libraries
|
||||
// directory for the class according to the PSR-0 naming standard. If the
|
||||
// file exists, we will add the class namespace to the array of registered
|
||||
// libraries that are loaded following the PSR-0 standard.
|
||||
if (file_exists($path = LIBRARY_PATH.str_replace('_', '/', $file).EXT))
|
||||
{
|
||||
static::$libraries[] = $namespace;
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
define('EXT', '.php');
|
||||
define('BLADE_EXT', '.blade.php');
|
||||
|
||||
function constants($constants)
|
||||
{
|
||||
foreach ($constants as $key => $value)
|
||||
{
|
||||
if ( ! defined($key)) define($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the core framework paths and all of the paths that
|
||||
* derive from them. If any constant has already been defined,
|
||||
* we will not attempt to define it again.
|
||||
*/
|
||||
$constants = array(
|
||||
'APP_PATH' => realpath($application).'/',
|
||||
'BASE_PATH' => realpath("$laravel/..").'/',
|
||||
'PUBLIC_PATH' => realpath($public).'/',
|
||||
'STORAGE_PATH' => realpath($storage).'/',
|
||||
'SYS_PATH' => realpath($laravel).'/',
|
||||
);
|
||||
|
||||
constants($constants);
|
||||
|
||||
unset($application, $public, $storage, $laravel);
|
||||
|
||||
$constants = array(
|
||||
'CACHE_PATH' => STORAGE_PATH.'cache/',
|
||||
'CONFIG_PATH' => APP_PATH.'config/',
|
||||
'CONTROLLER_PATH' => APP_PATH.'controllers/',
|
||||
'DATABASE_PATH' => STORAGE_PATH.'database/',
|
||||
'LANG_PATH' => APP_PATH.'language/',
|
||||
'LIBRARY_PATH' => APP_PATH.'libraries/',
|
||||
'MODEL_PATH' => APP_PATH.'models/',
|
||||
'ROUTE_PATH' => APP_PATH.'routes/',
|
||||
'SESSION_PATH' => STORAGE_PATH.'sessions/',
|
||||
'SYS_CONFIG_PATH' => SYS_PATH.'config/',
|
||||
'SYS_VIEW_PATH' => SYS_PATH.'views/',
|
||||
'VIEW_PATH' => APP_PATH.'views/',
|
||||
);
|
||||
|
||||
|
||||
constants($constants);
|
||||
|
||||
/**
|
||||
* Register the core framework paths and all of the paths that
|
||||
* derive from them. If any constant has already been defined,
|
||||
* we will not attempt to define it again.
|
||||
*/
|
||||
$environment = (isset($_SERVER['LARAVEL_ENV'])) ? CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/' : '';
|
||||
|
||||
constants(array('ENV_CONFIG_PATH' => $environment));
|
||||
|
||||
unset($constants, $environment);
|
|
@ -1,21 +1,87 @@
|
|||
<?php namespace Laravel;
|
||||
|
||||
require 'constants.php';
|
||||
/**
|
||||
* Define all of the constants used by the framework. All of the
|
||||
* core paths will be defined, as well as all of the paths which
|
||||
* derive from those core paths.
|
||||
*/
|
||||
define('EXT', '.php');
|
||||
define('CRLF', chr(13).chr(10));
|
||||
define('BLADE_EXT', '.blade.php');
|
||||
|
||||
define('APP_PATH', realpath($application).'/');
|
||||
define('BASE_PATH', realpath("$laravel/..").'/');
|
||||
define('PUBLIC_PATH', realpath($public).'/');
|
||||
define('STORAGE_PATH', realpath($storage).'/');
|
||||
define('SYS_PATH', realpath($laravel).'/');
|
||||
|
||||
define('CACHE_PATH', STORAGE_PATH.'cache/');
|
||||
define('CONFIG_PATH', APP_PATH.'config/');
|
||||
define('CONTROLLER_PATH', APP_PATH.'controllers/');
|
||||
define('DATABASE_PATH', STORAGE_PATH.'database/');
|
||||
define('LANG_PATH', APP_PATH.'language/');
|
||||
define('LIBRARY_PATH', APP_PATH.'libraries/');
|
||||
define('MODEL_PATH', APP_PATH.'models/');
|
||||
define('ROUTE_PATH', APP_PATH.'routes/');
|
||||
define('SESSION_PATH', STORAGE_PATH.'sessions/');
|
||||
define('SYS_CONFIG_PATH', SYS_PATH.'config/');
|
||||
define('SYS_VIEW_PATH', SYS_PATH.'views/');
|
||||
define('VIEW_PATH', APP_PATH.'views/');
|
||||
|
||||
/**
|
||||
* Define the Laravel environment configuration path. This path is
|
||||
* used by the configuration class to load configuration options
|
||||
* specific for the server environment.
|
||||
*/
|
||||
$environment = '';
|
||||
|
||||
if (isset($_SERVER['LARAVEL_ENV']))
|
||||
{
|
||||
$environment = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/';
|
||||
}
|
||||
|
||||
define('ENV_CONFIG_PATH', $environment);
|
||||
|
||||
unset($application, $public, $storage, $laravel, $environment);
|
||||
|
||||
/**
|
||||
* Require all of the classes that can't be loaded by the auto-loader.
|
||||
* These are typically classes that the auto-loader itself relies upon
|
||||
* to load classes, such as the array and configuration classes.
|
||||
*/
|
||||
require SYS_PATH.'arr'.EXT;
|
||||
require SYS_PATH.'config'.EXT;
|
||||
require SYS_PATH.'facades'.EXT;
|
||||
require SYS_PATH.'container'.EXT;
|
||||
require SYS_PATH.'autoloader'.EXT;
|
||||
|
||||
/**
|
||||
* Load a few of the core configuration files that are loaded for
|
||||
* every request to the application. It is quicker to load them
|
||||
* manually rather than parse the keys for every request.
|
||||
*/
|
||||
Config::load('application');
|
||||
Config::load('container');
|
||||
Config::load('session');
|
||||
|
||||
/**
|
||||
* Bootstrap the application inversion of control container.
|
||||
* The IoC container is responsible for resolving classes and
|
||||
* their dependencies, and helps keep the framework flexible.
|
||||
*/
|
||||
IoC::bootstrap();
|
||||
|
||||
/**
|
||||
* Register the Autoloader's "load" method on the auto-loader stack.
|
||||
* This method provides the lazy-loading of all class files, as well
|
||||
* as any PSR-0 compliant libraries used by the application.
|
||||
*/
|
||||
spl_autoload_register(array('Laravel\\Autoloader', 'load'));
|
||||
|
||||
/**
|
||||
* Define a few convenient functions to make our lives as
|
||||
* developers a little more easy and enjoyable.
|
||||
*/
|
||||
function e($value)
|
||||
{
|
||||
return HTML::entities($value);
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* Define a clousre that will return a more readable version
|
||||
* of the severity of an exception. This function will be used
|
||||
* by the error handler when parsing exceptions.
|
||||
* Define a closure that will return a more readable version of
|
||||
* the severity of an exception. This function will be used by
|
||||
* the error handler when parsing exceptions.
|
||||
*/
|
||||
$severity = function($e)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,16 @@ public static function get($key = null, $default = null)
|
|||
return Arr::get(static::$input, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash the input for the current request to the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function flash()
|
||||
{
|
||||
IoC::container()->core('session')->flash(Input::old_input, static::get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the old input data contains an item.
|
||||
*
|
||||
|
@ -74,16 +84,6 @@ public static function had($key)
|
|||
return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash the input for the current request to the session.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function flash()
|
||||
{
|
||||
IoC::container()->core('session')->flash(Input::old_input, static::get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input data from the previous request.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php namespace Laravel;
|
||||
|
||||
define('CRLF', chr(13).chr(10));
|
||||
|
||||
class Redis {
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,9 +47,6 @@ public function __construct($view, $data = array())
|
|||
/**
|
||||
* Get the path to a given view on disk.
|
||||
*
|
||||
* The view may be either a "normal" view or a "Blade" view, so we will
|
||||
* need to check the view directory for either extension.
|
||||
*
|
||||
* @param string $view
|
||||
* @return string
|
||||
*/
|
||||
|
@ -57,6 +54,11 @@ protected function path($view)
|
|||
{
|
||||
$view = str_replace('.', '/', $view);
|
||||
|
||||
// Application views take priority over system views, so we will return the
|
||||
// application version of the view if both exists. Also, we need to check
|
||||
// for Blade views using the Blade extension. The Blade extension gives
|
||||
// an easy method of determining if the view should be compiled using
|
||||
// the Blade compiler or if the view is plain PHP.
|
||||
foreach (array(EXT, BLADE_EXT) as $extension)
|
||||
{
|
||||
if (file_exists($path = VIEW_PATH.$view.$extension))
|
||||
|
@ -123,7 +125,9 @@ public static function of($name, $data = array())
|
|||
/**
|
||||
* Find the key for a view by name.
|
||||
*
|
||||
* The view "key" is the string that should be passed into the "make" method.
|
||||
* The view "key" is the string that should be passed into the "make" method and
|
||||
* should correspond with the location of the view within the application views
|
||||
* directory, such as "home.index" or "home/index".
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
|
@ -209,7 +213,7 @@ protected function compile()
|
|||
// since the last compiled version of the view was created or no
|
||||
// compiled view exists. Otherwise, the path will be returned
|
||||
// without re-compiling.
|
||||
if ((file_exists($compiled) and filemtime($this->path) > filemtime($compiled)) or ! file_exists($compiled))
|
||||
if ( ! file_exists($compiled) or (filemtime($this->path) > filemtime($compiled)))
|
||||
{
|
||||
file_put_contents($compiled, Blade::compile($this->path));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue