Skip to content

Commit

Permalink
used PHP 5.4 array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 21, 2015
1 parent 459aeab commit 532059a
Show file tree
Hide file tree
Showing 81 changed files with 877 additions and 877 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ matrix:

script:
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
- php code-checker/src/code-checker.php -i netteForms
- php temp/code-checker/src/code-checker.php --short-arrays -i netteForms
- if [ $TRAVIS_PHP_VERSION == "5.6" ]; then grunt --gruntfile tests/netteForms/Gruntfile.js test; fi

after_failure:
Expand All @@ -23,5 +23,5 @@ after_failure:
before_script:
# Install Nette Tester & Code Checker
- composer install --no-interaction --prefer-source
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
- composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction --prefer-source
- if [ $TRAVIS_PHP_VERSION == "5.6" ]; then npm install -g grunt-cli; cd tests/netteForms; npm install; bower install; cd ../..; fi
22 changes: 11 additions & 11 deletions examples/basic-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
$form->addText('age', 'Your age:')
->setRequired('Enter your age')
->addRule($form::INTEGER, 'Age must be numeric value')
->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);

$form->addRadioList('gender', 'Your gender:', array(
$form->addRadioList('gender', 'Your gender:', [
'm' => 'male',
'f' => 'female',
));
]);

$form->addCheckboxList('colors', 'Favorite colors:', array(
$form->addCheckboxList('colors', 'Favorite colors:', [
'r' => 'red',
'g' => 'green',
'b' => 'blue',
));
]);

$form->addText('email', 'Email:')
->setEmptyValue('@')
Expand All @@ -67,14 +67,14 @@
->addConditionOn($form['send'], $form::FILLED)
->setRequired('Enter your shipping address');

$countries = array(
'World' => array(
$countries = [
'World' => [
'bu' => 'Buranda',
'qu' => 'Qumran',
'st' => 'Saint Georges Island',
),
],
'?' => 'other',
);
];
$form->addSelect('country', 'Country:', $countries)
->setPrompt('Select your country')
->addConditionOn($form['send'], $form::FILLED)
Expand Down Expand Up @@ -106,10 +106,10 @@
$form->addSubmit('submit', 'Send');


$form->setDefaults(array(
$form->setDefaults([
'name' => 'John Doe',
'userid' => 231,
));
]);


