Skip to content

Commit

Permalink
phalcon#14203 - Changed Phalcon\Forms\Form::isValid() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Aziz Muzafarov committed Nov 2, 2021
1 parent 4b13e09 commit 6231f27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@
- Renamed `Phalcon\Db\Adapter\AbstractAdapter::getSqlVariables()` to `Phalcon\Db\Adapter\AbstractAdapter::getSQLVariables()` to align with the rest of the `getSQL*` methods [#15637](https://github.com/phalcon/cphalcon/issues/15637)
- Moved `Phalcon\Logger` to `Phalcon\Logger\Logger` [#15727](https://github.com/phalcon/cphalcon/issues/15727)
- Changed `Phalcon\Validation::getValue()` behavior to get value from `data` if not found in `entity`. [#14203](https://github.com/phalcon/cphalcon/issues/14203)
- Changed `Phalcon\Forms\Form::isValid()` signature: added `whitelist` argument. [#14203](https://github.com/phalcon/cphalcon/issues/14203)

## Added
- Added more tests in the suite for additional code coverage [#15691](https://github.com/phalcon/cphalcon/issues/15691)
- Added `Phalcon\Events\AbstractEventsAware` class to handle the Events Manager when necessary [#15691](https://github.com/phalcon/cphalcon/issues/15691)
- Added `Phalcon\Acl\Adapter\AdapterInterface::getInheritedRoles()` and `Phalcon\Acl\Adapter\Memory::getInheritedRoles()` that returns the inherited roles based on a passed role name (or all if no parameter supplied) [#15154](https://github.com/phalcon/cphalcon/issues/15154)
- Added `Phalcon\Forms\Form::setWhitelist()` and `Phalcon\Forms\Form::getWhitelist()` [#14203](https://github.com/phalcon/cphalcon/issues/14203)

## Fixed
- Fixed `Query::getExpression()` return type [#15553](https://github.com/phalcon/cphalcon/issues/15553)
Expand Down
41 changes: 38 additions & 3 deletions phalcon/Forms/Form.zep
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
*/
protected validation = null { set, get };

/**
* @var array
*/
protected whitelist = [];

/**
* Phalcon\Forms\Form constructor
*/
Expand Down Expand Up @@ -175,6 +180,10 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
throw new Exception("There are no elements in the form");
}

if empty whitelist && !empty this->whitelist {
let whitelist = this->whitelist;
}

let filter = null;
let assignData = [];

Expand Down Expand Up @@ -362,6 +371,16 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
return this->entity;
}

/**
* Returns whitelist array
*
* @return array
*/
public function getWhitelist() -> array
{
return this->whitelist;
}

/**
* Returns a label for an element
*/
Expand Down Expand Up @@ -566,7 +585,7 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
* @param array data
* @param object entity
*/
public function isValid(var data = null, var entity = null) -> bool
public function isValid(var data = null, var entity = null, var whitelist = null) -> bool
{
var messages, element, validators, name, filters, validator, validation,
elementMessage;
Expand All @@ -576,6 +595,10 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
return true;
}

if empty whitelist && !empty this->whitelist {
let whitelist = this->whitelist;
}

/**
* If the data is not an array use the one passed previously
*/
Expand All @@ -587,10 +610,10 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
* If the user doesn't pass an entity we use the one in this_ptr->entity
*/
if typeof entity == "object" {
this->bind(data, entity);
this->bind(data, entity, whitelist);
} else {
if typeof this->entity == "object" {
this->bind(data, this->entity);
this->bind(data, this->entity, whitelist);
let entity = this->entity;
}
}
Expand Down Expand Up @@ -784,6 +807,18 @@ class Form extends Injectable implements Countable, Iterator, AttributesInterfac
return this;
}

/**
* Sets the default whitelist
*
* @param object entity
*/
public function setWhitelist(array whitelist) -> <Form>
{
let this->whitelist = whitelist;

return this;
}

/**
* Set form attributes collection
*/
Expand Down

0 comments on commit 6231f27

Please sign in to comment.