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
9d1b9718
Commit
9d1b9718
authored
Apr 15, 2012
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
e3cb887c
cf6d2699
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
153 additions
and
163 deletions
+153
-163
YiiBase.php
framework/YiiBase.php
+21
-14
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/YiiBase.php
View file @
9d1b9718
...
@@ -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?"
);
}
}
}
}
...
...
framework/base/Model.php
View file @
9d1b9718
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
namespace
yii\base
;
namespace
yii\base
;
use
yii\util\
Text
;
use
yii\util\
StringHelper
;
/**
/**
* Model is the base class for data models.
* Model is the base class for data models.
...
@@ -443,7 +443,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -443,7 +443,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
public
function
generateAttributeLabel
(
$name
)
public
function
generateAttributeLabel
(
$name
)
{
{
return
Text
::
camel2words
(
$name
,
true
);
return
StringHelper
::
camel2words
(
$name
,
true
);
}
}
/**
/**
...
...
framework/base/View.php
View file @
9d1b9718
...
@@ -9,19 +9,70 @@
...
@@ -9,19 +9,70 @@
namespace
yii\base
;
namespace
yii\base
;
use
yii\util\FileHelper
;
/**
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
View
extends
Component
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
$this
->
resolveViewFile
();
extract
(
$_
data_
,
EXTR_PREFIX_SAME
,
'data'
);
extract
(
$_
params_
,
EXTR_OVERWRITE
);
ob_start
();
ob_start
();
ob_implicit_flush
(
false
);
ob_implicit_flush
(
false
);
require
(
$
_file_
);
require
(
$
this
->
file
);
return
ob_get_clean
();
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 @
9d1b9718
...
@@ -18,7 +18,7 @@ use yii\db\dao\Connection;
...
@@ -18,7 +18,7 @@ use yii\db\dao\Connection;
use
yii\db\dao\TableSchema
;
use
yii\db\dao\TableSchema
;
use
yii\db\dao\Query
;
use
yii\db\dao\Query
;
use
yii\db\dao\Expression
;
use
yii\db\dao\Expression
;
use
yii\util\
Text
;
use
yii\util\
StringHelper
;
/**
/**
* ActiveRecord is the base class for classes representing relational data.
* ActiveRecord is the base class for classes representing relational data.
...
@@ -247,14 +247,14 @@ abstract class ActiveRecord extends Model
...
@@ -247,14 +247,14 @@ abstract class ActiveRecord extends Model
/**
/**
* Declares the name of the database table associated with this AR class.
* 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'.
* For example, 'Customer' becomes 'customer', and 'OrderDetail' becomes 'order_detail'.
* You may override this method if the table is not named after this convention.
* You may override this method if the table is not named after this convention.
* @return string the table name
* @return string the table name
*/
*/
public
static
function
tableName
()
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 @
e3cb887c
<?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 @
9d1b9718
<?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 @
9d1b9718
...
@@ -16,7 +16,7 @@ namespace yii\util;
...
@@ -16,7 +16,7 @@ namespace yii\util;
* @author Alex Makarov <sam@rmcreative.ru>
* @author Alex Makarov <sam@rmcreative.ru>
* @since 2.0
* @since 2.0
*/
*/
class
Text
class
StringHelper
{
{
/**
/**
* Converts a word to its plural form.
* 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