if ($form->isSuccess()) {
Expand Down
12 changes: 6 additions & 6 deletions examples/bootstrap2-rendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
$form->addText('name', 'Your name')
->setRequired('Enter your name');

$form->addRadioList('gender', 'Your gender', array(
$form->addRadioList('gender', 'Your gender', [
'male', 'female',
));
]);

$form->addCheckboxList('colors', 'Favorite colors:', array(
$form->addCheckboxList('colors', 'Favorite colors:', [
'red', 'green', 'blue',
));
]);

$form->addSelect('country', 'Country', array(
$form->addSelect('country', 'Country', [
'Buranda', 'Qumran', 'Saint Georges Island',
));
]);

$form->addCheckbox('send', 'Ship to address');

Expand Down
12 changes: 6 additions & 6 deletions examples/bootstrap3-rendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
$form->addText('name', 'Your name')
->setRequired('Enter your name');

$form->addRadioList('gender', 'Your gender', array(
$form->addRadioList('gender', 'Your gender', [
'male', 'female',
));
]);

$form->addCheckboxList('colors', 'Favorite colors:', array(
$form->addCheckboxList('colors', 'Favorite colors:', [
'red', 'green', 'blue',
));
]);

$form->addSelect('country', 'Country', array(
$form->addSelect('country', 'Country', [
'Buranda', 'Qumran', 'Saint Georges Island',
));
]);

$form->addCheckbox('send', 'Ship to address');

Expand Down
4 changes: 2 additions & 2 deletions examples/custom-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function getControl()
return Html::el()
->add(Html::el('input')->name($name . '[day]')->id($this->getHtmlId())->value($this->day))
->add(Nette\Forms\Helpers::createSelectBox(
array(1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
array('selected?' => $this->month)
[1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
['selected?' => $this->month]
)->name($name . '[month]'))
->add(Html::el('input')->name($name . '[year]')->value($this->year));
}
Expand Down
8 changes: 4 additions & 4 deletions examples/custom-rendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
$form->addText('name', 'Your name')
->setRequired('Enter your name');

$form->addRadioList('gender', 'Your gender', array(
$form->addRadioList('gender', 'Your gender', [
'm' => Html::el('option', 'male')->style('color: #248bd3'),
'f' => Html::el('option', 'female')->style('color: #e948d4'),
));
]);

$form->addSelect('country', 'Country', array(
$form->addSelect('country', 'Country', [
'Buranda', 'Qumran', 'Saint Georges Island',
));
]);

$form->addCheckbox('send', 'Ship to address');

Expand Down
4 changes: 2 additions & 2 deletions examples/html5.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
->setType('number')
->setDefaultValue(10)
->addRule($form::INTEGER, 'Must be numeric value')
->addRule($form::RANGE, 'Must be in range from %d to %d', array(1, 100));
->addRule($form::RANGE, 'Must be in range from %d to %d', [1, 100]);

$form->addText('precision', 'Precision:')
->setType('range')
->setDefaultValue(50)
->addRule($form::INTEGER, 'Precision must be numeric value')
->addRule($form::RANGE, 'Precision must be in range from %d to %d', array(0, 100));
->addRule($form::RANGE, 'Precision must be in range from %d to %d', [0, 100]);

$form->addText('email', 'Send to email:')
->setType('email')
Expand Down
10 changes: 5 additions & 5 deletions examples/localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public function translate($message, $count = NULL)
$form->addText('age', 'Your age:')
->setRequired('Enter your age')
->addRule($form::INTEGER, 'Age must be numeric value')
->addRule($form::RANGE, 'Age must be in range from %d to %d', array(10, 100));
->addRule($form::RANGE, 'Age must be in range from %d to %d', [10, 100]);

$countries = array(
'World' => array(
$countries = [
'World' => [
'bu' => 'Buranda',
'qu' => 'Qumran',
'st' => 'Saint Georges Island',
),
],
'?' => 'other',
);
];
$form->addSelect('country', 'Country:', $countries)
->setPrompt('Select your country');

Expand Down
4 changes: 2 additions & 2 deletions examples/manual-rendering.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
$form->addText('age')
->setRequired('Enter your age');

$form->addRadioList('gender', NULL, array(
$form->addRadioList('gender', NULL, [
'm' => 'male',
'f' => 'female',
));
]);

$form->addText('email')
->addCondition($form::FILLED)
Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/FormsDI/FormsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
class FormsExtension extends Nette\DI\CompilerExtension
{
public $defaults = array(
'messages' => array()
);
public $defaults = [
'messages' => []
];


public function afterCompile(Nette\PhpGenerator\ClassType $class)
Expand All @@ -30,9 +30,9 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)

foreach ((array) $config['messages'] as $name => $text) {
if (defined('Nette\Forms\Form::' . $name)) {
$initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', array($name, $text));
$initialize->addBody('Nette\Forms\Validator::$messages[Nette\Forms\Form::?] = ?;', [$name, $text]);
} elseif (defined($name)) {
$initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', array($text));
$initialize->addBody('Nette\Forms\Validator::$messages[' . $name . '] = ?;', [$text]);
} else {
throw new Nette\InvalidArgumentException('Constant Nette\Forms\Form::' . $name . ' or constant ' . $name . ' does not exist.');
}
Expand Down
18 changes: 9 additions & 9 deletions src/Bridges/FormsLatte/FormMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class FormMacros extends MacroSet
public static function install(Latte\Compiler $compiler)
{
$me = new static($compiler);
$me->addMacro('form', array($me, 'macroForm'), 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)');
$me->addMacro('formContainer', array($me, 'macroFormContainer'), '$formContainer = $_form = array_pop($_formStack)');
$me->addMacro('label', array($me, 'macroLabel'), array($me, 'macroLabelEnd'));
$me->addMacro('input', array($me, 'macroInput'), NULL, array($me, 'macroInputAttr'));
$me->addMacro('name', array($me, 'macroName'), array($me, 'macroNameEnd'), array($me, 'macroNameAttr'));
$me->addMacro('inputError', array($me, 'macroInputError'));
$me->addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form)');
$me->addMacro('formContainer', [$me, 'macroFormContainer'], '$formContainer = $_form = array_pop($_formStack)');
$me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd']);
$me->addMacro('input', [$me, 'macroInput'], NULL, [$me, 'macroInputAttr']);
$me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']);
$me->addMacro('inputError', [$me, 'macroInputError']);
}


Expand Down Expand Up @@ -97,7 +97,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer)
. '->%1.raw) echo $_label'
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''),
$name,
$words ? ('getLabelPart(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')') : 'getLabel()'
$words ? ('getLabelPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')') : 'getLabel()'
);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public function macroInput(MacroNode $node, PhpWriter $writer)
. '->%1.raw'
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''),
$name,
$words ? 'getControlPart(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')' : 'getControl()'
$words ? 'getControlPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')' : 'getControl()'
);
}

