Skip to content

Commit

Permalink
constants are PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 7, 2023
1 parent 4864154 commit 94ecd90
Show file tree
Hide file tree
Showing 50 changed files with 424 additions and 386 deletions.
16 changes: 8 additions & 8 deletions examples/basic-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

$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', [10, 100]);
->addRule($form::Integer, 'Age must be numeric value')
->addRule($form::Range, 'Age must be in range from %d to %d', [10, 100]);

$form->addRadioList('gender', 'Your gender:', [
'm' => 'male',
Expand All @@ -53,7 +53,7 @@
->setOption('embedNext', true);

$form->addCheckbox('send', 'Ship to address')
->addCondition($form::FILLED) // conditional rule: if is checkbox checked...
->addCondition($form::Filled) // conditional rule: if is checkbox checked...
->toggle('sendBox'); // toggle div #sendBox


Expand All @@ -64,7 +64,7 @@
$form->addText('street', 'Street:');

$form->addText('city', 'City:')
->addConditionOn($form['send'], $form::FILLED)
->addConditionOn($form['send'], $form::Filled)
->setRequired('Enter your shipping address');

$countries = [
Expand All @@ -77,7 +77,7 @@
];
$form->addSelect('country', 'Country:', $countries)
->setPrompt('Select your country')
->addConditionOn($form['send'], $form::FILLED)
->addConditionOn($form['send'], $form::Filled)
->setRequired('Select your country');


Expand All @@ -86,14 +86,14 @@

$form->addPassword('password', 'Choose password:')
->setRequired('Choose your password')
->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
->addRule($form::MinLength, 'The password is too short: it must be at least %d characters', 3);

$form->addPassword('password2', 'Reenter password:')
->setRequired('Reenter your password')
->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
->addRule($form::Equal, 'Passwords do not match', $form['password']);

$form->addUpload('avatar', 'Picture:')
->addRule($form::IMAGE, 'Uploaded file is not image');
->addRule($form::Image, 'Uploaded file is not image');

$form->addHidden('userid');

Expand Down
6 changes: 3 additions & 3 deletions examples/custom-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function isFilled(): bool

public function loadHttpData(): void
{
$this->day = $this->getHttpData(Form::DATA_LINE, '[day]');
$this->month = $this->getHttpData(Form::DATA_LINE, '[month]');
$this->year = $this->getHttpData(Form::DATA_LINE, '[year]');
$this->day = $this->getHttpData(Form::DataLine, '[day]');
$this->month = $this->getHttpData(Form::DataLine, '[month]');
$this->year = $this->getHttpData(Form::DataLine, '[year]');
}


Expand Down
8 changes: 4 additions & 4 deletions examples/html5.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
$form->addText('count', 'Number of results:')
->setHtmlType('number')
->setDefaultValue(10)
->addRule($form::INTEGER, 'Must be numeric value')
->addRule($form::RANGE, 'Must be in range from %d to %d', [1, 100]);
->addRule($form::Integer, 'Must be numeric value')
->addRule($form::Range, 'Must be in range from %d to %d', [1, 100]);

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

$form->addEmail('email', 'Send to email:')
->setHtmlAttribute('autocomplete', 'off')
Expand Down
4 changes: 2 additions & 2 deletions examples/latte.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

$form->addPassword('password', 'Choose password:')
->setRequired('Choose your password')
->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
->addRule($form::MinLength, 'The password is too short: it must be at least %d characters', 3);

$form->addPassword('password2', 'Reenter password:')
->setRequired('Reenter your password')
->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
->addRule($form::Equal, 'Passwords do not match', $form['password']);

$form->addSubmit('submit', 'Send');

Expand Down
8 changes: 4 additions & 4 deletions examples/live-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

$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', [10, 100]);
->addRule($form::Integer, 'Age must be numeric value')
->addRule($form::Range, 'Age must be in range from %d to %d', [10, 100]);

$form->addPassword('password', 'Choose password:')
->setRequired('Choose your password')
->addRule($form::MIN_LENGTH, 'The password is too short: it must be at least %d characters', 3);
->addRule($form::MinLength, 'The password is too short: it must be at least %d characters', 3);

$form->addPassword('password2', 'Reenter password:')
->setRequired('Reenter your password')
->addRule($form::EQUAL, 'Passwords do not match', $form['password']);
->addRule($form::Equal, 'Passwords do not match', $form['password']);

$form->addSubmit('submit', 'Send');

Expand Down
4 changes: 2 additions & 2 deletions examples/localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function translate($message, ...$parameters): string

$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', [10, 100]);
->addRule($form::Integer, 'Age must be numeric value')
->addRule($form::Range, 'Age must be in range from %d to %d', [10, 100]);

$countries = [
'World' => [
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function addTextArea(string $name, $label = null, ?int $cols = null, ?int
public function addEmail(string $name, $label = null): Controls\TextInput
{
return $this[$name] = (new Controls\TextInput($label))
->addRule(Form::EMAIL);
->addRule(Form::Email);
}


Expand All @@ -378,7 +378,7 @@ public function addInteger(string $name, $label = null): Controls\TextInput
{
return $this[$name] = (new Controls\TextInput($label))
->setNullable()
->addRule(Form::INTEGER);
->addRule(Form::Integer);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/BaseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getForm(bool $throw = true): ?Form
*/
public function loadHttpData(): void
{
$this->setValue($this->getHttpData(Form::DATA_TEXT));
$this->setValue($this->getHttpData(Form::DataText));
}


Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Controls/CheckboxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function __construct($label = null, ?array $items = null)

public function loadHttpData(): void
{
$data = $this->getForm()->getHttpData(Nette\Forms\Form::DATA_TEXT, substr($this->getHtmlName(), 0, -2));
$data = $this->getForm()->getHttpData(Nette\Forms\Form::DataText, substr($this->getHtmlName(), 0, -2));
$data = $data === null
? $this->getHttpData(Nette\Forms\Form::DATA_TEXT)
? $this->getHttpData(Nette\Forms\Form::DataText)
: explode(',', $data);
$this->value = array_keys(array_flip($data));
if (is_array($this->disabled)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/ChoiceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($label = null, ?array $items = null)

public function loadHttpData(): void
{
$this->value = $this->getHttpData(Nette\Forms\Form::DATA_TEXT);
$this->value = $this->getHttpData(Nette\Forms\Form::DataText);
if ($this->value !== null) {
$this->value = is_array($this->disabled) && isset($this->disabled[$this->value])
? null
Expand Down
7 changes: 4 additions & 3 deletions src/Forms/Controls/CsrfProtection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
class CsrfProtection extends HiddenField
{
public const PROTECTION = 'Nette\Forms\Controls\CsrfProtection::validateCsrf';
public const Protection = 'Nette\Forms\Controls\CsrfProtection::validateCsrf';
public const PROTECTION = self::Protection;

/** @var Nette\Http\Session|null */
public $session;
Expand All @@ -32,7 +33,7 @@ public function __construct($errorMessage)
parent::__construct();
$this->setOmitted()
->setRequired()
->addRule(self::PROTECTION, $errorMessage);
->addRule(self::Protection, $errorMessage);

$this->monitor(Presenter::class, function (Presenter $presenter): void {
if (!$this->session) {
Expand Down Expand Up @@ -62,7 +63,7 @@ public function setValue($value)

public function loadHttpData(): void
{
$this->value = $this->getHttpData(Nette\Forms\Form::DATA_TEXT);
$this->value = $this->getHttpData(Nette\Forms\Form::DataText);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/MultiChoiceControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($label = null, ?array $items = null)

public function loadHttpData(): void
{
$this->value = array_keys(array_flip($this->getHttpData(Nette\Forms\Form::DATA_TEXT)));
$this->value = array_keys(array_flip($this->getHttpData(Nette\Forms\Form::DataText)));
if (is_array($this->disabled)) {
$this->value = array_diff($this->value, array_keys($this->disabled));
}
Expand Down
5 changes: 3 additions & 2 deletions src/Forms/Controls/SelectBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class SelectBox extends ChoiceControl
{
/** validation rule */
public const VALID = ':selectBoxValid';
public const Valid = ':selectBoxValid';
public const VALID = self::Valid;

/** @var array of option / optgroup */
private $options = [];
Expand All @@ -38,7 +39,7 @@ public function __construct($label = null, ?array $items = null)
return $this->prompt === false
&& $this->options
&& $this->control->size < 2;
})->addRule(Nette\Forms\Form::FILLED, Nette\Forms\Validator::$messages[self::VALID]);
})->addRule(Nette\Forms\Form::Filled, Nette\Forms\Validator::$messages[self::Valid]);
}


Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Controls/TextBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function addRule($validator, $errorMessage = null, $arg = null)
}
}

if ($validator === Form::LENGTH || $validator === Form::MAX_LENGTH) {
if ($validator === Form::Length || $validator === Form::MaxLength) {
$tmp = is_array($arg) ? $arg[1] : $arg;
if (is_scalar($tmp)) {
$this->control->maxlength = isset($this->control->maxlength)
Expand Down
14 changes: 7 additions & 7 deletions src/Forms/Controls/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct($label = null, ?int $maxLength = null)

public function loadHttpData(): void
{
$this->setValue($this->getHttpData(Form::DATA_LINE));
$this->setValue($this->getHttpData(Form::DataLine));
}


Expand Down Expand Up @@ -74,17 +74,17 @@ public function addRule($validator, $errorMessage = null, $arg = null)
}
}

if ($this->control->type === null && in_array($validator, [Form::EMAIL, Form::URL, Form::INTEGER], true)) {
$types = [Form::EMAIL => 'email', Form::URL => 'url', Form::INTEGER => 'number'];
if ($this->control->type === null && in_array($validator, [Form::Email, Form::URL, Form::Integer], true)) {
$types = [Form::Email => 'email', Form::URL => 'url', Form::Integer => 'number'];
$this->control->type = $types[$validator];

} elseif (
in_array($validator, [Form::MIN, Form::MAX, Form::RANGE], true)
in_array($validator, [Form::Min, Form::Max, Form::Range], true)
&& in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], true)
) {
if ($validator === Form::MIN) {
if ($validator === Form::Min) {
$range = [$arg, null];
} elseif ($validator === Form::MAX) {
} elseif ($validator === Form::Max) {
$range = [null, $arg];
} else {
$range = $arg;
Expand All @@ -103,7 +103,7 @@ public function addRule($validator, $errorMessage = null, $arg = null)
}

} elseif (
$validator === Form::PATTERN
$validator === Form::Pattern
&& is_scalar($arg)
&& in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], true)
) {
Expand Down
15 changes: 8 additions & 7 deletions src/Forms/Controls/UploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
class UploadControl extends BaseControl
{
/** validation rule */
public const VALID = ':uploadControlValid';
public const Valid = ':uploadControlValid';
public const VALID = self::Valid;


/**
Expand All @@ -34,8 +35,8 @@ public function __construct($label = null, bool $multiple = false)
$this->control->multiple = $multiple;
$this->setOption('type', 'file');
$this->addCondition(true) // not to block the export of rules to JS
->addRule([$this, 'isOk'], Forms\Validator::$messages[self::VALID]);
$this->addRule(Form::MAX_FILE_SIZE, null, Forms\Helpers::iniGetSize('upload_max_filesize'));
->addRule([$this, 'isOk'], Forms\Validator::$messages[self::Valid]);
$this->addRule(Form::MaxFileSize, null, Forms\Helpers::iniGetSize('upload_max_filesize'));

$this->monitor(Form::class, function (Form $form): void {
if (!$form->isMethod('post')) {
Expand All @@ -49,7 +50,7 @@ public function __construct($label = null, bool $multiple = false)

public function loadHttpData(): void
{
$this->value = $this->getHttpData(Form::DATA_FILE);
$this->value = $this->getHttpData(Form::DataFile);
if ($this->value === null) {
$this->value = new FileUpload(null);
}
Expand Down Expand Up @@ -99,11 +100,11 @@ public function isOk(): bool
/** @return static */
public function addRule($validator, $errorMessage = null, $arg = null)
{
if ($validator === Form::IMAGE) {
if ($validator === Form::Image) {
$this->control->accept = implode(', ', FileUpload::IMAGE_MIME_TYPES);
} elseif ($validator === Form::MIME_TYPE) {
} elseif ($validator === Form::MimeType) {
$this->control->accept = implode(', ', (array) $arg);
} elseif ($validator === Form::MAX_FILE_SIZE) {
} elseif ($validator === Form::MaxFileSize) {
if ($arg > Forms\Helpers::iniGetSize('upload_max_filesize')) {
$ini = ini_get('upload_max_filesize');
trigger_error("Value of MAX_FILE_SIZE ($arg) is greater than value of directive upload_max_filesize ($ini).", E_USER_WARNING);
Expand Down
Loading

0 comments on commit 94ecd90

Please sign in to comment.