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
d44c076e
Commit
d44c076e
authored
Oct 31, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring the autoloader.
parent
f824cc0f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
53 deletions
+24
-53
application/libraries/.gitignore
+0
-0
application/models/.gitignore
+0
-0
laravel/autoloader.php
+21
-51
laravel/bootstrap/constants.php
+2
-1
laravel/bootstrap/core.php
+1
-1
No files found.
application/
class
es/.gitignore
→
application/
librari
es/.gitignore
View file @
d44c076e
File moved
application/models/.gitignore
0 → 100644
View file @
d44c076e
laravel/autoloader.php
View file @
d44c076e
...
...
@@ -3,36 +3,18 @@
class
Autoloader
{
/**
* The class alises defined for the application.
*
* @var array
*/
protected
$aliases
=
array
();
/**
* The PSR-0 compliant libraries registered with the auto-loader.
*
* @var array
*/
protected
$libraries
=
array
();
protected
static
$libraries
=
array
();
/**
* The paths to be searched by the auto-loader.
*
* @var array
*/
protected
$paths
=
array
(
BASE_PATH
,
CLASS_PATH
);
/**
* Create a new auto-loader instance.
*
* @param array $aliases
* @return void
*/
public
function
__construct
(
$aliases
=
array
())
{
$this
->
aliases
=
$aliases
;
}
protected
static
$paths
=
array
(
BASE_PATH
,
MODEL_PATH
,
LIBRARY_PATH
);
/**
* Load the file corresponding to a given class.
...
...
@@ -40,30 +22,30 @@ class Autoloader {
* @param string $class
* @return void
*/
public
function
load
(
$class
)
public
static
function
load
(
$class
)
{
// Most of the core classes are aliases for convenient access in spite
//
of the namespace. If an alias is defined for the class, we will load
//
the
alias and bail out of the auto-load method.
if
(
array_key_exists
(
$class
,
$this
->
aliases
))
// Most of the core classes are aliases for convenient access in spite
of
//
the namespace. If an alias is defined for the class, we will load the
// alias and bail out of the auto-load method.
if
(
array_key_exists
(
$class
,
Config
::
$items
[
'application'
][
'aliases'
]
))
{
return
class_alias
(
$this
->
aliases
[
$class
],
$class
);
return
class_alias
(
Config
::
$items
[
'application'
][
'aliases'
]
[
$class
],
$class
);
}
$file
=
str_replace
(
'\\'
,
'/'
,
$class
);
$namespace
=
substr
(
$class
,
0
,
strpos
(
$class
,
'\\'
));
// If the class namespace exists in the libraries array, it means that
//
the library is PSR-0 compliant, and we will load it following those
//
standards. This allows us to add many third-party libraries to an
// a
pplication and be a
ble to auto-load them automatically.
if
(
array_key_exists
(
$namespace
,
$this
->
libraries
))
// If the class namespace exists in the libraries array, it means that
the
//
library is PSR-0 compliant, and we will load it following those standards.
//
This allows us to add many third-party libraries to an application and be
// able to auto-load them automatically.
if
(
array_key_exists
(
$namespace
,
static
::
$
libraries
))
{
require
CLASS_PATH
.
$this
->
psr
(
$file
);
require
LIBRARY_PATH
.
str_replace
(
'_'
,
'/'
,
$file
);
}
foreach
(
$this
->
paths
as
$path
)
foreach
(
static
::
$
paths
as
$path
)
{
if
(
file_exists
(
$path
=
$path
.
strtolower
(
$file
)
.
EXT
))
{
...
...
@@ -73,26 +55,15 @@ class Autoloader {
}
}
// If the namespace exists in the
class
es directory, we will assume the
// library is PSR-0 compliant, and will add the namespace to the array
//
of
libraries and load the class accordingly.
if
(
is_dir
(
CLASS
_PATH
.
$namespace
))
// If the namespace exists in the
librari
es directory, we will assume the
// library is PSR-0 compliant, and will add the namespace to the array
of
// libraries and load the class accordingly.
if
(
is_dir
(
LIBRARY
_PATH
.
$namespace
))
{
$this
->
libraries
[]
=
$namespace
;
static
::
$
libraries
[]
=
$namespace
;
require
CLASS_PATH
.
$this
->
psr
(
$file
);
require
LIBRARY_PATH
.
str_replace
(
'_'
,
'/'
,
$file
);
}
}
/**
* Format a path for PSR-0 compliant auto-loading.
*
* @param string $file
* @return string
*/
protected
function
psr
(
$file
)
{
return
str_replace
(
'_'
,
'/'
,
$file
);
}
}
\ No newline at end of file
laravel/bootstrap/constants.php
View file @
d44c076e
...
...
@@ -26,11 +26,12 @@ unset($application, $public, $storage, $laravel);
$constants
=
array
(
'CACHE_PATH'
=>
STORAGE_PATH
.
'cache/'
,
'CLASS_PATH'
=>
APP_PATH
.
'classes/'
,
'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/'
,
...
...
laravel/bootstrap/core.php
View file @
d44c076e
...
...
@@ -14,7 +14,7 @@ Config::load('session');
IoC
::
bootstrap
();
spl_autoload_register
(
array
(
IoC
::
container
()
->
core
(
'autoloader'
)
,
'load'
));
spl_autoload_register
(
array
(
'Laravel\\Autoloader'
,
'load'
));
function
e
(
$value
)
{
...
...
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