mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
cleanup.
This commit is contained in:
@ -62,7 +62,7 @@ class LocaleController extends Controller
|
|||||||
}
|
}
|
||||||
$expr = preg_replace('/\\bn\\b/', '$n', implode('||', $expr_or));
|
$expr = preg_replace('/\\bn\\b/', '$n', implode('||', $expr_or));
|
||||||
$rules[] = preg_replace_callback('/range\((\d+),(\d+)\)/', function ($matches) {
|
$rules[] = preg_replace_callback('/range\((\d+),(\d+)\)/', function ($matches) {
|
||||||
if ($matches[2] - $matches[1] <= 2) {
|
if ($matches[2] - $matches[1] <= 5) {
|
||||||
return 'array(' . implode(',', range($matches[1], $matches[2])) . ')';
|
return 'array(' . implode(',', range($matches[1], $matches[2])) . ')';
|
||||||
} else {
|
} else {
|
||||||
return $matches[0];
|
return $matches[0];
|
||||||
|
@ -494,8 +494,8 @@ return array (
|
|||||||
array (
|
array (
|
||||||
0 => '$n==1',
|
0 => '$n==1',
|
||||||
1 => '$n==2',
|
1 => '$n==2',
|
||||||
2 => 'in_array($n,range(3,6))',
|
2 => 'in_array($n,array(3,4,5,6))',
|
||||||
3 => 'in_array($n,range(7,10))',
|
3 => 'in_array($n,array(7,8,9,10))',
|
||||||
),
|
),
|
||||||
'ro' =>
|
'ro' =>
|
||||||
array (
|
array (
|
||||||
@ -516,43 +516,43 @@ return array (
|
|||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'bs' =>
|
'bs' =>
|
||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'hr' =>
|
'hr' =>
|
||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'ru' =>
|
'ru' =>
|
||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'sh' =>
|
'sh' =>
|
||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'sr' =>
|
'sr' =>
|
||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'uk' =>
|
'uk' =>
|
||||||
array (
|
array (
|
||||||
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
0 => 'fmod($n,10)==1&&fmod($n,100)!=11',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => 'fmod($n,10)==0||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),range(11,14))',
|
2 => 'fmod($n,10)==0||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(11,12,13,14))',
|
||||||
),
|
),
|
||||||
'cs' =>
|
'cs' =>
|
||||||
array (
|
array (
|
||||||
@ -568,7 +568,7 @@ return array (
|
|||||||
array (
|
array (
|
||||||
0 => '$n==1',
|
0 => '$n==1',
|
||||||
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
1 => 'in_array(fmod($n,10),array(2,3,4))&&!in_array(fmod($n,100),array(12,13,14))',
|
||||||
2 => '$n!=1&&in_array(fmod($n,10),array(0,1))||in_array(fmod($n,10),range(5,9))||in_array(fmod($n,100),array(12,13,14))',
|
2 => '$n!=1&&in_array(fmod($n,10),array(0,1))||in_array(fmod($n,10),array(5,6,7,8,9))||in_array(fmod($n,100),array(12,13,14))',
|
||||||
),
|
),
|
||||||
'sl' =>
|
'sl' =>
|
||||||
array (
|
array (
|
||||||
|
@ -110,8 +110,7 @@ class ActiveForm extends Widget
|
|||||||
*/
|
*/
|
||||||
public function error($model, $attribute, $options = array())
|
public function error($model, $attribute, $options = array())
|
||||||
{
|
{
|
||||||
$attribute = $this->normalizeAttributeName($attribute);
|
$attribute = $this->getAttributeName($attribute);
|
||||||
$this->getInputName($model, $attribute);
|
|
||||||
$tag = isset($options['tag']) ? $options['tag'] : 'div';
|
$tag = isset($options['tag']) ? $options['tag'] : 'div';
|
||||||
unset($options['tag']);
|
unset($options['tag']);
|
||||||
$error = $model->getFirstError($attribute);
|
$error = $model->getFirstError($attribute);
|
||||||
@ -126,15 +125,19 @@ class ActiveForm extends Widget
|
|||||||
*/
|
*/
|
||||||
public function label($model, $attribute, $options = array())
|
public function label($model, $attribute, $options = array())
|
||||||
{
|
{
|
||||||
$attribute = $this->normalizeAttributeName($attribute);
|
$attribute = $this->getAttributeName($attribute);
|
||||||
$label = $model->getAttributeLabel($attribute);
|
$label = isset($options['label']) ? $options['label'] : Html::encode($model->getAttributeLabel($attribute));
|
||||||
return Html::label(Html::encode($label), isset($options['for']) ? $options['for'] : null, $options);
|
$for = array_key_exists('for', $options) ? $options['for'] : $this->getInputId($model, $attribute);
|
||||||
|
return Html::label($label, $for, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function input($type, $model, $attribute, $options = array())
|
public function input($type, $model, $attribute, $options = array())
|
||||||
{
|
{
|
||||||
$value = $this->getAttributeValue($model, $attribute);
|
$value = $this->getAttributeValue($model, $attribute);
|
||||||
$name = $this->getInputName($model, $attribute);
|
$name = $this->getInputName($model, $attribute);
|
||||||
|
if (!array_key_exists('id', $options)) {
|
||||||
|
$options['id'] = $this->getInputId($model, $attribute);
|
||||||
|
}
|
||||||
return Html::input($type, $name, $value, $options);
|
return Html::input($type, $name, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +165,9 @@ class ActiveForm extends Widget
|
|||||||
{
|
{
|
||||||
$value = $this->getAttributeValue($model, $attribute);
|
$value = $this->getAttributeValue($model, $attribute);
|
||||||
$name = $this->getInputName($model, $attribute);
|
$name = $this->getInputName($model, $attribute);
|
||||||
|
if (!array_key_exists('id', $options)) {
|
||||||
|
$options['id'] = $this->getInputId($model, $attribute);
|
||||||
|
}
|
||||||
return Html::textarea($name, $value, $options);
|
return Html::textarea($name, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +178,9 @@ class ActiveForm extends Widget
|
|||||||
if (!array_key_exists('uncheck', $options)) {
|
if (!array_key_exists('uncheck', $options)) {
|
||||||
$options['unchecked'] = '0';
|
$options['unchecked'] = '0';
|
||||||
}
|
}
|
||||||
|
if (!array_key_exists('id', $options)) {
|
||||||
|
$options['id'] = $this->getInputId($model, $attribute);
|
||||||
|
}
|
||||||
return Html::radio($name, $checked, $value, $options);
|
return Html::radio($name, $checked, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,6 +191,9 @@ class ActiveForm extends Widget
|
|||||||
if (!array_key_exists('uncheck', $options)) {
|
if (!array_key_exists('uncheck', $options)) {
|
||||||
$options['unchecked'] = '0';
|
$options['unchecked'] = '0';
|
||||||
}
|
}
|
||||||
|
if (!array_key_exists('id', $options)) {
|
||||||
|
$options['id'] = $this->getInputId($model, $attribute);
|
||||||
|
}
|
||||||
return Html::checkbox($name, $checked, $value, $options);
|
return Html::checkbox($name, $checked, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,6 +201,9 @@ class ActiveForm extends Widget
|
|||||||
{
|
{
|
||||||
$checked = $this->getAttributeValue($model, $attribute);
|
$checked = $this->getAttributeValue($model, $attribute);
|
||||||
$name = $this->getInputName($model, $attribute);
|
$name = $this->getInputName($model, $attribute);
|
||||||
|
if (!array_key_exists('id', $options)) {
|
||||||
|
$options['id'] = $this->getInputId($model, $attribute);
|
||||||
|
}
|
||||||
return Html::dropDownList($name, $checked, $items, $options);
|
return Html::dropDownList($name, $checked, $items, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +214,9 @@ class ActiveForm extends Widget
|
|||||||
if (!array_key_exists('unselect', $options)) {
|
if (!array_key_exists('unselect', $options)) {
|
||||||
$options['unselect'] = '0';
|
$options['unselect'] = '0';
|
||||||
}
|
}
|
||||||
|
if (!array_key_exists('id', $options)) {
|
||||||
|
$options['id'] = $this->getInputId($model, $attribute);
|
||||||
|
}
|
||||||
return Html::listBox($name, $checked, $items, $options);
|
return Html::listBox($name, $checked, $items, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +246,7 @@ class ActiveForm extends Widget
|
|||||||
if (isset($this->modelMap[$class])) {
|
if (isset($this->modelMap[$class])) {
|
||||||
$class = $this->modelMap[$class];
|
$class = $this->modelMap[$class];
|
||||||
} elseif (($pos = strrpos($class, '\\')) !== false) {
|
} elseif (($pos = strrpos($class, '\\')) !== false) {
|
||||||
$class = substr($class, $pos);
|
$class = substr($class, $pos + 1);
|
||||||
}
|
}
|
||||||
if (!preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
|
if (!preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
|
||||||
throw new InvalidParamException('Attribute name must contain word characters only.');
|
throw new InvalidParamException('Attribute name must contain word characters only.');
|
||||||
@ -245,6 +263,12 @@ class ActiveForm extends Widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getInputId($model, $attribute)
|
||||||
|
{
|
||||||
|
$name = $this->getInputName($model, $attribute);
|
||||||
|
return str_replace(array('[]', '][', '[', ']', ' '), array('', '-', '-', '', '-'), $name);
|
||||||
|
}
|
||||||
|
|
||||||
public function getAttributeValue($model, $attribute)
|
public function getAttributeValue($model, $attribute)
|
||||||
{
|
{
|
||||||
if (!preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
|
if (!preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
|
||||||
@ -267,7 +291,7 @@ class ActiveForm extends Widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function normalizeAttributeName($attribute)
|
public function getAttributeName($attribute)
|
||||||
{
|
{
|
||||||
if (preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
|
if (preg_match('/(^|.*\])(\w+)(\[.*|$)/', $attribute, $matches)) {
|
||||||
return $matches[2];
|
return $matches[2];
|
||||||
|
Reference in New Issue
Block a user