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
cf6d2699
Commit
cf6d2699
authored
Apr 14, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
951520ac
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
132 additions
and
149 deletions
+132
-149
Model.php
framework/base/Model.php
+2
-2
View.php
framework/base/View.php
+56
-4
ActiveRecord.php
framework/db/ar/ActiveRecord.php
+3
-3
File.php
framework/util/File.php
+0
-139
FileHelper.php
framework/util/FileHelper.php
+70
-0
StringHelper.php
framework/util/StringHelper.php
+1
-1
No files found.
framework/base/Model.php
View file @
cf6d2699
...
...
@@ -9,7 +9,7 @@
namespace
yii\base
;
use
yii\util\
Text
;
use
yii\util\
StringHelper
;
/**
* Model is the base class for data models.
...
...
@@ -443,7 +443,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
public
function
generateAttributeLabel
(
$name
)
{
return
Text
::
camel2words
(
$name
,
true
);
return
StringHelper
::
camel2words
(
$name
,
true
);
}
/**
...
...
framework/base/View.php
View file @
cf6d2699
...
...
@@ -9,19 +9,70 @@
namespace
yii\base
;
use
yii\util\FileHelper
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
View
extends
Component
{
public
function
render
(
$context
,
$_file_
,
$_data_
=
array
())
public
$file
;
public
$name
;
/**
* @var string|array
*/
public
$basePath
;
public
$owner
;
public
$locale
;
public
function
render
(
$_params_
=
array
())
{
// we use special variable names here to avoid conflict with extracted variables
extract
(
$_
data_
,
EXTR_PREFIX_SAME
,
'data'
);
$this
->
resolveViewFile
();
extract
(
$_
params_
,
EXTR_OVERWRITE
);
ob_start
();
ob_implicit_flush
(
false
);
require
(
$
_file_
);
require
(
$
this
->
file
);
return
ob_get_clean
();
}
public
function
resolveViewFile
()
{
if
(
$this
->
file
!==
null
)
{
return
$this
->
file
;
}
if
(
$this
->
name
===
null
||
$this
->
basePath
)
{
}
if
(
empty
(
$viewName
))
return
false
;
if
(
$moduleViewPath
===
null
)
$moduleViewPath
=
$basePath
;
if
((
$renderer
=
Yii
::
app
()
->
getViewRenderer
())
!==
null
)
$extension
=
$renderer
->
fileExtension
;
else
$extension
=
'.php'
;
if
(
$viewName
[
0
]
===
'/'
)
{
if
(
strncmp
(
$viewName
,
'//'
,
2
)
===
0
)
$viewFile
=
$basePath
.
$viewName
;
else
$viewFile
=
$moduleViewPath
.
$viewName
;
}
else
if
(
strpos
(
$viewName
,
'.'
))
$viewFile
=
Yii
::
getPathOfAlias
(
$viewName
);
else
$viewFile
=
$viewPath
.
DIRECTORY_SEPARATOR
.
$viewName
;
if
(
is_file
(
$viewFile
.
$extension
))
return
Yii
::
app
()
->
findLocalizedFile
(
$viewFile
.
$extension
);
else
if
(
$extension
!==
'.php'
&&
is_file
(
$viewFile
.
'.php'
))
return
Yii
::
app
()
->
findLocalizedFile
(
$viewFile
.
'.php'
);
else
return
false
;
}
}
\ No newline at end of file
framework/db/ar/ActiveRecord.php
View file @
cf6d2699
...
...
@@ -18,7 +18,7 @@ use yii\db\dao\Connection;
use
yii\db\dao\TableSchema
;
use
yii\db\dao\Query
;
use
yii\db\dao\Expression
;
use
yii\util\
Text
;
use
yii\util\
StringHelper
;
/**
* ActiveRecord is the base class for classes representing relational data.
...
...
@@ -247,14 +247,14 @@ abstract class ActiveRecord extends Model
/**
* Declares the name of the database table associated with this AR class.
* By default this method returns the class name as the table name by calling [[
Text
::camel2id()]].
* By default this method returns the class name as the table name by calling [[
StringHelper
::camel2id()]].
* For example, 'Customer' becomes 'customer', and 'OrderDetail' becomes 'order_detail'.
* You may override this method if the table is not named after this convention.
* @return string the table name
*/
public
static
function
tableName
()
{
return
Text
::
camel2id
(
basename
(
get_called_class
()),
'_'
);
return
StringHelper
::
camel2id
(
basename
(
get_called_class
()),
'_'
);
}
/**
...
...
framework/util/File.php
deleted
100644 → 0
View file @
951520ac
<?php
/**
* Filesystem helper class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\util
;
/**
* Filesystem helper
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Alex Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class
File
{
/**
* Copies a list of files from one place to another.
* @param array $fileList the list of files to be copied (name=>spec).
* The array keys are names displayed during the copy process, and array values are specifications
* for files to be copied. Each array value must be an array of the following structure:
* <ul>
* <li>source: required, the full path of the file/directory to be copied from</li>
* <li>target: required, the full path of the file/directory to be copied to</li>
* <li>callback: optional, the callback to be invoked when copying a file. The callback function
* should be declared as follows:
* <pre>
* function foo($source,$params)
* </pre>
* where $source parameter is the source file path, and the content returned
* by the function will be saved into the target file.</li>
* <li>params: optional, the parameters to be passed to the callback</li>
* </ul>
* @see buildFileList
*/
public
function
copyFiles
(
$fileList
)
{
$overwriteAll
=
false
;
foreach
(
$fileList
as
$name
=>
$file
)
{
$source
=
strtr
(
$file
[
'source'
],
'/\\'
,
DIRECTORY_SEPARATOR
);
$target
=
strtr
(
$file
[
'target'
],
'/\\'
,
DIRECTORY_SEPARATOR
);
$callback
=
isset
(
$file
[
'callback'
])
?
$file
[
'callback'
]
:
null
;
$params
=
isset
(
$file
[
'params'
])
?
$file
[
'params'
]
:
null
;
if
(
is_dir
(
$source
))
{
$this
->
ensureDirectory
(
$target
);
continue
;
}
if
(
$callback
!==
null
)
$content
=
call_user_func
(
$callback
,
$source
,
$params
);
else
$content
=
file_get_contents
(
$source
);
if
(
is_file
(
$target
))
{
if
(
$content
===
file_get_contents
(
$target
))
{
echo
" unchanged
$name
\n
"
;
continue
;
}
if
(
$overwriteAll
)
echo
" overwrite
$name
\n
"
;
else
{
echo
" exist
$name
\n
"
;
echo
" ...overwrite? [Yes|No|All|Quit] "
;
$answer
=
trim
(
fgets
(
STDIN
));
if
(
!
strncasecmp
(
$answer
,
'q'
,
1
))
return
;
else
if
(
!
strncasecmp
(
$answer
,
'y'
,
1
))
echo
" overwrite
$name
\n
"
;
else
if
(
!
strncasecmp
(
$answer
,
'a'
,
1
))
{
echo
" overwrite
$name
\n
"
;
$overwriteAll
=
true
;
}
else
{
echo
" skip
$name
\n
"
;
continue
;
}
}
}
else
{
$this
->
ensureDirectory
(
dirname
(
$target
));
echo
" generate
$name
\n
"
;
}
file_put_contents
(
$target
,
$content
);
}
}
/**
* Builds the file list of a directory.
* This method traverses through the specified directory and builds
* a list of files and subdirectories that the directory contains.
* The result of this function can be passed to {@link copyFiles}.
* @param string $sourceDir the source directory
* @param string $targetDir the target directory
* @param string $baseDir base directory
* @return array the file list (see {@link copyFiles})
*/
public
function
buildFileList
(
$sourceDir
,
$targetDir
,
$baseDir
=
''
)
{
$list
=
array
();
$handle
=
opendir
(
$sourceDir
);
while
((
$file
=
readdir
(
$handle
))
!==
false
)
{
if
(
$file
===
'.'
||
$file
===
'..'
||
$file
===
'.svn'
||
$file
===
'.yii'
)
continue
;
$sourcePath
=
$sourceDir
.
DIRECTORY_SEPARATOR
.
$file
;
$targetPath
=
$targetDir
.
DIRECTORY_SEPARATOR
.
$file
;
$name
=
$baseDir
===
''
?
$file
:
$baseDir
.
'/'
.
$file
;
$list
[
$name
]
=
array
(
'source'
=>
$sourcePath
,
'target'
=>
$targetPath
);
if
(
is_dir
(
$sourcePath
))
$list
=
array_merge
(
$list
,
$this
->
buildFileList
(
$sourcePath
,
$targetPath
,
$name
));
}
closedir
(
$handle
);
return
$list
;
}
/**
* Creates all parent directories if they do not exist.
* @param string $directory the directory to be checked
*/
public
function
ensureDirectory
(
$directory
)
{
if
(
!
is_dir
(
$directory
))
{
$this
->
ensureDirectory
(
dirname
(
$directory
));
echo
" mkdir "
.
strtr
(
$directory
,
'\\'
,
'/'
)
.
"
\n
"
;
mkdir
(
$directory
);
}
}
}
framework/util/FileHelper.php
0 → 100644
View file @
cf6d2699
<?php
/**
* Filesystem helper class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\util
;
/**
* Filesystem helper
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Alex Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class
FileHelper
{
/**
* Returns the extension name of a file path.
* For example, the path "path/to/something.php" would return "php".
* @param string $path the file path
* @return string the extension name without the dot character.
*/
public
static
function
getExtension
(
$path
)
{
return
pathinfo
(
$path
,
PATHINFO_EXTENSION
);
}
/**
* Returns the localized version of a specified file.
*
* The searching is based on the specified language code. In particular,
* a file with the same name will be looked for under the subdirectory
* whose name is same as the language code. For example, given the file "path/to/view.php"
* and language code "zh_cn", the localized file will be looked for as
* "path/to/zh_cn/view.php". If the file is not found, the original file
* will be returned.
*
* If the target and the source language codes are the same,
* the original file will be returned.
*
* For consistency, it is recommended that the language code is given
* in lower case and in the format of LanguageID_RegionID (e.g. "en_us").
*
* @param string $file the original file
* @param string $targetLanguage the target language that the file should be localized to.
* If not set, the value of [[\yii\base\Application::language]] will be used.
* @param string $sourceLanguage the language that the original file is in.
* If not set, the value of [[\yii\base\Application::sourceLanguage]] will be used.
* @return string the matching localized file, or the original file if the localized version is not found.
* If the target and the source language codes are the same, the original file will be returned.
*/
public
static
function
localize
(
$file
,
$targetLanguage
=
null
,
$sourceLanguage
=
null
)
{
if
(
$targetLanguage
===
null
)
{
$targetLanguage
=
\Yii
::
$application
->
getLanguage
();
}
if
(
$sourceLanguage
===
null
)
{
$sourceLanguage
=
\Yii
::
$application
->
sourceLanguage
;
}
if
(
$targetLanguage
===
$sourceLanguage
)
{
return
$file
;
}
$desiredFile
=
dirname
(
$file
)
.
DIRECTORY_SEPARATOR
.
$sourceLanguage
.
DIRECTORY_SEPARATOR
.
basename
(
$file
);
return
is_file
(
$desiredFile
)
?
$desiredFile
:
$file
;
}
}
framework/util/
Text
.php
→
framework/util/
StringHelper
.php
View file @
cf6d2699
...
...
@@ -16,7 +16,7 @@ namespace yii\util;
* @author Alex Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class
Text
class
StringHelper
{
/**
* Converts a word to its plural form.
...
...
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