Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
c314c0ab
Commit
c314c0ab
authored
Jan 18, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added namespace to directory mapping support in autoloader.
parent
28c3ef6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
5 deletions
+36
-5
autoloader.php
laravel/autoloader.php
+36
-5
No files found.
laravel/autoloader.php
View file @
c314c0ab
...
...
@@ -23,6 +23,13 @@ class Autoloader {
*/
public
static
$psr
=
array
();
/**
* The mappings for namespaces to directories.
*
* @var array
*/
public
static
$namespaces
=
array
();
/**
* Load the file corresponding to a given class.
*
...
...
@@ -59,14 +66,24 @@ class Autoloader {
// match the name of their bundle.
elseif
((
$slash
=
strpos
(
$class
,
'\\'
))
!==
false
)
{
$bundle
=
substr
(
$class
,
0
,
$slash
);
$namespace
=
substr
(
$class
,
0
,
$slash
);
// If the class namespace is mapped to a directory, we will load
// the class using the PSR-0 standards from that directory by
// passing the directory into the "load_psr" method.
if
(
isset
(
static
::
$namespaces
[
$namespace
]))
{
$directory
=
static
::
$namespaces
[
$namespace
];
return
static
::
load_psr
(
substr
(
$class
,
$slash
+
1
),
$directory
);
}
// It's very important that we make sure the bundle has not been
// started here. If we don't, we'll end up in an infinite loop
// attempting to load a bundle's class.
if
(
Bundle
::
exists
(
$
bundle
)
and
!
Bundle
::
started
(
$bundl
e
))
if
(
Bundle
::
exists
(
$
namespace
)
and
!
Bundle
::
started
(
$namespac
e
))
{
Bundle
::
start
(
$
bundl
e
);
Bundle
::
start
(
$
namespac
e
);
static
::
load
(
$class
);
}
...
...
@@ -79,19 +96,22 @@ class Autoloader {
* Attempt to resolve a class using the PSR-0 standard.
*
* @param string $class
* @param string $directory
* @return void
*/
protected
static
function
load_psr
(
$class
)
protected
static
function
load_psr
(
$class
,
$directory
=
null
)
{
// The PSR-0 standard indicates that class namespace slashes or
// underscores should be used to indicate the directory tree in
// which the class resides.
$file
=
str_replace
(
array
(
'\\'
,
'_'
),
'/'
,
$class
);
$directories
=
(
is_nulL
(
$directory
))
?
static
::
$psr
:
array
(
$directory
);
// Once we have formatted the class name, we will simply spin
// through the registered PSR-0 directories and attempt to
// locate and load the class into the script.
foreach
(
static
::
$psr
as
$directory
)
foreach
(
$directories
as
$directory
)
{
if
(
file_exists
(
$path
=
$directory
.
strtolower
(
$file
)
.
EXT
))
{
...
...
@@ -149,4 +169,15 @@ class Autoloader {
static
::
$psr
=
array_unique
(
array_merge
(
static
::
$psr
,
$directories
));
}
/**
* Map namespaces to directories.
*
* @param string $namespace
* @param string $path
*/
public
static
function
namespaces
(
$mappings
)
{
static
::
$namespaces
=
array_merge
(
static
::
$namespaces
,
$mappings
);
}
}
\ No newline at end of file
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