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
7865a56d
Commit
7865a56d
authored
May 24, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
21a8f40e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
22 deletions
+30
-22
Module.php
framework/base/Module.php
+10
-22
FileHelper.php
framework/util/FileHelper.php
+20
-0
No files found.
framework/base/Module.php
View file @
7865a56d
...
...
@@ -9,6 +9,8 @@
namespace
yii\base
;
use
yii\util\FileHelper
;
/**
* Module is the base class for module and application classes.
*
...
...
@@ -192,12 +194,7 @@ abstract class Module extends Component implements Initable
*/
public
function
setBasePath
(
$path
)
{
$p
=
\Yii
::
getAlias
(
$path
);
if
(
$p
===
false
||
!
is_dir
(
$p
))
{
throw
new
Exception
(
'Invalid base path: '
.
$path
);
}
else
{
$this
->
_basePath
=
realpath
(
$p
);
}
$this
->
_basePath
=
FileHelper
::
ensureDirectory
(
$path
);
}
/**
...
...
@@ -222,12 +219,7 @@ abstract class Module extends Component implements Initable
*/
public
function
setControllerPath
(
$path
)
{
$p
=
\Yii
::
getAlias
(
$path
);
if
(
$p
===
false
||
!
is_dir
(
$p
))
{
throw
new
Exception
(
'Invalid controller path: '
.
$path
);
}
else
{
$this
->
_controllerPath
=
realpath
(
$p
);
}
$this
->
_controllerPath
=
FileHelper
::
ensureDirectory
(
$path
);
}
/**
...
...
@@ -244,15 +236,13 @@ abstract class Module extends Component implements Initable
}
/**
* Sets the directory that contains the view files.
* @param string $path the root directory of view files.
* @throws
CException if the directory does not exist.
* @throws
Exception if the directory is invalid
*/
public
function
setViewPath
(
$path
)
{
if
((
$this
->
_viewPath
=
realpath
(
$path
))
===
false
||
!
is_dir
(
$this
->
_viewPath
))
{
throw
new
CException
(
Yii
::
t
(
'yii'
,
'The view path "{path}" is not a valid directory.'
,
array
(
'{path}'
=>
$path
)));
}
$this
->
_viewPath
=
FileHelper
::
ensureDirectory
(
$path
);
}
/**
...
...
@@ -269,15 +259,13 @@ abstract class Module extends Component implements Initable
}
/**
* Sets the directory that contains the layout files.
* @param string $path the root directory of layout files.
* @throws
CException if the directory does not exist.
* @throws
Exception if the directory is invalid
*/
public
function
setLayoutPath
(
$path
)
{
if
((
$this
->
_layoutPath
=
realpath
(
$path
))
===
false
||
!
is_dir
(
$this
->
_layoutPath
))
{
throw
new
CException
(
Yii
::
t
(
'yii'
,
'The layout path "{path}" is not a valid directory.'
,
array
(
'{path}'
=>
$path
)));
}
$this
->
_layoutPath
=
FileHelper
::
ensureDirectory
(
$path
);
}
/**
...
...
framework/util/FileHelper.php
View file @
7865a56d
...
...
@@ -9,6 +9,8 @@
namespace
yii\util
;
use
yii\base\Exception
;
/**
* Filesystem helper
*
...
...
@@ -30,6 +32,24 @@ class FileHelper
}
/**
* Checks the given path and ensures it is a directory.
* This method will call `realpath()` to "normalize" the given path.
* If the given path does not refer to an existing directory, an exception will be thrown.
* @param string $path the given path. This can also be a path alias.
* @return string the normalized path
* @throws Exception if the path does not refer to an existing directory.
*/
public
static
function
ensureDirectory
(
$path
)
{
$p
=
\Yii
::
getAlias
(
$path
);
if
(
$p
!==
false
&&
(
$p
=
realpath
(
$p
))
!==
false
&&
is_dir
(
$p
))
{
return
$p
;
}
else
{
throw
new
Exception
(
'Directory does not exist: '
.
$path
);
}
}
/**
* Returns the localized version of a specified file.
*
* The searching is based on the specified language code. In particular,
...
...
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