Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
[zendframework#3200] Update components to use new validator chain met…
Browse files Browse the repository at this point in the history
…hods

- s/addValidator/attach/
- s/addByName/attachByName/
  • Loading branch information
weierophinney committed Dec 11, 2012
1 parent 5618743 commit a1d8d95
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions library/Zend/InputFilter/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected function populateValidators(ValidatorChain $chain, $validators)
{
foreach ($validators as $validator) {
if ($validator instanceof ValidatorInterface) {
$chain->addValidator($validator);
$chain->attach($validator);
continue;
}

Expand All @@ -306,7 +306,7 @@ protected function populateValidators(ValidatorChain $chain, $validators)
if (isset($validator['break_chain_on_failure'])) {
$breakChainOnFailure = $validator['break_chain_on_failure'];
}
$chain->addByName($name, $options, $breakChainOnFailure);
$chain->attachByName($name, $options, $breakChainOnFailure);
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Mail/Protocol/AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ abstract class AbstractProtocol
public function __construct($host = '127.0.0.1', $port = null)
{
$this->validHost = new Validator\ValidatorChain();
$this->validHost->addValidator(new Validator\Hostname(Validator\Hostname::ALLOW_ALL));
$this->validHost->attach(new Validator\Hostname(Validator\Hostname::ALLOW_ALL));

if (!$this->validHost->isValid($host)) {
throw new Exception\RuntimeException(implode(', ', $this->validHost->getMessages()));
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Mvc/Router/Console/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function __construct(
} elseif ($validators instanceof Traversable || is_array($validators)) {
$this->validators = new ValidatorChain();
foreach ($validators as $v) {
$this->validators->addValidator($v);
$this->validators->attach($v);
}
} else {
throw new InvalidArgumentException('Cannot use ' . gettype($validators) . ' as validators for ' . __CLASS__);
Expand Down
34 changes: 17 additions & 17 deletions tests/ZendTest/InputFilter/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ public function getInputFilter()
$foo = new Input();
$foo->getFilterChain()->attachByName('stringtrim')
->attachByName('alpha');
$foo->getValidatorChain()->addValidator(new Validator\StringLength(3, 6));
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 6));

$bar = new Input();
$bar->getFilterChain()->attachByName('stringtrim');
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());

$baz = new Input();
$baz->setRequired(false);
$baz->getFilterChain()->attachByName('stringtrim');
$baz->getValidatorChain()->addValidator(new Validator\StringLength(1, 6));
$baz->getValidatorChain()->attach(new Validator\StringLength(1, 6));

$filter->add($foo, 'foo')
->add($bar, 'bar')
Expand All @@ -100,16 +100,16 @@ public function getChildInputFilter()
$foo = new Input();
$foo->getFilterChain()->attachByName('stringtrim')
->attachByName('alpha');
$foo->getValidatorChain()->addValidator(new Validator\StringLength(3, 6));
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 6));

$bar = new Input();
$bar->getFilterChain()->attachByName('stringtrim');
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());

$baz = new Input();
$baz->setRequired(false);
$baz->getFilterChain()->attachByName('stringtrim');
$baz->getValidatorChain()->addValidator(new Validator\StringLength(1, 6));
$baz->getValidatorChain()->attach(new Validator\StringLength(1, 6));

$filter->add($foo, 'foo')
->add($bar, 'bar')
Expand Down Expand Up @@ -343,14 +343,14 @@ public function testValidationCanUseContext()

$store = new stdClass;
$foo = new Input();
$foo->getValidatorChain()->addValidator(new Validator\Callback(function ($value, $context) use ($store) {
$foo->getValidatorChain()->attach(new Validator\Callback(function ($value, $context) use ($store) {
$store->value = $value;
$store->context = $context;
return true;
}));

$bar = new Input();
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());

$filter->add($foo, 'foo')
->add($bar, 'bar');
Expand All @@ -373,14 +373,14 @@ public function testInputBreakOnFailureFlagIsHonoredWhenValidating()

$store = new stdClass;
$foo = new Input();
$foo->getValidatorChain()->addValidator(new Validator\Callback(function ($value, $context) use ($store) {
$foo->getValidatorChain()->attach(new Validator\Callback(function ($value, $context) use ($store) {
$store->value = $value;
$store->context = $context;
return true;
}));

$bar = new Input();
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());
$bar->setBreakOnFailure(true);

$filter->add($bar, 'bar') // adding bar first, as we want it to validate first and break the chain
Expand All @@ -399,11 +399,11 @@ public function testValidationSkipsFieldsMarkedNotRequiredWhenNoDataPresent()
$filter = new InputFilter();

$foo = new Input();
$foo->getValidatorChain()->addValidator(new Validator\StringLength(3, 5));
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 5));
$foo->setRequired(false);

$bar = new Input();
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());
$bar->setRequired(true);

$filter->add($foo, 'foo')
Expand All @@ -420,7 +420,7 @@ public function testValidationSkipsFileInputsMarkedNotRequiredWhenNoFileDataIsPr
$filter = new InputFilter();

$foo = new FileInput();
$foo->getValidatorChain()->addValidator(new Validator\File\Upload());
$foo->getValidatorChain()->attach(new Validator\File\Upload());
$foo->setRequired(false);

$filter->add($foo, 'foo');
Expand Down Expand Up @@ -473,12 +473,12 @@ public function testValidationAllowsEmptyValuesToRequiredInputWhenAllowEmptyFlag
$filter = new InputFilter();

$foo = new Input('foo');
$foo->getValidatorChain()->addValidator(new Validator\StringLength(3, 5));
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 5));
$foo->setRequired(true);
$foo->setAllowEmpty(true);

