Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
951520ac
Commit
951520ac
authored
Apr 13, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved autoloading.
parent
6d917566
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
YiiBase.php
framework/YiiBase.php
+21
-14
No files found.
framework/YiiBase.php
View file @
951520ac
...
@@ -117,8 +117,9 @@ class YiiBase
...
@@ -117,8 +117,9 @@ class YiiBase
* To import a class or a directory, one can use either path alias or class name (can be namespaced):
* To import a class or a directory, one can use either path alias or class name (can be namespaced):
*
*
* - `@app/components/GoogleMap`: importing the `GoogleMap` class with a path alias;
* - `@app/components/GoogleMap`: importing the `GoogleMap` class with a path alias;
* - `GoogleMap`: importing the `GoogleMap` class with a class name;
* - `@app/components/*`: importing the whole `components` directory with a path alias;
* - `@app/components/*`: importing the whole `components` directory with a path alias.
* - `GoogleMap`: importing the `GoogleMap` class with a class name. [[autoload()]] will be used
* when this class is used for the first time.
*
*
* @param string $alias path alias or a simple class name to be imported
* @param string $alias path alias or a simple class name to be imported
* @param boolean $forceInclude whether to include the class file immediately. If false, the class file
* @param boolean $forceInclude whether to include the class file immediately. If false, the class file
...
@@ -160,7 +161,7 @@ class YiiBase
...
@@ -160,7 +161,7 @@ class YiiBase
require
(
$path
.
"/
$className
.php"
);
require
(
$path
.
"/
$className
.php"
);
self
::
$_imported
[
$alias
]
=
$className
;
self
::
$_imported
[
$alias
]
=
$className
;
}
else
{
}
else
{
self
::
$classMap
[
$className
]
=
$path
.
"/
$className
.php"
;
self
::
$classMap
[
$className
]
=
$path
.
DIRECTORY_SEPARATOR
.
"
$className
.php"
;
}
}
return
$className
;
return
$className
;
}
else
{
}
else
{
...
@@ -257,33 +258,39 @@ class YiiBase
...
@@ -257,33 +258,39 @@ class YiiBase
return
true
;
return
true
;
}
}
// namespaced class, e.g. yii\base\Component
if
(
strpos
(
$className
,
'\\'
)
!==
false
)
{
if
(
strpos
(
$className
,
'\\'
)
!==
false
)
{
// namespaced class, e.g. yii\base\Component
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component
// convert namespace to path alias, e.g. yii\base\Component to @yii/base/Component
$alias
=
'@'
.
str_replace
(
'\\'
,
'/'
,
ltrim
(
$className
,
'\\'
));
$alias
=
'@'
.
str_replace
(
'\\'
,
'/'
,
ltrim
(
$className
,
'\\'
));
if
((
$path
=
static
::
getAlias
(
$alias
))
!==
false
)
{
if
((
$path
=
static
::
getAlias
(
$alias
))
!==
false
)
{
include
(
$path
.
'.php'
);
$classFile
=
$path
.
'.php'
;
return
true
;
}
}
return
false
;
}
elseif
((
$pos
=
strpos
(
$className
,
'_'
))
!==
false
)
{
}
// PEAR-styled class, e.g. PHPUnit_Framework_TestCase
// PEAR-styled class, e.g. PHPUnit_Framework_TestCase
if
((
$pos
=
strpos
(
$className
,
'_'
))
!==
false
)
{
// convert class name to path alias, e.g. PHPUnit_Framework_TestCase to @PHPUnit/Framework/TestCase
// convert class name to path alias, e.g. PHPUnit_Framework_TestCase to @PHPUnit/Framework/TestCase
$alias
=
'@'
.
str_replace
(
'_'
,
'/'
,
$className
);
$alias
=
'@'
.
str_replace
(
'_'
,
'/'
,
$className
);
if
((
$path
=
static
::
getAlias
(
$alias
))
!==
false
)
{
if
((
$path
=
static
::
getAlias
(
$alias
))
!==
false
)
{
include
(
$path
.
'.php'
);
$classFile
=
$path
.
'.php'
;
return
true
;
}
}
}
}
if
(
!
isset
(
$classFile
))
{
// search in include paths
// search in include paths
foreach
(
self
::
$classPath
as
$path
)
{
foreach
(
self
::
$classPath
as
$path
)
{
$classFile
=
$path
.
DIRECTORY_SEPARATOR
.
$className
.
'.php'
;
$path
.=
DIRECTORY_SEPARATOR
.
$className
.
'.php'
;
if
(
is_file
(
$classFile
))
{
if
(
is_file
(
$path
))
{
$classFile
=
$path
;
$alias
=
$className
;
}
}
}
if
(
isset
(
$classFile
,
$alias
))
{
if
(
!
YII_DEBUG
||
basename
(
realpath
(
$classFile
))
===
basename
(
$alias
)
.
'.php'
)
{
include
(
$classFile
);
include
(
$classFile
);
return
true
;
return
true
;
}
else
{
throw
new
\yii\base\Exception
(
"Class name '
$className
' does not match the class file '"
.
realpath
(
$classFile
)
.
"'. Have you checked their case sensitivity?"
);
}
}
}
}
...
...
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