Expand Down Expand Up @@ -172,7 +172,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
. ($node->htmlNode->attrs ? '->addAttributes(%2.var)' : '') . '->attributes()',
$name,
$words
? $method . 'Part(' . implode(', ', array_map(array($writer, 'formatWord'), $words)) . ')'
? $method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')'
: "{method_exists(\$_input, '{$method}Part')?'{$method}Part':'{$method}'}()",
array_fill_keys(array_keys($node->htmlNode->attrs), NULL)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/FormsLatte/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function renderFormEnd(Form $form, $withTags = TRUE)
$parts = explode('=', $param, 2);
$name = urldecode($parts[0]);
if (!isset($form[$name])) {
$s .= Html::el('input', array('type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])));
$s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function setValues($values, $erase = FALSE)
$control->setValues($values[$name], $erase);

} elseif ($erase) {
$control->setValues(array(), $erase);
$control->setValues([], $erase);
}
}
}
Expand All @@ -97,7 +97,7 @@ public function setValues($values, $erase = FALSE)
*/
public function getValues($asArray = FALSE)
{
$values = $asArray ? array() : new Nette\Utils\ArrayHash;
$values = $asArray ? [] : new Nette\Utils\ArrayHash;
foreach ($this->getComponents() as $name => $control) {
if ($control instanceof IControl && !$control->isOmitted()) {
$values[$name] = $control->getValue();
Expand Down Expand Up @@ -139,7 +139,7 @@ public function validate(array $controls = NULL)
foreach ($controls === NULL ? $this->getComponents() : $controls as $control) {
$control->validate();
}
foreach ($this->onValidate ?: array() as $handler) {
foreach ($this->onValidate ?: [] as $handler) {
$params = Nette\Utils\Callback::toReflection($handler)->getParameters();
$values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
Nette\Utils\Callback::invoke($handler, $this, $values);
Expand All @@ -154,7 +154,7 @@ public function validate(array $controls = NULL)
*/
public function getErrors()
{
$errors = array();
$errors = [];
foreach ($this->getControls() as $control) {
$errors = array_merge($errors, $control->getErrors());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/ControlGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ControlGroup extends Nette\Object
protected $controls;

/** @var array user options */
private $options = array();
private $options = [];


public function __construct()
Expand Down
16 changes: 8 additions & 8 deletions src/Forms/Controls/BaseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
protected $label;

/** @var array */
private $errors = array();
private $errors = [];

/** @var bool */
protected $disabled = FALSE;
Expand All @@ -69,7 +69,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
private $translator = TRUE; // means autodetect

/** @var array user options */
private $options = array();
private $options = [];


/**
Expand All @@ -79,7 +79,7 @@ public function __construct($caption = NULL)
{
$this->monitor('Nette\Forms\Form');
parent::__construct();
$this->control = Html::el('input', array('type' => NULL, 'name' => NULL));
$this->control = Html::el('input', ['type' => NULL, 'name' => NULL]);
$this->label = Html::el('label');
$this->caption = $caption;
$this->rules = new Nette\Forms\Rules($this);
Expand Down Expand Up @@ -172,7 +172,7 @@ public function getValue()
public function isFilled()
{
$value = $this->getValue();
return $value !== NULL && $value !== array() && $value !== '';
return $value !== NULL && $value !== [] && $value !== '';
}


Expand Down Expand Up @@ -248,13 +248,13 @@ public function getControl()
{
$this->setOption('rendered', TRUE);
$el = clone $this->control;
return $el->addAttributes(array(
return $el->addAttributes([
'name' => $this->getHtmlName(),
'id' => $this->getHtmlId(),
'required' => $this->isRequired(),
'disabled' => $this->isDisabled(),
'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules) ?: NULL,
));
]);
}


Expand Down Expand Up @@ -366,7 +366,7 @@ public function getTranslator()
public function translate($value, $count = NULL)
{
if ($translator = $this->getTranslator()) {
$tmp = is_array($value) ? array(& $value) : array(array(& $value));
$tmp = is_array($value) ? [& $value] : [[& $value]];
foreach ($tmp[0] as & $v) {
if ($v != NULL && !$v instanceof Html) { // intentionally ==
$v = $translator->translate($v, $count);
Expand Down Expand Up @@ -509,7 +509,7 @@ public function hasErrors()
*/
public function cleanErrors()
{
$this->errors = array();
$this->errors = [];
}


Expand Down

0 comments on commit 532059a

Please sign in to comment.