Skip to content

Commit

Permalink
[system] fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Daria Prusova committed Jul 30, 2014
1 parent 60aa068 commit 42d692b
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library/form/adapter/ArrayFormAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getData(IFormElement $element)
/**
* {@inheritdoc}
*/
public function validate(IFormElement $element)
public function validate(IFormElement $element, $value)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion library/form/adapter/ConfigFormAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getData(IFormElement $element)
/**
* {@inheritdoc}
*/
public function validate(IFormElement $element)
public function validate(IFormElement $element, $value)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion library/form/adapter/DefaultFormAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getData(IFormElement $element)
/**
* {@inheritdoc}
*/
public function validate(IFormElement $element)
public function validate(IFormElement $element, $value)
{
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion library/form/adapter/IDataAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public function getData(IFormElement $element);
/**
* Валидирует значение провайдера данных.
* @param IFormElement $element элемент формы, для которого формируется значение
* @param mixed $value значение
* @return bool
*/
public function validate(IFormElement $element);
public function validate(IFormElement $element, $value);

/**
* Возвращает ошибки валидации провайдера данных.
Expand Down
4 changes: 2 additions & 2 deletions library/form/adapter/ObjectFormAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public function getData(IFormElement $element)
/**
* {@inheritdoc}
*/
public function validate(IFormElement $element)
public function validate(IFormElement $element, $value)
{
if ($dataSource = $element->getDataSource()) {
return $this->data->getPropertyByPath($dataSource)->validate();
return $this->data->getPropertyByPath($dataSource)->validate($value);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion library/form/element/BaseFormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function validate($value)
{
$isValid =
$this->getValidators()->isValid($value) &&
$this->getDataAdapter()->validate($this);
$this->getDataAdapter()->validate($this, $value);

$this->messages = array_merge(
$this->getValidators()->getMessages(),
Expand Down
2 changes: 1 addition & 1 deletion library/orm/object/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public function validate()
$result = true;

foreach ($this->getAllProperties() as $property) {
if (!$property->validate()) {
if (!$property->validate($property->getValue())) {
$this->validationErrors[$property->getFullName()] = $property->getValidationErrors();
$result = false;
}
Expand Down
5 changes: 3 additions & 2 deletions library/orm/object/property/IProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ public function getLocaleId();
public function rollback();

/**
* Производит валидацию
* Производит валидацию.
* @param mixed $value значение
* @return bool результат валидации
*/
public function validate();
public function validate($value);

/**
* Возвращает список ошибок валидации
Expand Down
4 changes: 2 additions & 2 deletions library/orm/object/property/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public function update($value)
/**
* {@inheritdoc}
*/
public function validate()
public function validate($value)
{
$result = true;
$this->validationErrors = [];
Expand All @@ -350,7 +350,7 @@ public function validate()
if ($validators = $this->getField()->getValidatorsConfig($this->getLocaleId())) {

$validatorCollection = $this->createValidatorCollection($validators);
if (!$validatorCollection->isValid($this->getValue())) {
if (!$validatorCollection->isValid($value)) {
$this->addValidationErrors($validatorCollection->getMessages());
$result = false;
}
Expand Down
11 changes: 10 additions & 1 deletion tests/utest/orm/func/object/ValidatorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ protected function getCollectionConfig()
self::USERS_USER => [
'type' => ICollectionFactory::TYPE_SIMPLE
],
self::USERS_PROFILE => [
'type' => ICollectionFactory::TYPE_SIMPLE
],
self::USERS_GROUP => [
'type' => ICollectionFactory::TYPE_SIMPLE
]
],
self::BLOGS_BLOG => [
'type' => ICollectionFactory::TYPE_SIMPLE_HIERARCHIC,
],
self::BLOGS_SUBSCRIBER => [
'type' => ICollectionFactory::TYPE_SIMPLE
],
],
true
];
Expand Down

0 comments on commit 42d692b

Please sign in to comment.