Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
d5d97762
Commit
d5d97762
authored
Oct 18, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
continuing to refactor the bootstrap process.
parent
9fc9f88a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
62 deletions
+119
-62
application/config/container.php
+55
-0
laravel/bootstrap/constants.php
+31
-2
laravel/bootstrap/core.php
+8
-41
laravel/bootstrap/errors.php
+22
-16
laravel/config.php
+3
-3
No files found.
application/config/container.php
0 → 100644
View file @
d5d97762
<?php
return
array
(
/*
|--------------------------------------------------------------------------
| Inversion of Control Container
|--------------------------------------------------------------------------
|
| Here you may define resolvers for the Laravel inversion of control (IoC)
| container. An IoC container provides the ability to create more flexible
| and testable applications, as well as a convenient method of managing
| the instantiation of complex objects.
|
| To register a resolver in the container, simple create add an item to
| the array for the object with a closure that returns an instance of
| the object.
|
| For example, here's how to register a resolver for a Mailer class:
|
| 'mailer' => function($c)
| {
| return new Mailer($sender, $key);
| }
|
| Note that the container instance itself is passed into the resolver,
| allowing you to continue to resolve dependencies within the resolver
| itself. This allows you to easily resolve nested dependencies.
|
| When creating controller instances, Laravel will check to see if a
| resolver has been registered for the controller. If it has, it will
| be used to create the controller instance. All controller resolvers
| should be registered beginning using a {controllers}.{name} naming
| convention. For example:
|
| 'controllers.user' => function($c)
| {
| return new User_Controller($c->resolve('repository'));
| }
|
| Of course, sometimes you may wish to register an object as a singleton
| Singletons are resolved by the controller the first time they are
| resolved; however, that same resolved instance will continue to be
| returned by the container each time it is requested. Registering an
| object as a singleton couldn't be simpler:
|
| 'mailer' => array('singleton' => true, 'resolver' => function($c)
| {
| return new Mailer($sender, $key);
| })
|
*/
);
\ No newline at end of file
laravel/bootstrap/constants.php
View file @
d5d97762
<?php
/**
* Define the extensions used by the framework.
*/
define
(
'EXT'
,
'.php'
);
define
(
'BLADE_EXT'
,
'.blade.php'
);
/**
* Define a function that registers an array of constants
* if they haven't already been registered. This allows the
* constants to be changed from their default values when
* unit testing the framework.
*/
function
constants
(
$constants
)
{
foreach
(
$constants
as
$key
=>
$value
)
...
...
@@ -11,6 +20,11 @@ function constants($constants)
}
}
/**
* Register the core framework paths. All other paths are
* built on top of these core paths. All of these paths are
* changable by the developer in the front controller.
*/
$constants
=
array
(
'APP_PATH'
=>
realpath
(
$application
)
.
'/'
,
'BASE_PATH'
=>
realpath
(
"
$laravel
/.."
)
.
'/'
,
...
...
@@ -22,6 +36,10 @@ $constants = array(
constants
(
$constants
);
/**
* Register all of the other framework paths. All of these
* paths are built on top of the core paths above.
*/
$constants
=
array
(
'CACHE_PATH'
=>
STORAGE_PATH
.
'cache/'
,
'CONFIG_PATH'
=>
APP_PATH
.
'config/'
,
...
...
@@ -41,4 +59,15 @@ $constants = array(
constants
(
$constants
);
unset
(
$constants
);
\ No newline at end of file
unset
(
$constants
);
/**
* Set the Laravel environment configuration path constant.
* The environment is controller by setting an environment
* variable on the server running Laravel.
*/
$environment
=
(
isset
(
$_SERVER
[
'LARAVEL_ENV'
]))
?
$_SERVER
[
'LARAVEL_ENV'
]
:
''
;
define
(
'ENV_CONFIG_PATH'
,
$environment
);
unset
(
$environment
);
\ No newline at end of file
laravel/bootstrap/core.php
View file @
d5d97762
...
...
@@ -12,48 +12,13 @@ require SYS_PATH.'config'.EXT;
require
SYS_PATH
.
'loader'
.
EXT
;
/**
* If a Laravel environment has been specified on the server, we will
* add a path to the configuration manager for the environment.
*/
if
(
isset
(
$_SERVER
[
'LARAVEL_ENV'
]))
{
define
(
'ENV_CONFIG_PATH'
,
CONFIG_PATH
.
$_SERVER
[
'LARAVEL_ENV'
]
.
'/'
);
Config
::
glance
(
ENV_CONFIG_PATH
);
}
/**
* Load some core configuration files by default so we don't have to
* let them fall through the Config
load
er. This will allow us to
* let them fall through the Config
pars
er. This will allow us to
* load these files faster for each request.
*/
foreach
(
array
(
'application'
,
'session'
)
as
$file
)
{
$config
=
require
CONFIG_PATH
.
$file
.
EXT
;
if
(
isset
(
$_SERVER
[
'LARAVEL_ENV'
])
and
file_exists
(
$path
=
ENV_CONFIG_PATH
.
$file
.
EXT
))
{
$config
=
array_merge
(
$config
,
require
$path
);
}
Config
::
$items
[
$file
]
=
$config
;
}
/**
* Load the container configuration into the Config class. We load
* this file manually to avoid the overhead of Config::load.
*/
Config
::
$items
[
'container'
]
=
require
SYS_CONFIG_PATH
.
'container'
.
EXT
;
if
(
file_exists
(
$path
=
CONFIG_PATH
.
'container'
.
EXT
))
{
Config
::
$items
[
'container'
]
=
array_merge
(
Config
::
$items
[
'container'
],
require
$path
);
}
if
(
isset
(
$_SERVER
[
'LARAVEL_ENV'
])
and
file_exists
(
$path
=
ENV_CONFIG_PATH
.
'container'
.
EXT
))
{
Config
::
$items
[
'container'
]
=
array_merge
(
Config
::
$items
[
'container'
],
require
$path
);
}
Config
::
load
(
'application'
);
Config
::
load
(
'container'
);
Config
::
load
(
'session'
);
/**
* Bootstrap the application inversion of control (IoC) container.
...
...
@@ -67,7 +32,7 @@ $container = new Container(Config::$items['container']);
IoC
::
$container
=
$container
;
unset
(
$con
fig
,
$con
tainer
);
unset
(
$container
);
/**
* Register the application auto-loader. The auto-loader is responsible
...
...
@@ -79,7 +44,9 @@ spl_autoload_register(array('Laravel\\Loader', 'load'));
Loader
::
$aliases
=
Config
::
$items
[
'application'
][
'aliases'
];
/**
* Define a few convenient global functions.
* 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.
*/
function
e
(
$value
)
{
...
...
laravel/bootstrap/errors.php
View file @
d5d97762
<?php
namespace
Laravel
;
/**
*
Create the exception formatter closure. This function will format
*
the exception message and severity for display and return the two
*
formatted strings in an array
.
*
Define a closure that will return a formatted error message
*
when given an exception. This function will be used by the
*
error handler to create a more readable message
.
*/
$formatter
=
function
(
$e
)
$message
=
function
(
$e
)
{
$file
=
str_replace
(
array
(
APP_PATH
,
SYS_PATH
),
array
(
'APP_PATH/'
,
'SYS_PATH/'
),
$e
->
getFile
());
return
rtrim
(
$e
->
getMessage
(),
'.'
)
.
' in '
.
$file
.
' on line '
.
$e
->
getLine
()
.
'.'
;
};
/**
* 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.
*/
$severity
=
function
(
$e
)
{
$levels
=
array
(
0
=>
'Error'
,
...
...
@@ -23,31 +35,25 @@ $formatter = function($e)
E_STRICT
=>
'Runtime Notice'
,
);
$file
=
str_replace
(
array
(
APP_PATH
,
SYS_PATH
),
array
(
'APP_PATH/'
,
'SYS_PATH/'
),
$e
->
getFile
());
$message
=
rtrim
(
$e
->
getMessage
(),
'.'
)
.
' in '
.
$file
.
' on line '
.
$e
->
getLine
()
.
'.'
;
$severity
=
(
array_key_exists
(
$e
->
getCode
(),
$levels
))
?
$levels
[
$e
->
getCode
()]
:
$e
->
getCode
();
return
array
(
$severity
,
$message
);
return
(
array_key_exists
(
$e
->
getCode
(),
$levels
))
?
$levels
[
$e
->
getCode
()]
:
$e
->
getCode
();
};
/**
* Create the exception handler function. All of the error handlers
* registered with PHP call this closure to keep the code D.R.Y.
* Each of the formatting closures defined above will be passed
* into the handler for convenient use.
*/
$handler
=
function
(
$e
)
use
(
$
formatter
)
$handler
=
function
(
$e
)
use
(
$
message
,
$severity
)
{
list
(
$severity
,
$message
)
=
$formatter
(
$e
);
$config
=
Config
::
get
(
'error'
);
if
(
$config
[
'log'
])
{
call_user_func
(
$config
[
'logger'
],
$e
,
$severity
,
$message
,
$config
);
call_user_func
(
$config
[
'logger'
],
$e
,
$severity
(
$e
),
$message
(
$e
)
,
$config
);
}
call_user_func
(
$config
[
'handler'
],
$e
,
$severity
,
$message
,
$config
);
call_user_func
(
$config
[
'handler'
],
$e
,
$severity
(
$e
),
$message
(
$e
)
,
$config
);
exit
(
1
);
};
...
...
laravel/config.php
View file @
d5d97762
...
...
@@ -16,7 +16,7 @@ class Config {
*
* @var array
*/
public
static
$paths
=
array
(
SYS_CONFIG_PATH
,
CONFIG_PATH
);
public
static
$paths
=
array
(
SYS_CONFIG_PATH
,
CONFIG_PATH
,
ENV_CONFIG_PATH
);
/**
* Determine if a configuration item or file exists.
...
...
@@ -130,7 +130,7 @@ class Config {
* @param string $file
* @return bool
*/
p
rotected
static
function
load
(
$file
)
p
ublic
static
function
load
(
$file
)
{
if
(
isset
(
static
::
$items
[
$file
]))
return
true
;
...
...
@@ -141,7 +141,7 @@ class Config {
// cascading of configuration options from system to application.
foreach
(
static
::
$paths
as
$directory
)
{
if
(
file_exists
(
$path
=
$directory
.
$file
.
EXT
))
if
(
$directory
!==
''
and
file_exists
(
$path
=
$directory
.
$file
.
EXT
))
{
$config
=
array_merge
(
$config
,
require
$path
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment