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
a3dd0d57
Commit
a3dd0d57
authored
11 years ago
by
Paul Klimov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2 into email-swift-2
parents
b611c424
2a71c72d
Hide whitespace changes
Inline
Side-by-side
Showing
97 changed files
with
865 additions
and
381 deletions
+865
-381
main.php
apps/advanced/backend/config/main.php
+1
-0
composer.json
apps/advanced/composer.json
+2
-2
main.php
apps/advanced/console/config/main.php
+1
-0
index.php
apps/advanced/environments/dev/frontend/web/index.php
+0
-1
yii
apps/advanced/environments/dev/yii
+0
-1
index.php
apps/advanced/environments/prod/frontend/web/index.php
+0
-1
yii
apps/advanced/environments/prod/yii
+0
-1
main.php
apps/advanced/frontend/config/main.php
+1
-0
composer.json
apps/basic/composer.json
+3
-3
console.php
apps/basic/config/console.php
+1
-2
web.php
apps/basic/config/web.php
+1
-0
index-test.php
apps/basic/web/index-test.php
+0
-1
index.php
apps/basic/web/index.php
+0
-1
yii
apps/basic/yii
+0
-1
apps-advanced.md
docs/guide/apps-advanced.md
+2
-2
apps-basic.md
docs/guide/apps-basic.md
+3
-3
composer.json
extensions/composer/composer.json
+1
-1
InstallHandler.php
extensions/composer/yii/composer/InstallHandler.php
+0
-97
Installer.php
extensions/composer/yii/composer/Installer.php
+3
-38
Plugin.php
extensions/composer/yii/composer/Plugin.php
+2
-2
AccordionAsset.php
extensions/jui/yii/jui/AccordionAsset.php
+1
-0
Extension.php
extensions/jui/yii/jui/Extension.php
+27
-0
BaseYii.php
framework/yii/BaseYii.php
+6
-31
Application.php
framework/yii/base/Application.php
+0
-4
Model.php
framework/yii/base/Model.php
+7
-2
Module.php
framework/yii/base/Module.php
+1
-1
Theme.php
framework/yii/base/Theme.php
+0
-1
Carousel.php
framework/yii/bootstrap/Carousel.php
+2
-2
Dropdown.php
framework/yii/bootstrap/Dropdown.php
+2
-0
Nav.php
framework/yii/bootstrap/Nav.php
+1
-1
Tabs.php
framework/yii/bootstrap/Tabs.php
+5
-1
Widget.php
framework/yii/bootstrap/Widget.php
+0
-1
CaptchaValidator.php
framework/yii/captcha/CaptchaValidator.php
+5
-8
ArrayDataProvider.php
framework/yii/data/ArrayDataProvider.php
+1
-1
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+6
-12
Generator.php
framework/yii/gii/generators/crud/Generator.php
+0
-1
action.php
framework/yii/gii/generators/form/templates/action.php
+1
-1
form.php
framework/yii/gii/generators/form/templates/form.php
+4
-4
Generator.php
framework/yii/gii/generators/model/Generator.php
+4
-4
view.php
framework/yii/gii/generators/module/templates/view.php
+5
-5
view.php
framework/yii/gii/views/default/view.php
+0
-1
files.php
framework/yii/gii/views/default/view/files.php
+0
-1
results.php
framework/yii/gii/views/default/view/results.php
+0
-4
ActionColumn.php
framework/yii/grid/ActionColumn.php
+0
-2
DataColumn.php
framework/yii/grid/DataColumn.php
+4
-4
GridView.php
framework/yii/grid/GridView.php
+0
-2
BaseArrayHelper.php
framework/yii/helpers/BaseArrayHelper.php
+3
-11
FallbackMessageFormatter.php
framework/yii/i18n/FallbackMessageFormatter.php
+306
-0
I18N.php
framework/yii/i18n/I18N.php
+18
-4
MessageFormatter.php
framework/yii/i18n/MessageFormatter.php
+13
-3
Logger.php
framework/yii/log/Logger.php
+1
-1
YiiRequirementChecker.php
framework/yii/requirements/YiiRequirementChecker.php
+21
-21
requirements.php
framework/yii/requirements/requirements.php
+14
-14
index.php
framework/yii/requirements/views/web/index.php
+6
-6
BooleanValidator.php
framework/yii/validators/BooleanValidator.php
+2
-2
CompareValidator.php
framework/yii/validators/CompareValidator.php
+2
-2
DateValidator.php
framework/yii/validators/DateValidator.php
+3
-1
FileValidator.php
framework/yii/validators/FileValidator.php
+5
-5
NumberValidator.php
framework/yii/validators/NumberValidator.php
+2
-2
RequiredValidator.php
framework/yii/validators/RequiredValidator.php
+1
-1
StringValidator.php
framework/yii/validators/StringValidator.php
+3
-3
UniqueValidator.php
framework/yii/validators/UniqueValidator.php
+1
-1
Validator.php
framework/yii/validators/Validator.php
+3
-3
AccessControl.php
framework/yii/web/AccessControl.php
+3
-3
AssetBundle.php
framework/yii/web/AssetBundle.php
+10
-1
Request.php
framework/yii/web/Request.php
+1
-5
Session.php
framework/yii/web/Session.php
+3
-6
YiiAsset.php
framework/yii/web/YiiAsset.php
+0
-3
ActiveField.php
framework/yii/widgets/ActiveField.php
+0
-1
ActiveForm.php
framework/yii/widgets/ActiveForm.php
+89
-0
BaseListView.php
framework/yii/widgets/BaseListView.php
+13
-11
Menu.php
framework/yii/widgets/Menu.php
+3
-3
ActiveRecord.php
tests/unit/data/ar/ActiveRecord.php
+0
-2
CacheTestCase.php
tests/unit/framework/caching/CacheTestCase.php
+0
-1
RedisCacheTest.php
tests/unit/framework/caching/RedisCacheTest.php
+0
-1
ZendDataCacheTest.php
tests/unit/framework/caching/ZendDataCacheTest.php
+0
-1
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+0
-1
CommandTest.php
tests/unit/framework/db/CommandTest.php
+0
-3
QueryTest.php
tests/unit/framework/db/QueryTest.php
+0
-3
CubridQueryBuilderTest.php
tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php
+0
-1
FallbackMessageFormatterTest.php
tests/unit/framework/i18n/FallbackMessageFormatterTest.php
+156
-0
GettextMessageSourceTest.php
tests/unit/framework/i18n/GettextMessageSourceTest.php
+0
-1
I18NTest.php
tests/unit/framework/i18n/I18NTest.php
+6
-1
BooleanValidatorTest.php
tests/unit/framework/validators/BooleanValidatorTest.php
+6
-0
CompareValidatorTest.php
tests/unit/framework/validators/CompareValidatorTest.php
+5
-0
DateValidatorTest.php
tests/unit/framework/validators/DateValidatorTest.php
+7
-0
DefaultValueValidatorTest.php
...s/unit/framework/validators/DefaultValueValidatorTest.php
+6
-0
EmailValidatorTest.php
tests/unit/framework/validators/EmailValidatorTest.php
+6
-0
ExistValidatorTest.php
tests/unit/framework/validators/ExistValidatorTest.php
+1
-0
FilterValidatorTest.php
tests/unit/framework/validators/FilterValidatorTest.php
+6
-0
NumberValidatorTest.php
tests/unit/framework/validators/NumberValidatorTest.php
+6
-0
RangeValidatorTest.php
tests/unit/framework/validators/RangeValidatorTest.php
+6
-0
RegularExpressionValidatorTest.php
...t/framework/validators/RegularExpressionValidatorTest.php
+6
-0
RequiredValidatorTest.php
tests/unit/framework/validators/RequiredValidatorTest.php
+6
-0
UniqueValidatorTest.php
tests/unit/framework/validators/UniqueValidatorTest.php
+1
-1
UrlValidatorTest.php
tests/unit/framework/validators/UrlValidatorTest.php
+6
-0
ValidatorTest.php
tests/unit/framework/validators/ValidatorTest.php
+6
-1
No files found.
apps/advanced/backend/config/main.php
View file @
a3dd0d57
...
...
@@ -15,6 +15,7 @@ return [
'preload'
=>
[
'log'
],
'controllerNamespace'
=>
'backend\controllers'
,
'modules'
=>
[],
'extensions'
=>
require
(
__DIR__
.
'/../../vendor/yii-extensions.php'
),
'components'
=>
[
'request'
=>
[
'enableCsrfValidation'
=>
true
,
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/composer.json
View file @
a3dd0d57
...
...
@@ -20,12 +20,12 @@
},
"scripts"
:
{
"post-create-project-cmd"
:
[
"yii
\\
composer
\\
Install
Handler::setPermissions
"
,
"yii
\\
composer
\\
Install
er::setPermission
"
,
"./init"
]
},
"extra"
:
{
"
yii-install-
writable"
:
[
"writable"
:
[
"backend/runtime"
,
"backend/web/assets"
,
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/console/config/main.php
View file @
a3dd0d57
...
...
@@ -15,6 +15,7 @@ return [
'controllerNamespace'
=>
'console\controllers'
,
'modules'
=>
[
],
'extensions'
=>
require
(
__DIR__
.
'/../../vendor/yii-extensions.php'
),
'components'
=>
[
'db'
=>
$params
[
'components.db'
],
'cache'
=>
$params
[
'components.cache'
],
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/environments/dev/frontend/web/index.php
View file @
a3dd0d57
...
...
@@ -4,7 +4,6 @@ defined('YII_ENV') or define('YII_ENV', 'dev');
require
(
__DIR__
.
'/../../vendor/autoload.php'
);
require
(
__DIR__
.
'/../../vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/../../vendor/composer/autoload_namespaces.php'
));
$config
=
yii\helpers\ArrayHelper
::
merge
(
require
(
__DIR__
.
'/../config/main.php'
),
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/environments/dev/yii
View file @
a3dd0d57
...
...
@@ -16,7 +16,6 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require
(
__DIR__
.
'/vendor/autoload.php'
);
require
(
__DIR__
.
'/vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/vendor/composer/autoload_namespaces.php'
));
$config
=
yii\helpers\ArrayHelper
::
merge
(
require
(
__DIR__
.
'/console/config/main.php'
),
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/environments/prod/frontend/web/index.php
View file @
a3dd0d57
...
...
@@ -4,7 +4,6 @@ defined('YII_ENV') or define('YII_ENV', 'prod');
require
(
__DIR__
.
'/../../vendor/autoload.php'
);
require
(
__DIR__
.
'/../../vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/../../vendor/composer/autoload_namespaces.php'
));
$config
=
yii\helpers\ArrayHelper
::
merge
(
require
(
__DIR__
.
'/../config/main.php'
),
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/environments/prod/yii
View file @
a3dd0d57
...
...
@@ -16,7 +16,6 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require
(
__DIR__
.
'/vendor/autoload.php'
);
require
(
__DIR__
.
'/vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/vendor/composer/autoload_namespaces.php'
));
$config
=
yii\helpers\ArrayHelper
::
merge
(
require
(
__DIR__
.
'/console/config/main.php'
),
...
...
This diff is collapsed.
Click to expand it.
apps/advanced/frontend/config/main.php
View file @
a3dd0d57
...
...
@@ -16,6 +16,7 @@ return [
'modules'
=>
[
'gii'
=>
'yii\gii\Module'
],
'extensions'
=>
require
(
__DIR__
.
'/../../vendor/yii-extensions.php'
),
'components'
=>
[
'request'
=>
[
'enableCsrfValidation'
=>
true
,
...
...
This diff is collapsed.
Click to expand it.
apps/basic/composer.json
View file @
a3dd0d57
...
...
@@ -20,15 +20,15 @@
},
"scripts"
:
{
"post-create-project-cmd"
:
[
"yii
\\
composer
\\
Install
Handler::setPermissions
"
"yii
\\
composer
\\
Install
er::setPermission
"
]
},
"extra"
:
{
"
yii-install-
writable"
:
[
"writable"
:
[
"runtime"
,
"web/assets"
],
"
yii-install-
executable"
:
[
"executable"
:
[
"yii"
]
}
...
...
This diff is collapsed.
Click to expand it.
apps/basic/config/console.php
View file @
a3dd0d57
...
...
@@ -6,8 +6,7 @@ return [
'preload'
=>
[
'log'
],
'controllerPath'
=>
dirname
(
__DIR__
)
.
'/commands'
,
'controllerNamespace'
=>
'app\commands'
,
'modules'
=>
[
],
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yii-extensions.php'
),
'components'
=>
[
'cache'
=>
[
'class'
=>
'yii\caching\FileCache'
,
...
...
This diff is collapsed.
Click to expand it.
apps/basic/config/web.php
View file @
a3dd0d57
...
...
@@ -3,6 +3,7 @@ $params = require(__DIR__ . '/params.php');
$config
=
[
'id'
=>
'bootstrap'
,
'basePath'
=>
dirname
(
__DIR__
),
'extensions'
=>
require
(
__DIR__
.
'/../vendor/yii-extensions.php'
),
'components'
=>
[
'request'
=>
[
'enableCsrfValidation'
=>
true
,
...
...
This diff is collapsed.
Click to expand it.
apps/basic/web/index-test.php
View file @
a3dd0d57
...
...
@@ -10,7 +10,6 @@ defined('YII_ENV') or define('YII_ENV', 'test');
require_once
(
__DIR__
.
'/../vendor/autoload.php'
);
require_once
(
__DIR__
.
'/../vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/../vendor/composer/autoload_namespaces.php'
));
$config
=
require
(
__DIR__
.
'/../config/web-test.php'
);
...
...
This diff is collapsed.
Click to expand it.
apps/basic/web/index.php
View file @
a3dd0d57
...
...
@@ -6,7 +6,6 @@ defined('YII_ENV') or define('YII_ENV', 'dev');
require
(
__DIR__
.
'/../vendor/autoload.php'
);
require
(
__DIR__
.
'/../vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/../vendor/composer/autoload_namespaces.php'
));
$config
=
require
(
__DIR__
.
'/../config/web.php'
);
...
...
This diff is collapsed.
Click to expand it.
apps/basic/yii
View file @
a3dd0d57
...
...
@@ -15,7 +15,6 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
require
(
__DIR__
.
'/vendor/autoload.php'
);
require
(
__DIR__
.
'/vendor/yiisoft/yii2/yii/Yii.php'
);
Yii
::
importNamespaces
(
require
(
__DIR__
.
'/vendor/composer/autoload_namespaces.php'
));
$config
=
require
(
__DIR__
.
'/config/console.php'
);
...
...
This diff is collapsed.
Click to expand it.
docs/guide/apps-advanced.md
View file @
a3dd0d57
...
...
@@ -144,11 +144,11 @@ directory:
},
"scripts"
:
{
"post-create-project-cmd"
:
[
"yii
\\
composer
\\
Install
Handler::setPermissions
"
"yii
\\
composer
\\
Install
er::setPermission
"
]
},
"extra"
:
{
"
yii-install-
writable"
:
[
"writable"
:
[
"backend/runtime"
,
"backend/web/assets"
,
...
...
This diff is collapsed.
Click to expand it.
docs/guide/apps-basic.md
View file @
a3dd0d57
...
...
@@ -134,15 +134,15 @@ directory:
},
"scripts"
:
{
"post-create-project-cmd"
:
[
"yii
\\
composer
\\
Install
Handler::setPermissions
"
"yii
\\
composer
\\
Install
er::setPermission
"
]
},
"extra"
:
{
"
yii-install-
writable"
:
[
"writable"
:
[
"runtime"
,
"web/assets"
],
"
yii-install-
executable"
:
[
"executable"
:
[
"yii"
]
}
...
...
This diff is collapsed.
Click to expand it.
extensions/composer/composer.json
View file @
a3dd0d57
...
...
@@ -22,7 +22,7 @@
"psr-0"
:
{
"yii
\\
composer
\\
"
:
""
}
},
"extra"
:
{
"class"
:
"yii
\\
composer
\\
Installer
Plugin"
"class"
:
"yii
\\
composer
\\
Plugin"
},
"require"
:
{
"composer-plugin-api"
:
"1.0.0"
...
...
This diff is collapsed.
Click to expand it.
extensions/composer/yii/composer/InstallHandler.php
deleted
100644 → 0
View file @
b611c424
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\composer
;
use
Composer\Script\CommandEvent
;
use
yii\console\Application
;
use
yii\console\Exception
;
defined
(
'YII_DEBUG'
)
or
define
(
'YII_DEBUG'
,
true
);
// fcgi doesn't have STDIN defined by default
defined
(
'STDIN'
)
or
define
(
'STDIN'
,
fopen
(
'php://stdin'
,
'r'
));
/**
* InstallHandler is called by Composer after it installs/updates the current package.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Tobias Munk <schmunk@usrbin.de>
* @since 2.0
*/
class
InstallHandler
{
const
PARAM_WRITABLE
=
'yii-install-writable'
;
const
PARAM_EXECUTABLE
=
'yii-install-executable'
;
const
PARAM_CONFIG
=
'yii-install-config'
;
const
PARAM_COMMANDS
=
'yii-install-commands'
;
/**
* Sets the correct permissions of files and directories.
* @param CommandEvent $event
*/
public
static
function
setPermissions
(
$event
)
{
$options
=
array_merge
([
self
::
PARAM_WRITABLE
=>
[],
self
::
PARAM_EXECUTABLE
=>
[],
],
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
foreach
((
array
)
$options
[
self
::
PARAM_WRITABLE
]
as
$path
)
{
echo
"Setting writable:
$path
..."
;
if
(
is_dir
(
$path
))
{
chmod
(
$path
,
0777
);
echo
"done
\n
"
;
}
else
{
echo
"The directory was not found: "
.
getcwd
()
.
DIRECTORY_SEPARATOR
.
$path
;
return
;
}
}
foreach
((
array
)
$options
[
self
::
PARAM_EXECUTABLE
]
as
$path
)
{
echo
"Setting executable:
$path
..."
;
if
(
is_file
(
$path
))
{
chmod
(
$path
,
0755
);
echo
"done
\n
"
;
}
else
{
echo
"
\n\t
The file was not found: "
.
getcwd
()
.
DIRECTORY_SEPARATOR
.
$path
.
"
\n
"
;
return
;
}
}
}
/**
* Executes a yii command.
* @param CommandEvent $event
*/
public
static
function
run
(
$event
)
{
$options
=
array_merge
([
self
::
PARAM_COMMANDS
=>
[],
],
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
if
(
!
isset
(
$options
[
self
::
PARAM_CONFIG
]))
{
throw
new
Exception
(
'Please specify the "'
.
self
::
PARAM_CONFIG
.
'" parameter in composer.json.'
);
}
$configFile
=
getcwd
()
.
'/'
.
$options
[
self
::
PARAM_CONFIG
];
if
(
!
is_file
(
$configFile
))
{
throw
new
Exception
(
"Config file does not exist:
$configFile
"
);
}
require_once
(
__DIR__
.
'/../../../yii2/yii/Yii.php'
);
$application
=
new
Application
(
require
(
$configFile
));
$request
=
$application
->
getRequest
();
foreach
((
array
)
$options
[
self
::
PARAM_COMMANDS
]
as
$command
)
{
$params
=
str_getcsv
(
$command
,
' '
);
// see http://stackoverflow.com/a/6609509/291573
$request
->
setParams
(
$params
);
list
(
$route
,
$params
)
=
$request
->
resolve
();
echo
"Running command: yii
{
$command
}
\n
"
;
$application
->
runAction
(
$route
,
$params
);
}
}
}
This diff is collapsed.
Click to expand it.
extensions/composer/yii/composer/Installer.php
View file @
a3dd0d57
...
...
@@ -11,8 +11,6 @@ use Composer\Package\PackageInterface;
use
Composer\Installer\LibraryInstaller
;
use
Composer\Repository\InstalledRepositoryInterface
;
use
Composer\Script\CommandEvent
;
use
yii\console\Application
;
use
yii\console\Exception
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -20,11 +18,9 @@ use yii\console\Exception;
*/
class
Installer
extends
LibraryInstaller
{
const
EXTRA_BOOTSTRAP
=
'bootstrap'
;
const
EXTRA_WRITABLE
=
'writable'
;
const
EXTRA_EXECUTABLE
=
'executable'
;
const
EXTRA_CONFIG
=
'yii-config'
;
const
EXTRA_COMMANDS
=
'yii-commands'
;
const
EXTRA_BOOTSTRAP
=
'bootstrap'
;
/**
* @inheritdoc
...
...
@@ -101,10 +97,10 @@ class Installer extends LibraryInstaller
/**
* Sets the correct permission
s of files and directories
.
* Sets the correct permission
for the files and directories listed in the extra section
.
* @param CommandEvent $event
*/
public
static
function
setPermission
s
(
$event
)
public
static
function
setPermission
(
$event
)
{
$options
=
array_merge
([
self
::
EXTRA_WRITABLE
=>
[],
...
...
@@ -133,35 +129,4 @@ class Installer extends LibraryInstaller
}
}
}
/**
* Executes a yii command.
* @param CommandEvent $event
*/
public
static
function
run
(
$event
)
{
$options
=
array_merge
([
self
::
EXTRA_COMMANDS
=>
[],
],
$event
->
getComposer
()
->
getPackage
()
->
getExtra
());
if
(
!
isset
(
$options
[
self
::
EXTRA_CONFIG
]))
{
throw
new
Exception
(
'Please specify the "'
.
self
::
EXTRA_CONFIG
.
'" parameter in composer.json.'
);
}
$configFile
=
getcwd
()
.
'/'
.
$options
[
self
::
EXTRA_CONFIG
];
if
(
!
is_file
(
$configFile
))
{
throw
new
Exception
(
"Config file does not exist:
$configFile
"
);
}
require_once
(
__DIR__
.
'/../../../yii2/yii/Yii.php'
);
$application
=
new
Application
(
require
(
$configFile
));
$request
=
$application
->
getRequest
();
foreach
((
array
)
$options
[
self
::
EXTRA_COMMANDS
]
as
$command
)
{
$params
=
str_getcsv
(
$command
,
' '
);
// see http://stackoverflow.com/a/6609509/291573
$request
->
setParams
(
$params
);
list
(
$route
,
$params
)
=
$request
->
resolve
();
echo
"Running command: yii
{
$command
}
\n
"
;
$application
->
runAction
(
$route
,
$params
);
}
}
}
This diff is collapsed.
Click to expand it.
extensions/composer/yii/composer/
Installer
Plugin.php
→
extensions/composer/yii/composer/Plugin.php
View file @
a3dd0d57
...
...
@@ -12,12 +12,12 @@ use Composer\IO\IOInterface;
use
Composer\Plugin\PluginInterface
;
/**
*
Installer
Plugin is the composer plugin that registers the Yii composer installer.
* Plugin is the composer plugin that registers the Yii composer installer.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Installer
Plugin
implements
PluginInterface
class
Plugin
implements
PluginInterface
{
/**
* @inheritdoc
...
...
This diff is collapsed.
Click to expand it.
extensions/jui/yii/jui/AccordionAsset.php
View file @
a3dd0d57
...
...
@@ -6,6 +6,7 @@
*/
namespace
yii\jui
;
use
yii\web\AssetBundle
;
/**
...
...
This diff is collapsed.
Click to expand it.
extensions/jui/yii/jui/Extension.php
0 → 100644
View file @
a3dd0d57
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\jui
;
use
Yii
;
/**
* This is the bootstrap class for the Yii JUI extension.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Extension
extends
\yii\base\Extension
{
/**
* @inheritdoc
*/
public
static
function
init
()
{
Yii
::
setAlias
(
'@yii/jui'
,
__DIR__
);
}
}
This diff is collapsed.
Click to expand it.
framework/yii/BaseYii.php
View file @
a3dd0d57
...
...
@@ -6,7 +6,6 @@
*/
namespace
yii
;
use
yii\base\Exception
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidParamException
;
use
yii\base\UnknownClassException
;
...
...
@@ -110,33 +109,6 @@ class BaseYii
}
/**
* Imports a set of namespaces.
*
* By importing a namespace, the method will create an alias for the directory corresponding
* to the namespace. For example, if "foo\bar" is a namespace associated with the directory
* "path/to/foo/bar", then an alias "@foo/bar" will be created for this directory.
*
* This method is typically invoked in the bootstrap file to import the namespaces of
* the installed extensions. By default, Composer, when installing new extensions, will
* generate such a mapping file which can be loaded and passed to this method.
*
* @param array $namespaces the namespaces to be imported. The keys are the namespaces,
* and the values are the corresponding directories.
*/
public
static
function
importNamespaces
(
$namespaces
)
{
foreach
(
$namespaces
as
$name
=>
$path
)
{
if
(
$name
!==
''
)
{
$name
=
trim
(
strtr
(
$name
,
[
'\\'
=>
'/'
,
'_'
=>
'/'
]),
'/'
);
if
(
is_array
(
$path
))
{
$path
=
reset
(
$path
);
}
static
::
setAlias
(
'@'
.
$name
,
rtrim
(
$path
,
'/\\'
)
.
'/'
.
$name
);
}
}
}
/**
* Translates a path alias into an actual path.
*
* The translation is done according to the following procedure:
...
...
@@ -335,8 +307,7 @@ class BaseYii
include
(
$classFile
);
if
(
YII_DEBUG
&&
!
class_exists
(
$className
,
false
)
&&
!
interface_exists
(
$className
,
false
)
&&
(
!
function_exists
(
'trait_exists'
)
||
!
trait_exists
(
$className
,
false
)))
{
if
(
YII_DEBUG
&&
!
class_exists
(
$className
,
false
)
&&
!
interface_exists
(
$className
,
false
)
&&
!
trait_exists
(
$className
,
false
))
{
throw
new
UnknownClassException
(
"Unable to find '
$className
' in file:
$classFile
"
);
}
}
...
...
@@ -543,7 +514,11 @@ class BaseYii
if
(
self
::
$app
!==
null
)
{
return
self
::
$app
->
getI18n
()
->
translate
(
$category
,
$message
,
$params
,
$language
?:
self
::
$app
->
language
);
}
else
{
return
is_array
(
$params
)
?
strtr
(
$message
,
$params
)
:
$message
;
$p
=
[];
foreach
((
array
)
$params
as
$name
=>
$value
)
{
$p
[
'{'
.
$name
.
'}'
]
=
$value
;
}
return
(
$p
===
[])
?
$message
:
strtr
(
$message
,
$p
);
}
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/base/Application.php
View file @
a3dd0d57
...
...
@@ -85,10 +85,6 @@ abstract class Application extends Module
*/
public
$sourceLanguage
=
'en_US'
;
/**
* @var array IDs of the components that need to be loaded when the application starts.
*/
public
$preload
=
[];
/**
* @var Controller the currently active controller instance
*/
public
$controller
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/base/Model.php
View file @
a3dd0d57
...
...
@@ -748,16 +748,21 @@ class Model extends Component implements IteratorAggregate, ArrayAccess
/**
* Validates multiple models.
* This method will validate every model. The models being validated may
* be of the same or different types.
* @param array $models the models to be validated
* @param array $attributes list of attributes that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
* @return boolean whether all models are valid. False will be returned if one
* or multiple models have validation error.
*/
public
static
function
validateMultiple
(
$models
)
public
static
function
validateMultiple
(
$models
,
$attributes
=
null
)
{
$valid
=
true
;
/** @var Model $model */
foreach
(
$models
as
$model
)
{
$valid
=
$model
->
validate
()
&&
$valid
;
$valid
=
$model
->
validate
(
$attributes
)
&&
$valid
;
}
return
$valid
;
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/base/Module.php
View file @
a3dd0d57
...
...
@@ -41,7 +41,7 @@ abstract class Module extends Component
*/
public
$params
=
[];
/**
* @var array the IDs of the components or modules that should be preloaded
when this module is created
.
* @var array the IDs of the components or modules that should be preloaded
right after initialization
.
*/
public
$preload
=
[];
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/base/Theme.php
View file @
a3dd0d57
...
...
@@ -8,7 +8,6 @@
namespace
yii\base
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\FileHelper
;
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/bootstrap/Carousel.php
View file @
a3dd0d57
...
...
@@ -29,8 +29,8 @@ use yii\helpers\Html;
* 'caption' => '<h4>This is title</h4><p>This is the caption text</p>',
* 'options' => [...],
* ],
*
)
*
)
);
*
]
*
]
);
* ```
*
* @see http://twitter.github.io/bootstrap/javascript.html#carousel
...
...
This diff is collapsed.
Click to expand it.
framework/yii/bootstrap/Dropdown.php
View file @
a3dd0d57
...
...
@@ -29,6 +29,8 @@ class Dropdown extends Widget
* - visible: boolean, optional, whether this menu item is visible. Defaults to true.
* - linkOptions: array, optional, the HTML attributes of the item link.
* - options: array, optional, the HTML attributes of the item.
*
* To insert divider use `<li role="presentation" class="divider"></li>`.
*/
public
$items
=
[];
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/bootstrap/Nav.php
View file @
a3dd0d57
...
...
@@ -24,7 +24,7 @@ use yii\helpers\Html;
* 'label' => 'Home',
* 'url' => ['site/index'],
* 'linkOptions' => [...],
*
)
,
*
]
,
* [
* 'label' => 'Dropdown',
* 'items' => [
...
...
This diff is collapsed.
Click to expand it.
framework/yii/bootstrap/Tabs.php
View file @
a3dd0d57
...
...
@@ -85,6 +85,10 @@ class Tabs extends Widget
* @var boolean whether the labels for header items should be HTML-encoded.
*/
public
$encodeLabels
=
true
;
/**
* @var string, specifies the Bootstrap tab styling.
*/
public
$navType
=
'nav-tabs'
;
/**
...
...
@@ -93,7 +97,7 @@ class Tabs extends Widget
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'nav
nav-tabs'
);
Html
::
addCssClass
(
$this
->
options
,
'nav
'
.
$this
->
navType
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/bootstrap/Widget.php
View file @
a3dd0d57
...
...
@@ -8,7 +8,6 @@
namespace
yii\bootstrap
;
use
Yii
;
use
yii\base\View
;
use
yii\helpers\Json
;
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/captcha/CaptchaValidator.php
View file @
a3dd0d57
...
...
@@ -18,8 +18,6 @@ use yii\validators\Validator;
*
* CaptchaValidator should be used together with [[CaptchaAction]].
*
* @property \yii\captcha\CaptchaAction $captchaAction The action object. This property is read-only.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
...
...
@@ -71,16 +69,16 @@ class CaptchaValidator extends Validator
*/
public
function
validateValue
(
$value
)
{
$captcha
=
$this
->
get
CaptchaAction
();
$captcha
=
$this
->
create
CaptchaAction
();
return
!
is_array
(
$value
)
&&
$captcha
->
validate
(
$value
,
$this
->
caseSensitive
);
}
/**
* Returns the CAPTCHA action object.
* @throws InvalidConfigException
* Creates the CAPTCHA action object from the route specified by [[captchaAction]].
* @return \yii\captcha\CaptchaAction the action object
* @throws InvalidConfigException
*/
public
function
get
CaptchaAction
()
public
function
create
CaptchaAction
()
{
$ca
=
Yii
::
$app
->
createController
(
$this
->
captchaAction
);
if
(
$ca
!==
false
)
{
...
...
@@ -104,7 +102,7 @@ class CaptchaValidator extends Validator
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$captcha
=
$this
->
get
CaptchaAction
();
$captcha
=
$this
->
create
CaptchaAction
();
$code
=
$captcha
->
getVerifyCode
(
false
);
$hash
=
$captcha
->
generateValidationHash
(
$this
->
caseSensitive
?
$code
:
strtolower
(
$code
));
$options
=
[
...
...
@@ -113,7 +111,6 @@ class CaptchaValidator extends Validator
'caseSensitive'
=>
$this
->
caseSensitive
,
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
[
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
])),
];
if
(
$this
->
skipOnEmpty
)
{
...
...
This diff is collapsed.
Click to expand it.
framework/yii/data/ArrayDataProvider.php
View file @
a3dd0d57
...
...
@@ -33,7 +33,7 @@ use yii\helpers\ArrayHelper;
* 'allModels' => $query->from('tbl_post')->all(),
* 'sort' => [
* 'attributes' => ['id', 'username', 'email'],
*
)
,
*
]
,
* 'pagination' => [
* 'pageSize' => 10,
* ],
...
...
This diff is collapsed.
Click to expand it.
framework/yii/db/ActiveRecord.php
View file @
a3dd0d57
...
...
@@ -1125,26 +1125,20 @@ class ActiveRecord extends Model
/**
* Repopulates this active record with the latest data.
* @param array $attributes
* @return boolean whether the row still exists in the database. If true, the latest data
* will be populated to this active record.
* will be populated to this active record.
Otherwise, this record will remain unchanged.
*/
public
function
refresh
(
$attributes
=
null
)
public
function
refresh
()
{
$record
=
$this
->
find
(
$this
->
getPrimaryKey
(
true
));
if
(
$record
===
null
)
{
return
false
;
}
if
(
$attributes
===
null
)
{
foreach
(
$this
->
attributes
()
as
$name
)
{
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
];
}
$this
->
_oldAttributes
=
$this
->
_attributes
;
}
else
{
foreach
(
$attributes
as
$name
)
{
$this
->
_oldAttributes
[
$name
]
=
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
];
}
foreach
(
$this
->
attributes
()
as
$name
)
{
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
];
}
$this
->
_oldAttributes
=
$this
->
_attributes
;
$this
->
_related
=
null
;
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/gii/generators/crud/Generator.php
View file @
a3dd0d57
...
...
@@ -8,7 +8,6 @@
namespace
yii\gii\generators\crud
;
use
Yii
;
use
yii\base\Model
;
use
yii\db\ActiveRecord
;
use
yii\db\Schema
;
use
yii\gii\CodeFile
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/gii/generators/form/templates/action.php
View file @
a3dd0d57
...
...
@@ -14,7 +14,7 @@ echo "<?php\n";
public function action
<?=
Inflector
::
id2camel
(
trim
(
basename
(
$generator
->
viewName
),
'_'
))
?>
()
{
$model = new
<?=
$generator
->
modelClass
?><?=
empty
(
$generator
->
scenarioName
)
?
''
:
"(['scenario' => '
{
$generator
->
scenarioName
}
'])"
?>
;
$model = new
<?=
$generator
->
modelClass
?><?=
empty
(
$generator
->
scenarioName
)
?
""
:
"(['scenario' => '
{
$generator
->
scenarioName
}
'])"
?>
;
if ($model->load($_POST)) {
if($model->validate()) {
...
...
This diff is collapsed.
Click to expand it.
framework/yii/gii/generators/form/templates/form.php
View file @
a3dd0d57
...
...
@@ -21,15 +21,15 @@ use yii\widgets\ActiveForm;
<div
class=
"
<?=
str_replace
(
'/'
,
'-'
,
trim
(
$generator
->
viewName
,
'_'
))
?>
"
>
<?=
'<?php'
?>
$form = ActiveForm::begin(); ?>
<?=
"<?php "
?>
$form = ActiveForm::begin(); ?>
<?php
foreach
(
$generator
->
getModelAttributes
()
as
$attribute
)
:
?>
<?=
'<?php'
?>
echo $form->field($model, '
<?=
$attribute
?>
');
?>
<?=
"<?= "
?>
$form->field($model, '
<?=
$attribute
?>
')
?>
<?php
endforeach
;
?>
<div
class=
"form-group"
>
<?=
'<?php'
?>
echo Html::submitButton('Submit', ['class' => 'btn btn-primary']);
?>
<?=
"<?= "
?>
Html::submitButton('Submit', ['class' => 'btn btn-primary'])
?>
</div>
<?=
'<?php'
?>
ActiveForm::end(); ?>
<?=
"<?php "
?>
ActiveForm::end(); ?>
</div>
<!--
<?=
str_replace
(
'/'
,
'-'
,
trim
(
$generator
->
viewName
,
'-'
))
?>
-->
This diff is collapsed.
Click to expand it.
framework/yii/gii/generators/model/Generator.php
View file @
a3dd0d57
...
...
@@ -265,7 +265,7 @@ class Generator extends \yii\gii\Generator
$link
=
$this
->
generateRelationLink
(
array_flip
(
$refs
));
$relationName
=
$this
->
generateRelationName
(
$relations
,
$className
,
$table
,
$fks
[
0
],
false
);
$relations
[
$className
][
$relationName
]
=
[
"return
\$
this->hasOne(
'
$refClassName
'
,
$link
);"
,
"return
\$
this->hasOne(
$refClassName
::className()
,
$link
);"
,
$refClassName
,
false
,
];
...
...
@@ -281,7 +281,7 @@ class Generator extends \yii\gii\Generator
$link
=
$this
->
generateRelationLink
(
$refs
);
$relationName
=
$this
->
generateRelationName
(
$relations
,
$refClassName
,
$refTable
,
$className
,
$hasMany
);
$relations
[
$refClassName
][
$relationName
]
=
[
"return
\$
this->"
.
(
$hasMany
?
'hasMany'
:
'hasOne'
)
.
"(
'
$className
'
,
$link
);"
,
"return
\$
this->"
.
(
$hasMany
?
'hasMany'
:
'hasOne'
)
.
"(
$refClassName
::className()
,
$link
);"
,
$className
,
$hasMany
,
];
...
...
@@ -299,7 +299,7 @@ class Generator extends \yii\gii\Generator
$viaLink
=
$this
->
generateRelationLink
([
$table
->
primaryKey
[
0
]
=>
$fks
[
$table
->
primaryKey
[
0
]][
1
]]);
$relationName
=
$this
->
generateRelationName
(
$relations
,
$className0
,
$db
->
getTableSchema
(
$table0
),
$table
->
primaryKey
[
1
],
true
);
$relations
[
$className0
][
$relationName
]
=
[
"return
\$
this->hasMany(
'
$className1
'
,
$link
)->viaTable('
{
$table
->
name
}
',
$viaLink
);"
,
"return
\$
this->hasMany(
$className1
::className()
,
$link
)->viaTable('
{
$table
->
name
}
',
$viaLink
);"
,
$className0
,
true
,
];
...
...
@@ -308,7 +308,7 @@ class Generator extends \yii\gii\Generator
$viaLink
=
$this
->
generateRelationLink
([
$table
->
primaryKey
[
1
]
=>
$fks
[
$table
->
primaryKey
[
1
]][
1
]]);
$relationName
=
$this
->
generateRelationName
(
$relations
,
$className1
,
$db
->
getTableSchema
(
$table1
),
$table
->
primaryKey
[
0
],
true
);
$relations
[
$className1
][
$relationName
]
=
[
"return
\$
this->hasMany(
'
$className0
'
,
$link
)->viaTable('
{
$table
->
name
}
',
$viaLink
);"
,
"return
\$
this->hasMany(
$className0
::className()
,
$link
)->viaTable('
{
$table
->
name
}
',
$viaLink
);"
,
$className1
,
true
,
];
...
...
This diff is collapsed.
Click to expand it.
framework/yii/gii/generators/module/templates/view.php
View file @
a3dd0d57
...
...
@@ -5,14 +5,14 @@
*/
?>
<div
class=
"
<?=
$generator
->
moduleID
.
'-default-index'
?>
"
>
<h1>
<?=
"<?
php"
?>
echo $this->context->action->uniqueId;
?>
</h1>
<h1>
<?=
"<?
= "
?>
$this->context->action->uniqueId
?>
</h1>
<p>
This is the view content for action "
<?=
"<?
php"
?>
echo $this->context->action->id;
?>".
The action belongs to the controller "
<?=
"<?
php"
?>
echo get_class($this->context);
?>"
in the "
<?=
"<?
php"
?>
echo $this->context->module->id;
?>" module.
This is the view content for action "
<?=
"<?
= "
?>
$this->context->action->id
?>".
The action belongs to the controller "
<?=
"<?
= "
?>
get_class($this->context)
?>"
in the "
<?=
"<?
= "
?>
$this->context->module->id
?>" module.
</p>
<p>
You may customize this page by editing the following file:
<br>
<code>
<?=
"<?
php"
?>
echo __FILE__;
?>
</code>
<code>
<?=
"<?
= "
?>
__FILE__
?>
</code>
</p>
</div>
This diff is collapsed.
Click to expand it.
framework/yii/gii/views/default/view.php
View file @
a3dd0d57
<?php
use
yii\gii\Generator
;
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
yii\gii\components\ActiveField
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/gii/views/default/view/files.php
View file @
a3dd0d57
<?php
use
yii\gii\Generator
;
use
yii\helpers\Html
;
use
yii\gii\CodeFile
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/gii/views/default/view/results.php
View file @
a3dd0d57
<?php
use
yii\gii\Generator
;
use
yii\gii\CodeFile
;
/**
* @var yii\base\View $this
* @var yii\gii\Generator $generator
...
...
This diff is collapsed.
Click to expand it.
framework/yii/grid/ActionColumn.php
View file @
a3dd0d57
...
...
@@ -10,8 +10,6 @@ namespace yii\grid;
use
Yii
;
use
Closure
;
use
yii\helpers\Html
;
use
yii\helpers\Inflector
;
use
yii\helpers\StringHelper
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
This diff is collapsed.
Click to expand it.
framework/yii/grid/DataColumn.php
View file @
a3dd0d57
...
...
@@ -41,10 +41,10 @@ class DataColumn extends Column
*/
public
$value
;
/**
* @var string
in which format should the value of each data model be displayed as (e.g. "text", "html").
*
Supported formats are determined by the [[GridView::formatter|formatter]] used by the [[GridView]].
* Default format is "text" which will format the value as an HTML-encoded plain text when
* [[\yii\base\Formatter
]] or [[\yii\i18n\Formatter
]] is used.
* @var string
|array in which format should the value of each data model be displayed as (e.g. "text", "html",
*
['date', 'Y-m-d']). Supported formats are determined by the [[GridView::formatter|formatter]] used by
*
the [[GridView]].
Default format is "text" which will format the value as an HTML-encoded plain text when
* [[\yii\base\Formatter
::format()]] or [[\yii\i18n\Formatter::format()
]] is used.
*/
public
$format
=
'text'
;
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/grid/GridView.php
View file @
a3dd0d57
...
...
@@ -11,8 +11,6 @@ use Yii;
use
Closure
;
use
yii\base\Formatter
;
use
yii\base\InvalidConfigException
;
use
yii\base\Widget
;
use
yii\db\ActiveRecord
;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
use
yii\widgets\BaseListView
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/helpers/BaseArrayHelper.php
View file @
a3dd0d57
...
...
@@ -336,7 +336,7 @@ class BaseArrayHelper
* @param boolean|array $descending whether to sort in descending or ascending order. When
* sorting by multiple keys with different descending orders, use an array of descending flags.
* @param integer|array $sortFlag the PHP sort flag. Valid values include
* `SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`
and `SORT_LOCALE_STRING
`.
* `SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`
, `SORT_LOCALE_STRING`, `SORT_NATURAL` and `SORT_FLAG_CASE
`.
* Please refer to [PHP manual](http://php.net/manual/en/function.sort.php)
* for more details. When sorting by multiple keys with different sort flags, use an array of sort flags.
* @param boolean|array $caseSensitive whether to sort string in case-sensitive manner. This parameter
...
...
@@ -372,16 +372,8 @@ class BaseArrayHelper
$flag
=
$sortFlag
[
$i
];
$cs
=
$caseSensitive
[
$i
];
if
(
!
$cs
&&
(
$flag
===
SORT_STRING
))
{
if
(
defined
(
'SORT_FLAG_CASE'
))
{
$flag
=
$flag
|
SORT_FLAG_CASE
;
$args
[]
=
static
::
getColumn
(
$array
,
$key
);
}
else
{
$column
=
[];
foreach
(
static
::
getColumn
(
$array
,
$key
)
as
$k
=>
$value
)
{
$column
[
$k
]
=
mb_strtolower
(
$value
);
}
$args
[]
=
$column
;
}
$flag
=
$flag
|
SORT_FLAG_CASE
;
$args
[]
=
static
::
getColumn
(
$array
,
$key
);
}
else
{
$args
[]
=
static
::
getColumn
(
$array
,
$key
);
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/i18n/FallbackMessageFormatter.php
0 → 100644
View file @
a3dd0d57
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\i18n
;
use
yii\base\NotSupportedException
;
/**
* FallbackMessageFormatter is a fallback implementation for the PHP intl MessageFormatter that is
* used in case PHP intl extension is not installed.
*
* Do not use this class directly. Use [[MessageFormatter]] instead, which will automatically detect
* installed version of PHP intl and use the fallback if it is not installed.
*
* It is highly recommended that you install [PHP intl extension](http://php.net/manual/en/book.intl.php) if you want to use
* MessageFormatter features.
*
* This implementation only supports to following message formats:
* - plural formatting for english
* - select format
* - simple parameters
*
* The pattern also does NOT support the ['apostrophe-friendly' syntax](http://www.php.net/manual/en/messageformatter.formatmessage.php).
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
FallbackMessageFormatter
{
private
$_locale
;
private
$_pattern
;
private
$_errorMessage
=
''
;
private
$_errorCode
=
0
;
/**
* Constructs a new Message Formatter
* @link http://php.net/manual/en/messageformatter.create.php
* @param string $locale The locale to use when formatting arguments
* @param string $pattern The pattern string to stick arguments into.
*/
public
function
__construct
(
$locale
,
$pattern
)
{
$this
->
_locale
=
$locale
;
$this
->
_pattern
=
$pattern
;
}
/**
* Constructs a new Message Formatter
* @link http://php.net/manual/en/messageformatter.create.php
* @param string $locale The locale to use when formatting arguments
* @param string $pattern The pattern string to stick arguments into.
* @return MessageFormatter The formatter object
*/
public
static
function
create
(
$locale
,
$pattern
)
{
return
new
static
(
$locale
,
$pattern
);
}
/**
* Format the message
* @link http://php.net/manual/en/messageformatter.format.php
* @param array $args Arguments to insert into the format string
* @return string The formatted string, or `FALSE` if an error occurred
*/
public
function
format
(
array
$args
)
{
return
static
::
formatMessage
(
$this
->
_locale
,
$this
->
_pattern
,
$args
);
}
/**
* Quick format message
* @link http://php.net/manual/en/messageformatter.formatmessage.php
* @param string $locale The locale to use for formatting locale-dependent parts
* @param string $pattern The pattern string to insert things into.
* @param array $args The array of values to insert into the format string
* @return string The formatted pattern string or `FALSE` if an error occurred
*/
public
static
function
formatMessage
(
$locale
,
$pattern
,
array
$args
)
{
if
((
$tokens
=
static
::
tokenizePattern
(
$pattern
))
===
false
)
{
return
false
;
}
foreach
(
$tokens
as
$i
=>
$token
)
{
if
(
is_array
(
$token
))
{
if
((
$tokens
[
$i
]
=
static
::
parseToken
(
$token
,
$args
,
$locale
))
===
false
)
{
return
false
;
}
}
}
return
implode
(
''
,
$tokens
);
}
/**
* Tokenizes a pattern by separating normal text from replaceable patterns
* @param string $pattern patter to tokenize
* @return array|bool array of tokens or false on failure
*/
private
static
function
tokenizePattern
(
$pattern
)
{
$depth
=
1
;
if
((
$start
=
$pos
=
mb_strpos
(
$pattern
,
'{'
))
===
false
)
{
return
[
$pattern
];
}
$tokens
=
[
mb_substr
(
$pattern
,
0
,
$pos
)];
while
(
true
)
{
$open
=
mb_strpos
(
$pattern
,
'{'
,
$pos
+
1
);
$close
=
mb_strpos
(
$pattern
,
'}'
,
$pos
+
1
);
if
(
$open
===
false
&&
$close
===
false
)
{
break
;
}
if
(
$open
===
false
)
{
$open
=
mb_strlen
(
$pattern
);
}
if
(
$close
>
$open
)
{
$depth
++
;
$pos
=
$open
;
}
else
{
$depth
--
;
$pos
=
$close
;
}
if
(
$depth
==
0
)
{
$tokens
[]
=
explode
(
','
,
mb_substr
(
$pattern
,
$start
+
1
,
$pos
-
$start
-
1
),
3
);
$start
=
$pos
+
1
;
$tokens
[]
=
mb_substr
(
$pattern
,
$start
,
$open
-
$start
);
$start
=
$open
;
}
}
if
(
$depth
!=
0
)
{
return
false
;
}
return
$tokens
;
}
/**
* Parses a token
* @param array $token the token to parse
* @param array $args arguments to replace
* @param string $locale the locale
* @return bool|string parsed token or false on failure
* @throws \yii\base\NotSupportedException when unsupported formatting is used.
*/
private
static
function
parseToken
(
$token
,
$args
,
$locale
)
{
$param
=
trim
(
$token
[
0
]);
if
(
isset
(
$args
[
$param
]))
{
$arg
=
$args
[
$param
];
}
else
{
return
'{'
.
implode
(
','
,
$token
)
.
'}'
;
}
$type
=
isset
(
$token
[
1
])
?
trim
(
$token
[
1
])
:
'none'
;
switch
(
$type
)
{
case
'number'
:
case
'date'
:
case
'time'
:
case
'spellout'
:
case
'ordinal'
:
case
'duration'
:
case
'choice'
:
case
'selectordinal'
:
throw
new
NotSupportedException
(
"Message format '
$type
' is not supported. You have to install PHP intl extension to use this feature."
);
case
'none'
:
return
$arg
;
case
'select'
:
/* http://icu-project.org/apiref/icu4c/classicu_1_1SelectFormat.html
selectStyle = (selector '{' message '}')+
*/
$select
=
static
::
tokenizePattern
(
$token
[
2
]);
$c
=
count
(
$select
);
$message
=
false
;
for
(
$i
=
0
;
$i
+
1
<
$c
;
$i
++
)
{
if
(
is_array
(
$select
[
$i
])
||
!
is_array
(
$select
[
$i
+
1
]))
{
return
false
;
}
$selector
=
trim
(
$select
[
$i
++
]);
if
(
$message
===
false
&&
$selector
==
'other'
||
$selector
==
$arg
)
{
$message
=
implode
(
','
,
$select
[
$i
]);
}
}
if
(
$message
!==
false
)
{
return
static
::
formatMessage
(
$locale
,
$message
,
$args
);
}
break
;
case
'plural'
:
/* http://icu-project.org/apiref/icu4c/classicu_1_1PluralFormat.html
pluralStyle = [offsetValue] (selector '{' message '}')+
offsetValue = "offset:" number
selector = explicitValue | keyword
explicitValue = '=' number // adjacent, no white space in between
keyword = [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
message: see MessageFormat
*/
$plural
=
static
::
tokenizePattern
(
$token
[
2
]);
$c
=
count
(
$plural
);
$message
=
false
;
$offset
=
0
;
for
(
$i
=
0
;
$i
+
1
<
$c
;
$i
++
)
{
if
(
is_array
(
$plural
[
$i
])
||
!
is_array
(
$plural
[
$i
+
1
]))
{
return
false
;
}
$selector
=
trim
(
$plural
[
$i
++
]);
if
(
$i
==
1
&&
substr
(
$selector
,
0
,
7
)
==
'offset:'
)
{
$offset
=
(
int
)
trim
(
mb_substr
(
$selector
,
7
,
(
$pos
=
mb_strpos
(
str_replace
([
"
\n
"
,
"
\r
"
,
"
\t
"
],
' '
,
$selector
),
' '
,
7
))
-
7
));
$selector
=
trim
(
mb_substr
(
$selector
,
$pos
+
1
));
}
if
(
$message
===
false
&&
$selector
==
'other'
||
$selector
[
0
]
==
'='
&&
(
int
)
mb_substr
(
$selector
,
1
)
==
$arg
||
$selector
==
'zero'
&&
$arg
-
$offset
==
0
||
$selector
==
'one'
&&
$arg
-
$offset
==
1
||
$selector
==
'two'
&&
$arg
-
$offset
==
2
)
{
$message
=
implode
(
','
,
str_replace
(
'#'
,
$arg
-
$offset
,
$plural
[
$i
]));
}
}
if
(
$message
!==
false
)
{
return
static
::
formatMessage
(
$locale
,
$message
,
$args
);
}
break
;
}
return
false
;
}
/**
* Parse input string according to pattern
* @link http://php.net/manual/en/messageformatter.parse.php
* @param string $value The string to parse
* @return array An array containing the items extracted, or `FALSE` on error
*/
public
function
parse
(
$value
)
{
throw
new
NotSupportedException
(
'You have to install PHP intl extension to use this feature.'
);
}
/**
* Quick parse input string
* @link http://php.net/manual/en/messageformatter.parsemessage.php
* @param string $locale The locale to use for parsing locale-dependent parts
* @param string $pattern The pattern with which to parse the `value`.
* @param string $source The string to parse, conforming to the `pattern`.
* @return array An array containing items extracted, or `FALSE` on error
*/
public
static
function
parseMessage
(
$locale
,
$pattern
,
$source
)
{
throw
new
NotSupportedException
(
'You have to install PHP intl extension to use this feature.'
);
}
/**
* Set the pattern used by the formatter
* @link http://php.net/manual/en/messageformatter.setpattern.php
* @param string $pattern The pattern string to use in this message formatter.
* @return bool `TRUE` on success or `FALSE` on failure.
*/
public
function
setPattern
(
$pattern
)
{
$this
->
_pattern
=
$pattern
;
return
true
;
}
/**
* Get the pattern used by the formatter
* @link http://php.net/manual/en/messageformatter.getpattern.php
* @return string The pattern string for this message formatter
*/
public
function
getPattern
()
{
return
$this
->
_pattern
;
}
/**
* Get the locale for which the formatter was created.
* @link http://php.net/manual/en/messageformatter.getlocale.php
* @return string The locale name
*/
public
function
getLocale
()
{
return
$this
->
_locale
;
}
/**
* Get the error code from last operation
* @link http://php.net/manual/en/messageformatter.geterrorcode.php
* @return int The error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.
*/
public
function
getErrorCode
()
{
return
$this
->
_errorCode
;
}
/**
* Get the error text from the last operation
* @link http://php.net/manual/en/messageformatter.geterrormessage.php
* @return string Description of the last error.
*/
public
function
getErrorMessage
()
{
return
$this
->
_errorMessage
;
}
}
if
(
!
class_exists
(
'MessageFormatter'
,
false
))
{
class_alias
(
'yii\\i18n\\FallbackMessageFormatter'
,
'MessageFormatter'
);
define
(
'YII_INTL_MESSAGE_FALLBACK'
,
true
);
}
This diff is collapsed.
Click to expand it.
framework/yii/i18n/I18N.php
View file @
a3dd0d57
...
...
@@ -10,7 +10,6 @@ namespace yii\i18n;
use
Yii
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
use
yii\log\Logger
;
/**
* I18N provides features related with internationalization (I18N) and localization (L10N).
...
...
@@ -63,6 +62,9 @@ class I18N extends Component
/**
* Translates a message to the specified language.
*
* After translation the message will be formatted using [[MessageFormatter]] if it contains
* ICU message format and `$params` are not empty.
*
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
...
...
@@ -72,22 +74,34 @@ class I18N extends Component
public
function
translate
(
$category
,
$message
,
$params
,
$language
)
{
$message
=
$this
->
getMessageSource
(
$category
)
->
translate
(
$category
,
$message
,
$language
);
return
$this
->
format
(
$message
,
$params
,
$language
);
}
/**
* Formats a message using using [[MessageFormatter]].
*
* @param string $message the message to be formatted.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en_US`, `en`).
* @return string the formatted message.
*/
public
function
format
(
$message
,
$params
,
$language
)
{
$params
=
(
array
)
$params
;
if
(
$params
===
[])
{
return
$message
;
}
if
(
class_exists
(
'MessageFormatter'
,
false
)
&&
preg_match
(
'~{\s*[\d\w]+\s*,~u'
,
$message
))
{
if
(
preg_match
(
'~{\s*[\d\w]+\s*,~u'
,
$message
))
{
$formatter
=
new
MessageFormatter
(
$language
,
$message
);
if
(
$formatter
===
null
)
{
Yii
::
warning
(
"
$language
message from category
$category
is invalid. Message is
:
$message
."
);
Yii
::
warning
(
"
Unable to format message in language '
$language
'
:
$message
."
);
return
$message
;
}
$result
=
$formatter
->
format
(
$params
);
if
(
$result
===
false
)
{
$errorMessage
=
$formatter
->
getErrorMessage
();
Yii
::
warning
(
"
$language
message from category
$category
failed with error:
$errorMessage
. Message i
s:
$message
."
);
Yii
::
warning
(
"
Formatting message for language '
$language
' failed with error:
$errorMessage
. The message being formatted wa
s:
$message
."
);
return
$message
;
}
else
{
return
$result
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/i18n/MessageFormatter.php
View file @
a3dd0d57
...
...
@@ -7,13 +7,23 @@
namespace
yii\i18n
;
if
(
!
class_exists
(
'MessageFormatter'
,
false
))
{
require_once
(
__DIR__
.
'/FallbackMessageFormatter.php'
);
}
defined
(
'YII_INTL_MESSAGE_FALLBACK'
)
||
define
(
'YII_INTL_MESSAGE_FALLBACK'
,
false
);
/**
* MessageFormatter is an enhanced version of PHP intl class that no matter which PHP and ICU versions are used:
* MessageFormatter enhances the message formatter class provided by PHP intl extension.
*
* The following enhancements are provided:
*
* - Accepts named arguments and mixed numeric and named arguments.
* - Issues no error when an insufficient number of arguments have been provided. Instead, the placeholders will not be
* substituted.
* - Fixes PHP 5.5 weird placeholder replacement in case no arguments are provided at all (https://bugs.php.net/bug.php?id=65920).
* - Offers limited support for message formatting in case PHP intl extension is not installed.
* However it is highly recommended that you install [PHP intl extension](http://php.net/manual/en/book.intl.php) if you want
* to use MessageFormatter features.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @author Carsten Brandt <mail@cebe.cc>
...
...
@@ -34,7 +44,7 @@ class MessageFormatter extends \MessageFormatter
return
$this
->
getPattern
();
}
if
(
version_compare
(
PHP_VERSION
,
'5.5.0'
,
'<'
))
{
if
(
version_compare
(
PHP_VERSION
,
'5.5.0'
,
'<'
)
&&
!
YII_INTL_MESSAGE_FALLBACK
)
{
$pattern
=
self
::
replaceNamedArguments
(
$this
->
getPattern
(),
$args
);
$this
->
setPattern
(
$pattern
);
$args
=
array_values
(
$args
);
...
...
@@ -57,7 +67,7 @@ class MessageFormatter extends \MessageFormatter
return
$pattern
;
}
if
(
version_compare
(
PHP_VERSION
,
'5.5.0'
,
'<'
))
{
if
(
version_compare
(
PHP_VERSION
,
'5.5.0'
,
'<'
)
&&
!
YII_INTL_MESSAGE_FALLBACK
)
{
$pattern
=
self
::
replaceNamedArguments
(
$pattern
,
$args
);
$args
=
array_values
(
$args
);
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/log/Logger.php
View file @
a3dd0d57
...
...
@@ -39,7 +39,7 @@ use yii\base\InvalidConfigException;
* 'class' => 'yii\log\FileTarget',
* 'levels' => ['trace', 'info'],
* 'categories' => ['yii\*'],
*
)
,
*
]
,
* 'email' => [
* 'class' => 'yii\log\EmailTarget',
* 'levels' => ['error', 'warning'],
...
...
This diff is collapsed.
Click to expand it.
framework/yii/requirements/YiiRequirementChecker.php
View file @
a3dd0d57
...
...
@@ -19,15 +19,15 @@ if (version_compare(PHP_VERSION, '4.3', '<')) {
* ~~~php
* require_once('path/to/YiiRequirementChecker.php');
* $requirementsChecker = new YiiRequirementChecker();
* $requirements =
[
*
[
* $requirements =
array(
*
array(
* 'name' => 'PHP Some Extension',
* 'mandatory' => true,
* 'condition' => extension_loaded('some_extension'),
* 'by' => 'Some application feature',
* 'memo' => 'PHP extension "some_extension" required',
*
]
,
*
]
;
*
)
,
*
)
;
* $requirementsChecker->checkYii()->check($requirements)->render();
* ~~~
*
...
...
@@ -38,12 +38,12 @@ if (version_compare(PHP_VERSION, '4.3', '<')) {
* For example:
*
* ~~~
* $requirements =
[
*
[
* $requirements =
array(
*
array(
* 'name' => 'Upload max file size',
* 'condition' => 'eval:$this->checkUploadMaxFileSize("5M")',
*
]
,
*
]
;
*
)
,
*
)
;
* ~~~
*
* Note: this class definition does not match ordinary Yii style, because it should match PHP 4.3
...
...
@@ -74,14 +74,14 @@ class YiiRequirementChecker
$this
->
usageError
(
'Requirements must be an array, "'
.
gettype
(
$requirements
)
.
'" has been given!'
);
}
if
(
!
isset
(
$this
->
result
)
||
!
is_array
(
$this
->
result
))
{
$this
->
result
=
[
'summary'
=>
[
$this
->
result
=
array
(
'summary'
=>
array
(
'total'
=>
0
,
'errors'
=>
0
,
'warnings'
=>
0
,
]
,
'requirements'
=>
[]
,
]
;
)
,
'requirements'
=>
array
()
,
)
;
}
foreach
(
$requirements
as
$key
=>
$rawRequirement
)
{
$requirement
=
$this
->
normalizeRequirement
(
$rawRequirement
,
$key
);
...
...
@@ -118,21 +118,21 @@ class YiiRequirementChecker
* Return the check results.
* @return array|null check results in format:
* <code>
*
[
* 'summary' =>
[
*
array(
* 'summary' =>
array(
* 'total' => total number of checks,
* 'errors' => number of errors,
* 'warnings' => number of warnings,
*
]
,
* 'requirements' =>
[
*
[
*
)
,
* 'requirements' =>
array(
*
array(
* ...
* 'error' => is there an error,
* 'warning' => is there a warning,
*
]
,
*
)
,
* ...
*
]
,
*
]
*
)
,
*
)
* </code>
*/
function
getResult
()
...
...
This diff is collapsed.
Click to expand it.
framework/yii/requirements/requirements.php
View file @
a3dd0d57
...
...
@@ -5,40 +5,40 @@
*
* @var $this YiiRequirementChecker
*/
return
[
[
return
array
(
array
(
'name'
=>
'PHP version'
,
'mandatory'
=>
true
,
'condition'
=>
version_compare
(
PHP_VERSION
,
'5.4.0'
,
'>='
),
'by'
=>
'<a href="http://www.yiiframework.com">Yii Framework</a>'
,
'memo'
=>
'PHP 5.4.0 or higher is required.'
,
]
,
[
)
,
array
(
'name'
=>
'Reflection extension'
,
'mandatory'
=>
true
,
'condition'
=>
class_exists
(
'Reflection'
,
false
),
'by'
=>
'<a href="http://www.yiiframework.com">Yii Framework</a>'
,
]
,
[
)
,
array
(
'name'
=>
'PCRE extension'
,
'mandatory'
=>
true
,
'condition'
=>
extension_loaded
(
'pcre'
),
'by'
=>
'<a href="http://www.yiiframework.com">Yii Framework</a>'
,
]
,
[
)
,
array
(
'name'
=>
'SPL extension'
,
'mandatory'
=>
true
,
'condition'
=>
extension_loaded
(
'SPL'
),
'by'
=>
'<a href="http://www.yiiframework.com">Yii Framework</a>'
,
]
,
[
)
,
array
(
'name'
=>
'MBString extension'
,
'mandatory'
=>
true
,
'condition'
=>
extension_loaded
(
'mbstring'
),
'by'
=>
'<a href="http://www.php.net/manual/en/book.mbstring.php">Multibyte string</a> processing'
,
'memo'
=>
'Required for multibyte encoding string processing.'
]
,
[
)
,
array
(
'name'
=>
'Intl extension'
,
'mandatory'
=>
false
,
'condition'
=>
$this
->
checkPhpExtensionVersion
(
'intl'
,
'1.0.2'
,
'>='
),
...
...
@@ -46,5 +46,5 @@ return [
'memo'
=>
'PHP Intl extension 1.0.2 or higher is required when you want to use advanced parameters formatting
in <code>\Yii::t()</code>, <abbr title="Internationalized domain names">IDN</abbr>-feature of
<code>EmailValidator</code> or <code>UrlValidator</code> or the <code>yii\i18n\Formatter</code> class.'
]
,
]
;
)
,
)
;
This diff is collapsed.
Click to expand it.
framework/yii/requirements/views/web/index.php
View file @
a3dd0d57
...
...
@@ -52,18 +52,18 @@
<table
class=
"table table-bordered"
>
<tr><th>
Name
</th><th>
Result
</th><th>
Required By
</th><th>
Memo
</th></tr>
<?php
foreach
(
$requirements
as
$requirement
)
:
?>
<tr
class=
"
<?
=
$requirement
[
'condition'
]
?
'success'
:
(
$requirement
[
'mandatory'
]
?
'error'
:
'warning'
)
?>
"
>
<tr
class=
"
<?
php
echo
$requirement
[
'condition'
]
?
'success'
:
(
$requirement
[
'mandatory'
]
?
'error'
:
'warning'
)
?>
"
>
<td>
<?
=
$requirement
[
'name'
]
?>
<?
php
echo
$requirement
[
'name'
]
?>
</td>
<td>
<span
class=
"result"
>
<?
=
$requirement
[
'condition'
]
?
'Passed'
:
(
$requirement
[
'mandatory'
]
?
'Failed'
:
'Warning'
)
?>
</span>
<span
class=
"result"
>
<?
php
echo
$requirement
[
'condition'
]
?
'Passed'
:
(
$requirement
[
'mandatory'
]
?
'Failed'
:
'Warning'
)
?>
</span>
</td>
<td>
<?
=
$requirement
[
'by'
]
?>
<?
php
echo
$requirement
[
'by'
]
?>
</td>
<td>
<?
=
$requirement
[
'memo'
]
?>
<?
php
echo
$requirement
[
'memo'
]
?>
</td>
</tr>
<?php
endforeach
;
?>
...
...
@@ -74,7 +74,7 @@
<hr>
<div
class=
"footer"
>
<p>
Server:
<?
=
$this
->
getServerInfo
()
.
' '
.
$this
->
getNowDate
()
?>
</p>
<p>
Server:
<?
php
echo
$this
->
getServerInfo
()
.
' '
.
$this
->
getNowDate
()
?>
</p>
<p>
Powered by
<a
href=
"http://www.yiiframework.com/"
rel=
"external"
>
Yii Framework
</a></p>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/BooleanValidator.php
View file @
a3dd0d57
...
...
@@ -58,8 +58,8 @@ class BooleanValidator extends Validator
$value
=
$object
->
$attribute
;
if
(
!
$this
->
validateValue
(
$value
))
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
,
[
'
{true}
'
=>
$this
->
trueValue
,
'
{false}
'
=>
$this
->
falseValue
,
'
true
'
=>
$this
->
trueValue
,
'
false
'
=>
$this
->
falseValue
,
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/CompareValidator.php
View file @
a3dd0d57
...
...
@@ -143,8 +143,8 @@ class CompareValidator extends Validator
}
if
(
!
$valid
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
,
[
'
{compareAttribute}
'
=>
$compareLabel
,
'
{compareValue}
'
=>
$compareValue
,
'
compareAttribute
'
=>
$compareLabel
,
'
compareValue
'
=>
$compareValue
,
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/DateValidator.php
View file @
a3dd0d57
...
...
@@ -70,6 +70,8 @@ class DateValidator extends Validator
*/
public
function
validateValue
(
$value
)
{
return
DateTime
::
createFromFormat
(
$this
->
format
,
$value
)
!==
false
;
DateTime
::
createFromFormat
(
$this
->
format
,
$value
);
$errors
=
DateTime
::
getLastErrors
();
return
$errors
[
'error_count'
]
===
0
&&
$errors
[
'warning_count'
]
===
0
;
}
}
This diff is collapsed.
Click to expand it.
framework/yii/validators/FileValidator.php
View file @
a3dd0d57
...
...
@@ -144,7 +144,7 @@ class FileValidator extends Validator
$this
->
addError
(
$object
,
$attribute
,
$this
->
uploadRequired
);
}
if
(
count
(
$files
)
>
$this
->
maxFiles
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooMany
,
[
'
{attribute}'
=>
$attribute
,
'{limit}
'
=>
$this
->
maxFiles
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooMany
,
[
'
limit
'
=>
$this
->
maxFiles
]);
}
else
{
foreach
(
$files
as
$file
)
{
$this
->
validateFile
(
$object
,
$attribute
,
$file
);
...
...
@@ -171,18 +171,18 @@ class FileValidator extends Validator
switch
(
$file
->
error
)
{
case
UPLOAD_ERR_OK
:
if
(
$this
->
maxSize
!==
null
&&
$file
->
size
>
$this
->
maxSize
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooBig
,
[
'
{file}'
=>
$file
->
name
,
'{limit}
'
=>
$this
->
getSizeLimit
()]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooBig
,
[
'
file'
=>
$file
->
name
,
'limit
'
=>
$this
->
getSizeLimit
()]);
}
if
(
$this
->
minSize
!==
null
&&
$file
->
size
<
$this
->
minSize
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooSmall
,
[
'
{file}'
=>
$file
->
name
,
'{limit}
'
=>
$this
->
minSize
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooSmall
,
[
'
file'
=>
$file
->
name
,
'limit
'
=>
$this
->
minSize
]);
}
if
(
!
empty
(
$this
->
types
)
&&
!
in_array
(
strtolower
(
pathinfo
(
$file
->
name
,
PATHINFO_EXTENSION
)),
$this
->
types
,
true
))
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
wrongType
,
[
'
{file}'
=>
$file
->
name
,
'{extensions}
'
=>
implode
(
', '
,
$this
->
types
)]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
wrongType
,
[
'
file'
=>
$file
->
name
,
'extensions
'
=>
implode
(
', '
,
$this
->
types
)]);
}
break
;
case
UPLOAD_ERR_INI_SIZE
:
case
UPLOAD_ERR_FORM_SIZE
:
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooBig
,
[
'
{file}'
=>
$file
->
name
,
'{limit}
'
=>
$this
->
getSizeLimit
()]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooBig
,
[
'
file'
=>
$file
->
name
,
'limit
'
=>
$this
->
getSizeLimit
()]);
break
;
case
UPLOAD_ERR_PARTIAL
:
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/NumberValidator.php
View file @
a3dd0d57
...
...
@@ -91,10 +91,10 @@ class NumberValidator extends Validator
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
if
(
$this
->
min
!==
null
&&
$value
<
$this
->
min
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooSmall
,
[
'
{min}
'
=>
$this
->
min
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooSmall
,
[
'
min
'
=>
$this
->
min
]);
}
if
(
$this
->
max
!==
null
&&
$value
>
$this
->
max
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooBig
,
[
'
{max}
'
=>
$this
->
max
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooBig
,
[
'
max
'
=>
$this
->
max
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/RequiredValidator.php
View file @
a3dd0d57
...
...
@@ -75,7 +75,7 @@ class RequiredValidator extends Validator
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
);
}
else
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
message
,
[
'
{requiredValue}
'
=>
$this
->
requiredValue
,
'
requiredValue
'
=>
$this
->
requiredValue
,
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/StringValidator.php
View file @
a3dd0d57
...
...
@@ -112,13 +112,13 @@ class StringValidator extends Validator
$length
=
mb_strlen
(
$value
,
$this
->
encoding
);
if
(
$this
->
min
!==
null
&&
$length
<
$this
->
min
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooShort
,
[
'
{min}
'
=>
$this
->
min
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooShort
,
[
'
min
'
=>
$this
->
min
]);
}
if
(
$this
->
max
!==
null
&&
$length
>
$this
->
max
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooLong
,
[
'
{max}
'
=>
$this
->
max
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
tooLong
,
[
'
max
'
=>
$this
->
max
]);
}
if
(
$this
->
length
!==
null
&&
$length
!==
$this
->
length
)
{
$this
->
addError
(
$object
,
$attribute
,
$this
->
notEqual
,
[
'
{length}
'
=>
$this
->
length
]);
$this
->
addError
(
$object
,
$attribute
,
$this
->
notEqual
,
[
'
length
'
=>
$this
->
length
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/UniqueValidator.php
View file @
a3dd0d57
...
...
@@ -12,7 +12,7 @@ use yii\base\InvalidConfigException;
use
yii\db\ActiveRecord
;
/**
*
C
UniqueValidator validates that the attribute value is unique in the corresponding database table.
* UniqueValidator validates that the attribute value is unique in the corresponding database table.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
This diff is collapsed.
Click to expand it.
framework/yii/validators/Validator.php
View file @
a3dd0d57
...
...
@@ -251,9 +251,9 @@ abstract class Validator extends Component
public
function
addError
(
$object
,
$attribute
,
$message
,
$params
=
[])
{
$value
=
$object
->
$attribute
;
$params
[
'
{attribute}
'
]
=
$object
->
getAttributeLabel
(
$attribute
);
$params
[
'
{value}
'
]
=
is_array
(
$value
)
?
'array()'
:
$value
;
$object
->
addError
(
$attribute
,
strtr
(
$message
,
$params
));
$params
[
'
attribute
'
]
=
$object
->
getAttributeLabel
(
$attribute
);
$params
[
'
value
'
]
=
is_array
(
$value
)
?
'array()'
:
$value
;
$object
->
addError
(
$attribute
,
Yii
::
$app
->
getI18n
()
->
format
(
$message
,
$params
,
Yii
::
$app
->
language
));
}
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/web/AccessControl.php
View file @
a3dd0d57
...
...
@@ -42,9 +42,9 @@ use yii\base\ActionFilter;
* 'roles' => ['@'],
* ],
* // everything else is denied
*
)
,
*
)
,
*
)
;
*
]
,
*
]
,
*
]
;
* }
* ~~~
*
...
...
This diff is collapsed.
Click to expand it.
framework/yii/web/AssetBundle.php
View file @
a3dd0d57
...
...
@@ -68,7 +68,16 @@ class AssetBundle extends Object
*/
public
$baseUrl
;
/**
* @var array list of the bundle names that this bundle depends on
* @var array list of bundle class names that this bundle depends on.
*
* For example:
*
* ```php
* public $depends = [
* 'yii\web\YiiAsset',
* 'yii\bootstrap\BootstrapAsset',
* ];
* ```
*/
public
$depends
=
[];
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/web/Request.php
View file @
a3dd0d57
...
...
@@ -246,11 +246,7 @@ class Request extends \yii\base\Request
$this
->
_restParams
=
$_POST
;
}
else
{
$this
->
_restParams
=
[];
if
(
function_exists
(
'mb_parse_str'
))
{
mb_parse_str
(
$this
->
getRawBody
(),
$this
->
_restParams
);
}
else
{
parse_str
(
$this
->
getRawBody
(),
$this
->
_restParams
);
}
mb_parse_str
(
$this
->
getRawBody
(),
$this
->
_restParams
);
}
}
return
$this
->
_restParams
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/web/Session.php
View file @
a3dd0d57
...
...
@@ -118,12 +118,9 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
*/
public
function
open
()
{
// this is available in PHP 5.4.0+
if
(
function_exists
(
'session_status'
))
{
if
(
session_status
()
==
PHP_SESSION_ACTIVE
)
{
$this
->
_opened
=
true
;
return
;
}
if
(
session_status
()
==
PHP_SESSION_ACTIVE
)
{
$this
->
_opened
=
true
;
return
;
}
if
(
!
$this
->
_opened
)
{
...
...
This diff is collapsed.
Click to expand it.
framework/yii/web/YiiAsset.php
View file @
a3dd0d57
...
...
@@ -7,9 +7,6 @@
namespace
yii\web
;
use
Yii
;
use
yii\base\View
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
This diff is collapsed.
Click to expand it.
framework/yii/widgets/ActiveField.php
View file @
a3dd0d57
...
...
@@ -8,7 +8,6 @@ namespace yii\widgets;
use
Yii
;
use
yii\base\Component
;
use
yii\db\ActiveRecord
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
use
yii\base\Model
;
...
...
This diff is collapsed.
Click to expand it.
framework/yii/widgets/ActiveForm.php
View file @
a3dd0d57
...
...
@@ -265,4 +265,93 @@ class ActiveForm extends Widget
'form'
=>
$this
,
]));
}
/**
* Validates one or several models and returns an error message array indexed by the attribute IDs.
* This is a helper method that simplifies the way of writing AJAX validation code.
*
* For example, you may use the following code in a controller action to respond
* to an AJAX validation request:
*
* ~~~
* $model = new Post;
* $model->load($_POST);
* if (Yii::$app->request->isAjax) {
* Yii::$app->response->format = Response::FORMAT_JSON;
* return ActiveForm::validate($model);
* }
* // ... respond to non-AJAX request ...
* ~~~
*
* To validate multiple models, simply pass each model as a parameter to this method, like
* the following:
*
* ~~~
* ActiveForm::validate($model1, $model2, ...);
* ~~~
*
* @param Model $model the model to be validated
* @param mixed $attributes list of attributes that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
*
* When this method is used to validate multiple models, this parameter will be interpreted
* as a model.
*
* @return array the error message array indexed by the attribute IDs.
*/
public
static
function
validate
(
$model
,
$attributes
=
null
)
{
$result
=
[];
if
(
$attributes
instanceof
Model
)
{
// validating multiple models
$models
=
func_get_args
();
$attributes
=
null
;
}
else
{
$models
=
[
$model
];
}
/** @var Model $model */
foreach
(
$models
as
$model
)
{
$model
->
validate
(
$attributes
);
foreach
(
$model
->
getErrors
()
as
$attribute
=>
$errors
)
{
$result
[
Html
::
getInputId
(
$model
,
$attribute
)]
=
$errors
;
}
}
return
$result
;
}
/**
* Validates an array of model instances and returns an error message array indexed by the attribute IDs.
* This is a helper method that simplifies the way of writing AJAX validation code for tabular input.
*
* For example, you may use the following code in a controller action to respond
* to an AJAX validation request:
*
* ~~~
* // ... load $models ...
* if (Yii::$app->request->isAjax) {
* Yii::$app->response->format = Response::FORMAT_JSON;
* return ActiveForm::validateMultiple($models);
* }
* // ... respond to non-AJAX request ...
* ~~~
*
* @param array $models an array of models to be validated.
* @param mixed $attributes list of attributes that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
* @return array the error message array indexed by the attribute IDs.
*/
public
static
function
validateMultiple
(
$models
,
$attributes
=
null
)
{
$result
=
[];
/** @var Model $model */
foreach
(
$models
as
$i
=>
$model
)
{
$model
->
validate
(
$attributes
);
foreach
(
$model
->
getErrors
()
as
$attribute
=>
$errors
)
{
$result
[
Html
::
getInputId
(
$model
,
"[
$i
]"
.
$attribute
)]
=
$errors
;
}
}
return
$result
;
}
}
This diff is collapsed.
Click to expand it.
framework/yii/widgets/BaseListView.php
View file @
a3dd0d57
...
...
@@ -131,30 +131,32 @@ abstract class BaseListView extends Widget
public
function
renderSummary
()
{
$count
=
$this
->
dataProvider
->
getCount
();
if
((
$pagination
=
$this
->
dataProvider
->
getPagination
())
!==
false
&&
$count
>
0
)
{
if
((
$pagination
=
$this
->
dataProvider
->
getPagination
())
!==
false
)
{
$totalCount
=
$this
->
dataProvider
->
getTotalCount
();
$begin
=
$pagination
->
getPage
()
*
$pagination
->
pageSize
+
1
;
$end
=
$begin
+
$count
-
1
;
$page
=
$pagination
->
getPage
()
+
1
;
$pageCount
=
$pagination
->
pageCount
;
if
((
$summaryContent
=
$this
->
summary
)
===
null
)
{
$summaryContent
=
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Showing <b>{begin}-{end}</b> of <b>{totalCount}</b> {0, plural, =1{item} other{items}}.'
,
$totalCount
)
.
'</div>'
;
$summaryContent
=
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Showing <b>{totalCount, plural, =0{0} other{{begin}-{end}}}</b> of <b>{totalCount}</b> {totalCount, plural, one{item} other{items}}.'
)
.
'</div>'
;
}
}
else
{
$begin
=
$page
=
$pageCount
=
1
;
$end
=
$totalCount
=
$count
;
if
((
$summaryContent
=
$this
->
summary
)
===
null
)
{
$summaryContent
=
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Total <b>{count}</b> {
0, plural, =1{item} other{items}}.'
,
$count
)
.
'</div>'
;
$summaryContent
=
'<div class="summary">'
.
Yii
::
t
(
'yii'
,
'Total <b>{count}</b> {
count, plural, one{item} other{items}}.'
)
.
'</div>'
;
}
}
return
strtr
(
$summaryContent
,
[
'
{begin}
'
=>
$begin
,
'
{end}
'
=>
$end
,
'
{count}
'
=>
$count
,
'
{totalCount}
'
=>
$totalCount
,
'
{page}
'
=>
$page
,
'
{pageCount}
'
=>
$pageCount
,
]);
return
Yii
::
$app
->
getI18n
()
->
format
(
$summaryContent
,
[
'
begin
'
=>
$begin
,
'
end
'
=>
$end
,
'
count
'
=>
$count
,
'
totalCount
'
=>
$totalCount
,
'
page
'
=>
$page
,
'
pageCount
'
=>
$pageCount
,
]
,
Yii
::
$app
->
language
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
framework/yii/widgets/Menu.php
View file @
a3dd0d57
...
...
@@ -33,13 +33,13 @@ use yii\helpers\Html;
* // not just as 'controller' even if default action is used.
* ['label' => 'Home', 'url' => ['site/index']],
* // 'Products' menu item will be selected as long as the route is 'product/index'
* ['label' => 'Products', 'url' => ['product/index'
)
, 'items' => [
* ['label' => 'Products', 'url' => ['product/index'
]
, 'items' => [
* ['label' => 'New Arrivals', 'url' => ['product/index', 'tag' => 'new']],
* ['label' => 'Most Popular', 'url' => ['product/index', 'tag' => 'popular']],
* ]],
* ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
*
)
,
*
)
);
*
]
,
*
]
);
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
This diff is collapsed.
Click to expand it.
tests/unit/data/ar/ActiveRecord.php
View file @
a3dd0d57
...
...
@@ -7,8 +7,6 @@
namespace
yiiunit\data\ar
;
use
yii\db\Connection
;
/**
* ActiveRecord is ...
*
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/caching/CacheTestCase.php
View file @
a3dd0d57
...
...
@@ -13,7 +13,6 @@ function time()
namespace
yiiunit\framework\caching
;
use
yii\helpers\StringHelper
;
use
yiiunit\TestCase
;
use
yii\caching\Cache
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/caching/RedisCacheTest.php
View file @
a3dd0d57
...
...
@@ -2,7 +2,6 @@
namespace
yiiunit\framework\caching
;
use
yii\caching\MemCache
;
use
yii\caching\RedisCache
;
use
yiiunit\TestCase
;
/**
* Class for testing redis cache backend
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/caching/ZendDataCacheTest.php
View file @
a3dd0d57
<?php
namespace
yiiunit\framework\caching
;
use
yii\caching\Cache
;
use
yii\caching\ZendDataCache
;
/**
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/ActiveRecordTest.php
View file @
a3dd0d57
<?php
namespace
yiiunit\framework\db
;
use
yii\db\Query
;
use
yii\db\ActiveQuery
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\data\ar\Customer
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/CommandTest.php
View file @
a3dd0d57
...
...
@@ -2,9 +2,6 @@
namespace
yiiunit\framework\db
;
use
yii\db\Connection
;
use
yii\db\Command
;
use
yii\db\Query
;
use
yii\db\DataReader
;
/**
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/QueryTest.php
View file @
a3dd0d57
...
...
@@ -2,10 +2,7 @@
namespace
yiiunit\framework\db
;
use
yii\db\Connection
;
use
yii\db\Command
;
use
yii\db\Query
;
use
yii\db\DataReader
;
/**
* @group db
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php
View file @
a3dd0d57
...
...
@@ -2,7 +2,6 @@
namespace
yiiunit\framework\db\cubrid
;
use
yii\base\NotSupportedException
;
use
yii\db\sqlite\Schema
;
use
yiiunit\framework\db\QueryBuilderTest
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/i18n/FallbackMessageFormatterTest.php
0 → 100644
View file @
a3dd0d57
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yiiunit\framework\i18n
;
use
yii\i18n\FallbackMessageFormatter
;
use
yiiunit\TestCase
;
/**
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
* @group i18n
*/
class
FallbackMessageFormatterTest
extends
TestCase
{
const
N
=
'n'
;
const
N_VALUE
=
42
;
const
SUBJECT
=
'сабж'
;
const
SUBJECT_VALUE
=
'Answer to the Ultimate Question of Life, the Universe, and Everything'
;
public
function
patterns
()
{
return
[
[
'{'
.
self
::
SUBJECT
.
'} is {'
.
self
::
N
.
'}'
,
// pattern
self
::
SUBJECT_VALUE
.
' is '
.
self
::
N_VALUE
,
// expected
[
// params
self
::
N
=>
self
::
N_VALUE
,
self
::
SUBJECT
=>
self
::
SUBJECT_VALUE
,
]
],
// This one was provided by Aura.Intl. Thanks!
[
<<<_MSG_
{gender_of_host, select,
female {{num_guests, plural, offset:1
=0 {{host} does not give a party.}
=1 {{host} invites {guest} to her party.}
=2 {{host} invites {guest} and one other person to her party.}
other {{host} invites {guest} and # other people to her party.}}}
male {{num_guests, plural, offset:1
=0 {{host} does not give a party.}
=1 {{host} invites {guest} to his party.}
=2 {{host} invites {guest} and one other person to his party.}
other {{host} invites {guest} and # other people to his party.}}}
other {{num_guests, plural, offset:1
=0 {{host} does not give a party.}
=1 {{host} invites {guest} to their party.}
=2 {{host} invites {guest} and one other person to their party.}
other {{host} invites {guest} and # other people to their party.}}}}
_MSG_
,
'ralph invites beep and 3 other people to his party.'
,
[
'gender_of_host'
=>
'male'
,
'num_guests'
=>
4
,
'host'
=>
'ralph'
,
'guest'
=>
'beep'
]
],
[
'{name} is {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!'
,
'Alexander is male and he loves Yii!'
,
[
'name'
=>
'Alexander'
,
'gender'
=>
'male'
,
],
],
// verify pattern in select does not get replaced
[
'{name} is {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!'
,
'Alexander is male and he loves Yii!'
,
[
'name'
=>
'Alexander'
,
'gender'
=>
'male'
,
// following should not be replaced
'he'
=>
'wtf'
,
'she'
=>
'wtf'
,
'it'
=>
'wtf'
,
]
],
// verify pattern in select message gets replaced
[
'{name} is {gender} and {gender, select, female{she} male{{he}} other{it}} loves Yii!'
,
'Alexander is male and wtf loves Yii!'
,
[
'name'
=>
'Alexander'
,
'gender'
=>
'male'
,
'he'
=>
'wtf'
,
'she'
=>
'wtf'
,
],
],
// some parser specific verifications
[
'{gender} and {gender, select, female{she} male{{he}} other{it}} loves {nr} is {gender}!'
,
'male and wtf loves 42 is male!'
,
[
'nr'
=>
42
,
'gender'
=>
'male'
,
'he'
=>
'wtf'
,
'she'
=>
'wtf'
,
],
],
];
}
/**
* @dataProvider patterns
*/
public
function
testNamedArgumentsStatic
(
$pattern
,
$expected
,
$args
)
{
$result
=
FallbackMessageFormatter
::
formatMessage
(
'en_US'
,
$pattern
,
$args
);
$this
->
assertEquals
(
$expected
,
$result
);
}
/**
* @dataProvider patterns
*/
public
function
testNamedArgumentsObject
(
$pattern
,
$expected
,
$args
)
{
$formatter
=
new
FallbackMessageFormatter
(
'en_US'
,
$pattern
);
$result
=
$formatter
->
format
(
$args
);
$this
->
assertEquals
(
$expected
,
$result
,
$formatter
->
getErrorMessage
());
}
public
function
testInsufficientArguments
()
{
$expected
=
'{'
.
self
::
SUBJECT
.
'} is '
.
self
::
N_VALUE
;
$result
=
FallbackMessageFormatter
::
formatMessage
(
'en_US'
,
'{'
.
self
::
SUBJECT
.
'} is {'
.
self
::
N
.
'}'
,
[
self
::
N
=>
self
::
N_VALUE
,
]);
$this
->
assertEquals
(
$expected
,
$result
);
}
public
function
testNoParams
()
{
$pattern
=
'{'
.
self
::
SUBJECT
.
'} is '
.
self
::
N
;
$result
=
FallbackMessageFormatter
::
formatMessage
(
'en_US'
,
$pattern
,
[]);
$this
->
assertEquals
(
$pattern
,
$result
);
$formatter
=
new
FallbackMessageFormatter
(
'en_US'
,
$pattern
);
$result
=
$formatter
->
format
([]);
$this
->
assertEquals
(
$pattern
,
$result
,
$formatter
->
getErrorMessage
());
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/unit/framework/i18n/GettextMessageSourceTest.php
View file @
a3dd0d57
...
...
@@ -2,7 +2,6 @@
namespace
yiiunit\framework\i18n
;
use
yii\i18n\GettextMessageSource
;
use
yiiunit\TestCase
;
/**
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/i18n/I18NTest.php
View file @
a3dd0d57
...
...
@@ -9,7 +9,6 @@ namespace yiiunit\framework\i18n;
use
yii\base\Model
;
use
yii\i18n\I18N
;
use
yii\i18n\MessageFormatter
;
use
yii\i18n\PhpMessageSource
;
use
yiiunit\TestCase
;
...
...
@@ -51,7 +50,13 @@ class I18NTest extends TestCase
$params
=
[
'n'
=>
42
];
$this
->
assertEquals
(
'His speed is about 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'en_US'
));
$this
->
assertEquals
(
'Seine Geschwindigkeit beträgt 42 km/h.'
,
$this
->
i18n
->
translate
(
'test'
,
$msg
,
$params
,
'de_DE'
));
}
public
function
testTranslateParams2
()
{
if
(
!
extension_loaded
(
"intl"
))
{
$this
->
markTestSkipped
(
"intl not installed. Skipping."
);
}
$msg
=
'His name is {name} and his speed is about {n, number} km/h.'
;
$params
=
[
'n'
=>
42
,
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/BooleanValidatorTest.php
View file @
a3dd0d57
...
...
@@ -10,6 +10,12 @@ use yiiunit\TestCase;
*/
class
BooleanValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateValue
()
{
$val
=
new
BooleanValidator
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/CompareValidatorTest.php
View file @
a3dd0d57
...
...
@@ -10,6 +10,11 @@ use yiiunit\TestCase;
class
CompareValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateValueException
()
{
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/DateValidatorTest.php
View file @
a3dd0d57
...
...
@@ -10,6 +10,12 @@ use yiiunit\TestCase;
class
DateValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testEnsureMessageIsSet
()
{
$val
=
new
DateValidator
;
...
...
@@ -19,6 +25,7 @@ class DateValidatorTest extends TestCase
public
function
testValidateValue
()
{
$val
=
new
DateValidator
;
$this
->
assertFalse
(
$val
->
validateValue
(
'3232-32-32'
));
$this
->
assertTrue
(
$val
->
validateValue
(
'2013-09-13'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'31.7.2013'
));
$this
->
assertFalse
(
$val
->
validateValue
(
'31-7-2013'
));
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/DefaultValueValidatorTest.php
View file @
a3dd0d57
...
...
@@ -8,6 +8,12 @@ use yiiunit\TestCase;
*/
class
DefaultValueValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateAttribute
()
{
$val
=
new
DefaultValueValidator
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/EmailValidatorTest.php
View file @
a3dd0d57
...
...
@@ -11,6 +11,12 @@ use yiiunit\TestCase;
*/
class
EmailValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateValue
()
{
$validator
=
new
EmailValidator
();
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/ExistValidatorTest.php
View file @
a3dd0d57
...
...
@@ -18,6 +18,7 @@ class ExistValidatorTest extends DatabaseTestCase
public
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
ActiveRecord
::
$db
=
$this
->
getConnection
();
}
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/FilterValidatorTest.php
View file @
a3dd0d57
...
...
@@ -9,6 +9,12 @@ use yiiunit\TestCase;
class
FilterValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testAssureExceptionOnInit
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
);
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/NumberValidatorTest.php
View file @
a3dd0d57
...
...
@@ -9,6 +9,12 @@ use yiiunit\TestCase;
class
NumberValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testEnsureMessageOnInit
()
{
$val
=
new
NumberValidator
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/RangeValidatorTest.php
View file @
a3dd0d57
...
...
@@ -9,6 +9,12 @@ use yiiunit\TestCase;
class
RangeValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testInitException
()
{
$this
->
setExpectedException
(
'yii\base\InvalidConfigException'
,
'The "range" property must be set.'
);
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/RegularExpressionValidatorTest.php
View file @
a3dd0d57
...
...
@@ -9,6 +9,12 @@ use yiiunit\TestCase;
class
RegularExpressionValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateValue
()
{
$val
=
new
RegularExpressionValidator
([
'pattern'
=>
'/^[a-zA-Z0-9](\.)?([^\/]*)$/m'
]);
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/RequiredValidatorTest.php
View file @
a3dd0d57
...
...
@@ -8,6 +8,12 @@ use yiiunit\TestCase;
class
RequiredValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateValueWithDefaults
()
{
$val
=
new
RequiredValidator
();
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/UniqueValidatorTest.php
View file @
a3dd0d57
...
...
@@ -10,7 +10,6 @@ use yiiunit\data\validators\models\FakedValidationModel;
use
yiiunit\data\validators\models\ValidatorTestMainModel
;
use
yiiunit\data\validators\models\ValidatorTestRefModel
;
use
yiiunit\framework\db\DatabaseTestCase
;
use
yiiunit\TestCase
;
class
UniqueValidatorTest
extends
DatabaseTestCase
{
...
...
@@ -19,6 +18,7 @@ class UniqueValidatorTest extends DatabaseTestCase
public
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
ActiveRecord
::
$db
=
$this
->
getConnection
();
}
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/UrlValidatorTest.php
View file @
a3dd0d57
...
...
@@ -9,6 +9,12 @@ use yiiunit\TestCase;
*/
class
UrlValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
public
function
testValidateValue
()
{
$val
=
new
UrlValidator
;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/framework/validators/ValidatorTest.php
View file @
a3dd0d57
...
...
@@ -12,6 +12,11 @@ use yiiunit\TestCase;
class
ValidatorTest
extends
TestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
}
protected
function
getTestModel
(
$additionalAttributes
=
[])
{
...
...
@@ -220,7 +225,7 @@ class ValidatorTest extends TestCase
$errors
=
$m
->
getErrors
(
'attr_msg_val'
);
$this
->
assertEquals
(
'attr_msg_val::array()'
,
$errors
[
0
]);
$m
=
$this
->
getTestModel
([
'attr_msg_val'
=>
'abc'
]);
$val
->
addError
(
$m
,
'attr_msg_val'
,
'{attribute}::{value}::{param}'
,
[
'
{param}
'
=>
'param_value'
]);
$val
->
addError
(
$m
,
'attr_msg_val'
,
'{attribute}::{value}::{param}'
,
[
'
param
'
=>
'param_value'
]);
$errors
=
$m
->
getErrors
(
'attr_msg_val'
);
$this
->
assertEquals
(
'attr_msg_val::abc::param_value'
,
$errors
[
0
]);
}
...
...
This diff is collapsed.
Click to expand it.
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