Skip to content

Commit

Permalink
Adding doc blocks for EntityValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 23, 2013
1 parent 2e4fd8c commit ecfc21d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions Cake/ORM/EntityValidator.php
Expand Up @@ -14,21 +14,16 @@
*/
namespace Cake\ORM;

use Cake\ORM\Association;
use Cake\ORM\Table;

/**
* Contains logic to convert array data into entities.
*
* Useful when converting request data into entities.
* Contains logic for validate entities and their associations
*
* @see Cake\ORM\Table::newEntity()
* @see Cake\ORM\Table::newEntities()
* @see Cake\ORM\Table::validate()
* @see Cake\ORM\Table::validateMany()
*/
class EntityValidator {

/**
* The table instance this marshaller is for.
* The table instance this validator is for.
*
* @var Cake\ORM\Table
*/
Expand All @@ -45,6 +40,7 @@ class EntityValidator {
* Constructor.
*
* @param Cake\ORM\Table $table
* @param string $type The name of the validator to use as stored in the table
*/
public function __construct(Table $table, $type = 'default') {
$this->_table = $table;
Expand Down Expand Up @@ -78,7 +74,16 @@ protected function _buildPropertyMap($include) {
return $map;
}

public function one($entity, $include = []) {
/**
* Validates a single entity by getting the correct validator object from
* the table and traverses associations passed in $include to validate them
* as well.
*
* @param \Cake\ORM\Entity $entity The entity to be validated
* @param array $include tree of associations to be validated
* @return boolean true if all validations passed, false otherwise
*/
public function one(Entity $entity, $include = []) {
$propertyMap = $this->_buildPropertyMap($include);
$valid = true;

Expand Down Expand Up @@ -109,6 +114,14 @@ public function one($entity, $include = []) {
return $valid;
}

/**
* Validates a list of entities by getting the correct validator for the related
* table and traverses associations passed in $include to validate them as well.
*
* @param array $entities List of entitites to be validated
* @param array $include tree of associations to be validated
* @return boolean true if all validations passed, false otherwise
*/
public function many(array $entities, $include = []) {
$valid = true;
foreach ($entities as $entity) {
Expand Down
2 changes: 1 addition & 1 deletion Cake/Test/TestCase/ORM/EntityValidatorTest.php
Expand Up @@ -54,7 +54,7 @@ public function setUp() {
public function tearDown() {
parent::tearDown();
TableRegistry::clear();
unset($this->articles, $this->comments);
unset($this->articles, $this->comments, $this->users);
}

/**
Expand Down

0 comments on commit ecfc21d

Please sign in to comment.