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
618980c6
Commit
618980c6
authored
Feb 06, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improvements to autoloader namespace handling.
parent
bc1a7d07
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
29 deletions
+49
-29
autoloader.php
laravel/autoloader.php
+49
-29
No files found.
laravel/autoloader.php
View file @
618980c6
...
...
@@ -56,19 +56,21 @@ class Autoloader {
require
static
::
$mappings
[
$class
];
}
elseif
((
$slash
=
strpos
(
$class
,
'\\'
))
!==
false
)
// If the class namespace is mapped to a directory, we will load the
// class using the PSR-0 standards from that directory; however, we
// will trim off the beginning of the namespace to account for
// the root of the mapped directory.
if
(
!
is_null
(
$info
=
static
::
namespaced
(
$class
)))
{
$
namespace
=
substr
(
$class
,
0
,
$slash
);
$
class
=
substr
(
$class
,
strlen
(
$info
[
'namespace'
])
);
// If the class namespace is mapped to a directory, we will load the class
// using the PSR-0 standards from that directory; however, we will trim
// off the beginning of the namespace to account for files in the root
// of the mapped directory.
if
(
!
is_null
(
$directory
=
static
::
directory
(
$class
)))
{
return
static
::
load_psr
(
substr
(
$class
,
$slash
+
1
),
$directory
);
return
static
::
load_psr
(
$class
,
$info
[
'directory'
]);
}
elseif
((
$slash
=
strpos
(
$class
,
'\\'
))
!==
false
)
{
$namespace
=
substr
(
$class
,
0
,
$slash
);
// If the class is namespaced to an existing bundle and the bundle has
// not been started, we will start the bundle and attempt to load the
// class file again. If that fails, an error will be thrown by PHP.
...
...
@@ -91,23 +93,6 @@ class Autoloader {
static
::
load_psr
(
$class
);
}
/**
* Get the directory associated with a given namespaced class.
*
* @param string $class
* @return string
*/
protected
static
function
directory
(
$class
)
{
foreach
(
static
::
$namespaces
as
$namespace
=>
$directory
)
{
if
(
starts_with
(
$class
,
$namespace
))
{
return
$directory
;
}
}
}
/**
* Attempt to resolve a class using the PSR-0 standard.
*
...
...
@@ -154,6 +139,26 @@ class Autoloader {
}
}
/**
* Get the directory for a given namespaced class.
*
* @param string $class
* @return string
*/
protected
static
function
namespaced
(
$class
)
{
foreach
(
static
::
$namespaces
as
$namespace
=>
$directory
)
{
// If the class begins with one of the registered namespaces,
// we'll return both the namespace and the directory, which
// will allow us to use PSR-0 to load the class.
if
(
starts_with
(
$class
,
$namespace
))
{
return
compact
(
'namespace'
,
'directory'
);
}
}
}
/**
* Register an array of class to path mappings.
*
...
...
@@ -203,11 +208,26 @@ class Autoloader {
*/
public
static
function
namespaces
(
$mappings
)
{
$directories
=
static
::
format
(
array_values
(
$mappings
));
foreach
(
$mappings
as
$namespace
=>
$directory
)
{
$namespace
=
trim
(
$namespace
,
'\\'
)
.
'\\'
;
$mappings
=
array_combine
(
array_keys
(
$mappings
),
$directories
);
static
::
$namespaces
[
$namespace
]
=
head
(
static
::
format
(
$directory
));
}
}
static
::
$namespaces
=
array_merge
(
static
::
$namespaces
,
$mappings
);
/**
* Register underscored "namespaces" to directory mappings.
*
* @param array $mappings
* @return void
*/
public
static
function
underscored
(
$mappings
)
{
foreach
(
$mappings
as
$namespace
=>
$directory
)
{
static
::
$namespaces
[
$namespace
.
'_'
]
=
head
(
static
::
format
(
$directory
));
}
}
/**
...
...
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