$bar = new Input();
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());
$bar->setRequired(true);

$filter->add($foo, '')
Expand All @@ -496,12 +496,12 @@ public function testValidationMarksInputInvalidWhenRequiredAndAllowEmptyFlagIsFa
$filter = new InputFilter();

$foo = new Input();
$foo->getValidatorChain()->addValidator(new Validator\StringLength(3, 5));
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 5));
$foo->setRequired(true);
$foo->setAllowEmpty(false);

$bar = new Input();
$bar->getValidatorChain()->addValidator(new Validator\Digits());
$bar->getValidatorChain()->attach(new Validator\Digits());
$bar->setRequired(true);

$filter->add($foo, '')
Expand Down
12 changes: 6 additions & 6 deletions tests/ZendTest/InputFilter/FileInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ public function testIsValidReturnsFalseIfValidationChainFails()
{
$this->input->setValue(array('tmp_name' => 'bar'));
$validator = new Validator\Digits();
$this->input->getValidatorChain()->addValidator($validator);
$this->input->getValidatorChain()->attach($validator);
$this->assertFalse($this->input->isValid());
}

public function testIsValidReturnsTrueIfValidationChainSucceeds()
{
$this->input->setValue(array('tmp_name' => 'bar'));
$validator = new Validator\NotEmpty();
$this->input->getValidatorChain()->addValidator($validator);
$this->input->getValidatorChain()->attach($validator);
$this->assertTrue($this->input->isValid());
}

Expand All @@ -162,7 +162,7 @@ public function testValidationOperatesBeforeFiltering()
$filter = new Filter\StringTrim();
$this->input->getFilterChain()->attach($filter);
$validator = new Validator\File\Exists();
$this->input->getValidatorChain()->addValidator($validator);
$this->input->getValidatorChain()->attach($validator);
$this->assertFalse($this->input->isValid());
$this->input->setValue(array(
'tmp_name' => __FILE__,
Expand Down Expand Up @@ -205,7 +205,7 @@ public function testCanValidateArrayOfMultiFileData()
);
$this->input->setValue($values);
$validator = new Validator\File\Exists();
$this->input->getValidatorChain()->addValidator($validator);
$this->input->getValidatorChain()->attach($validator);
$this->assertTrue($this->input->isValid());

// Negative test
Expand All @@ -218,7 +218,7 @@ public function testSpecifyingMessagesToInputReturnsThoseOnFailedValidation()
{
$this->input->setValue(array('tmp_name' => 'bar'));
$validator = new Validator\Digits();
$this->input->getValidatorChain()->addValidator($validator);
$this->input->getValidatorChain()->attach($validator);
$this->input->setErrorMessage('Please enter only digits');
$this->assertFalse($this->input->isValid());
$messages = $this->input->getMessages();
Expand Down Expand Up @@ -327,7 +327,7 @@ public function testMerge()
$filter = new Filter\StringTrim();
$input->getFilterChain()->attach($filter);
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);

$input2 = new FileInput('bar');
$input2->merge($input);
Expand Down
12 changes: 6 additions & 6 deletions tests/ZendTest/InputFilter/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testIsValidReturnsFalseIfValidationChainFails()
$input = new Input('foo');
$input->setValue('bar');
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);
$this->assertFalse($input->isValid());
}

Expand All @@ -126,7 +126,7 @@ public function testIsValidReturnsTrueIfValidationChainSucceeds()
$input = new Input('foo');
$input->setValue('123');
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);
$this->assertTrue($input->isValid());
}

Expand All @@ -137,7 +137,7 @@ public function testValidationOperatesOnFilteredValue()
$filter = new Filter\StringTrim();
$input->getFilterChain()->attach($filter);
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);
$this->assertTrue($input->isValid());
}

Expand All @@ -146,7 +146,7 @@ public function testGetMessagesReturnsValidationMessages()
$input = new Input('foo');
$input->setValue('bar');
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);
$this->assertFalse($input->isValid());
$messages = $input->getMessages();
$this->assertArrayHasKey(Validator\Digits::NOT_DIGITS, $messages);
Expand All @@ -157,7 +157,7 @@ public function testSpecifyingMessagesToInputReturnsThoseOnFailedValidation()
$input = new Input('foo');
$input->setValue('bar');
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);
$input->setErrorMessage('Please enter only digits');
$this->assertFalse($input->isValid());
$messages = $input->getMessages();
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testMerge()
$filter = new Filter\StringTrim();
$input->getFilterChain()->attach($filter);
$validator = new Validator\Digits();
$input->getValidatorChain()->addValidator($validator);
$input->getValidatorChain()->attach($validator);

$input2 = new Input('bar');
$input2->merge($input);
Expand Down
4 changes: 2 additions & 2 deletions tests/ZendTest/Log/Filter/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function testValidatorFilter()
public function testValidatorChain()
{
$validatorChain = new ValidatorChain();
$validatorChain->addValidator(new DigitsFilter());
$validatorChain->addValidator(new Int());
$validatorChain->attach(new DigitsFilter());
$validatorChain->attach(new Int());
$filter = new Validator($validatorChain);
$this->assertTrue($filter->filter(array('message' => '123')));
$this->assertFalse($filter->filter(array('message' => 'test')));
Expand Down

0 comments on commit a1d8d95

Please sign in to comment.