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
ca5dfa40
Commit
ca5dfa40
authored
Feb 27, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing underscored library auto-loading.
Signed-off-by:
Taylor Otwell
<
taylorotwell@gmail.com
>
parent
2fdde4ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
16 deletions
+63
-16
autoloader.php
laravel/autoloader.php
+59
-13
helpers.php
laravel/helpers.php
+4
-3
No files found.
laravel/autoloader.php
View file @
ca5dfa40
...
@@ -23,6 +23,13 @@ class Autoloader {
...
@@ -23,6 +23,13 @@ class Autoloader {
*/
*/
public
static
$namespaces
=
array
();
public
static
$namespaces
=
array
();
/**
* The mappings for underscored libraries to directories.
*
* @var array
*/
public
static
$underscored
=
array
();
/**
/**
* All of the class aliases registered with the auto-loader.
* All of the class aliases registered with the auto-loader.
*
*
...
@@ -56,21 +63,49 @@ class Autoloader {
...
@@ -56,21 +63,49 @@ class Autoloader {
require
static
::
$mappings
[
$class
];
require
static
::
$mappings
[
$class
];
}
}
$namespace
=
root_namespace
(
$class
)
.
'\\'
;
// If the class namespace is mapped to a directory, we will load the
// If the class namespace is mapped to a directory, we will load the
// class using the PSR-0 standards from that directory accounting
// class using the PSR-0 standards from that directory accounting
// for the root of the namespace by trimming it.
// for the root of the namespace by trimming it off.
$namespace
=
root_namespace
(
$class
)
.
'\\'
;
if
(
isset
(
static
::
$namespaces
[
$namespace
]))
if
(
isset
(
static
::
$namespaces
[
$namespace
]))
{
{
$
class
=
substr
(
$class
,
strlen
(
$namespace
))
;
$
directory
=
static
::
$namespaces
[
$namespace
]
;
return
static
::
load_
psr
(
$class
,
static
::
$namespaces
[
$namespace
]
);
return
static
::
load_
namespaced
(
$class
,
$namespace
,
$directory
);
}
}
// If the class uses PEARish style underscores for indicating its
// directory structure, we will load the class using the PSR-0
// standards from that directory, trimming the root.
$namespace
=
root_namespace
(
$class
,
'_'
)
.
'_'
;
if
(
isset
(
static
::
$underscored
[
$namespace
]))
{
$directory
=
static
::
$underscored
[
$namespace
];
return
static
::
load_namespaced
(
$class
,
$namespace
,
$directory
);
}
// If all else fails we will just iterator through the mapped
// PSR-0 directories looking for the class. This is the last
// resort and slowest loading option for the class.
static
::
load_psr
(
$class
);
static
::
load_psr
(
$class
);
}
}
/**
* Load a namespaced class from a given directory.
*
* @param string $class
* @param string $namespace
* @param string $directory
* @return void
*/
protected
static
function
load_namespaced
(
$class
,
$namespace
,
$directory
)
{
return
static
::
load_psr
(
substr
(
$class
,
strlen
(
$namespace
)),
$directory
);
}
/**
/**
* Attempt to resolve a class using the PSR-0 standard.
* Attempt to resolve a class using the PSR-0 standard.
*
*
...
@@ -149,17 +184,32 @@ class Autoloader {
...
@@ -149,17 +184,32 @@ class Autoloader {
*/
*/
public
static
function
underscored
(
$mappings
)
public
static
function
underscored
(
$mappings
)
{
{
static
::
namespaces
(
$mappings
,
'_'
);
$mappings
=
static
::
format_mappings
(
$mappings
,
'_'
);
static
::
$underscored
=
array_merge
(
$mappings
,
static
::
$underscored
);
}
}
/**
/**
* Map namespaces to directories.
* Map namespaces to directories.
*
*
* @param array $mappings
* @param array $mappings
* @param string $append
* @return void
* @return void
*/
*/
public
static
function
namespaces
(
$mappings
,
$append
=
'\\'
)
public
static
function
namespaces
(
$mappings
)
{
$mappings
=
static
::
format_mappings
(
$mappings
,
'\\'
);
static
::
$namespaces
=
array_merge
(
$mappings
,
static
::
$namespaces
);
}
/**
* Format an array of namespace to directory mappings.
*
* @param array $mappings
* @param string $append
* @return array
*/
protected
static
function
format_mappings
(
$mappings
,
$append
)
{
{
foreach
(
$mappings
as
$namespace
=>
$directory
)
foreach
(
$mappings
as
$namespace
=>
$directory
)
{
{
...
@@ -173,11 +223,7 @@ class Autoloader {
...
@@ -173,11 +223,7 @@ class Autoloader {
$namespaces
[
$namespace
]
=
head
(
static
::
format
(
$directory
));
$namespaces
[
$namespace
]
=
head
(
static
::
format
(
$directory
));
}
}
// We'll array_merge the new mappings onto the front of the array so
return
$namespaces
;
// derivative namespaces are not always shadowed by their parents.
// For instance, when mappings Laravel\Docs, we don't want the
// main Laravel namespace to always override it.
static
::
$namespaces
=
array_merge
(
$namespaces
,
static
::
$namespaces
);
}
}
/**
/**
...
...
laravel/helpers.php
View file @
ca5dfa40
...
@@ -365,13 +365,14 @@ function str_finish($value, $cap)
...
@@ -365,13 +365,14 @@ function str_finish($value, $cap)
* Get the root namespace of a given class.
* Get the root namespace of a given class.
*
*
* @param string $class
* @param string $class
* @param string $separator
* @return string
* @return string
*/
*/
function
root_namespace
(
$class
)
function
root_namespace
(
$class
,
$separator
=
'\\'
)
{
{
if
(
str_contains
(
$class
,
'\\'
))
if
(
str_contains
(
$class
,
$separator
))
{
{
return
head
(
explode
(
'\\'
,
$class
));
return
head
(
explode
(
$separator
,
$class
));
}
}
}
}
...
...
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