|
|
@@ -1636,18 +1636,6 @@ class Table implements RepositoryInterface, EventListenerInterface {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns a new instance of an EntityValidator that is configured to be used
|
|
|
- * for entities generated by this table. An EntityValidator can be used to
|
|
|
- * process validation rules on a single or multiple entities and any of its
|
|
|
- * associated values.
|
|
|
- *
|
|
|
- * @return EntityValidator
|
|
|
- */
|
|
|
- public function entityValidator() {
|
|
|
- return new EntityValidator($this);
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
* {@inheritDoc}
|
|
|
*
|
|
|
* By default all the associations on this table will be hydrated. You can
|
|
|
@@ -1782,108 +1770,6 @@ class Table implements RepositoryInterface, EventListenerInterface {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Validates a single entity based on the passed options and validates
|
|
|
- * any nested entity for this table associations as requested in the
|
|
|
- * options array.
|
|
|
- *
|
|
|
- * Calling this function directly is mostly useful when you need to get
|
|
|
- * validation errors for an entity and associated nested entities before
|
|
|
- * they are saved.
|
|
|
- *
|
|
|
- * {{{
|
|
|
- * $articles->validate($article);
|
|
|
- * }}}
|
|
|
- *
|
|
|
- * You can specify which validation set to use using the options array:
|
|
|
- *
|
|
|
- * {{{
|
|
|
- * $users->validate($user, ['validate' => 'forSignup']);
|
|
|
- * }}}
|
|
|
- *
|
|
|
- * By default all the associations on this table will be validated if they can
|
|
|
- * be found in the passed entity. You can limit which associations are built,
|
|
|
- * or include deeper associations using the options parameter
|
|
|
- *
|
|
|
- * {{{
|
|
|
- * $articles->validate($article, [
|
|
|
- * 'associated' => [
|
|
|
- * 'Tags',
|
|
|
- * 'Comments' => [
|
|
|
- * 'validate' => 'myCustomSet',
|
|
|
- * 'associated' => ['Users']
|
|
|
- * ]
|
|
|
- * ]
|
|
|
- * ]);
|
|
|
- * }}}
|
|
|
- *
|
|
|
- * @param \Cake\Datasource\EntityInterface $entity The entity to be validated
|
|
|
- * @param array|\ArrayObject $options A list of options to use while validating, the following
|
|
|
- * keys are accepted:
|
|
|
- * - validate: The name of the validation set to use
|
|
|
- * - associated: map of association names to validate as well
|
|
|
- * @return bool true if the passed entity and its associations are valid
|
|
|
- */
|
|
|
- public function validate($entity, $options = []) {
|
|
|
- if (!isset($options['associated'])) {
|
|
|
- $options['associated'] = $this->_associations->keys();
|
|
|
- }
|
|
|
-
|
|
|
- $entityValidator = $this->entityValidator();
|
|
|
- return $entityValidator->one($entity, $options);
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * Validates a list of entities based on the passed options and validates
|
|
|
- * any nested entity for this table associations as requested in the
|
|
|
- * options array.
|
|
|
- *
|
|
|
- * Calling this function directly is mostly useful when you need to get
|
|
|
- * validation errors for a list of entities and associations before they are
|
|
|
- * saved.
|
|
|
- *
|
|
|
- * {{{
|
|
|
- * $articles->validateMany([$article1, $article2]);
|
|
|
- * }}}
|
|
|
- *
|
|
|
- * You can specify which validation set to use using the options array:
|
|
|
- *
|
|
|
- * {{{
|
|
|
- * $users->validateMany([$user1, $user2], ['validate' => 'forSignup']);
|
|
|
- * }}}
|
|
|
- *
|
|
|
- * By default all the associations on this table will be validated if they can
|
|
|
- * be found in the passed entities. You can limit which associations are built,
|
|
|
- * or include deeper associations using the options parameter
|
|
|
- *
|
|
|
- * {{{
|
|
|
- * $articles->validateMany([$article1, $article2], [
|
|
|
- * 'associated' => [
|
|
|
- * 'Tags',
|
|
|
- * 'Comments' => [
|
|
|
- * 'validate' => 'myCustomSet',
|
|
|
- * 'associated' => ['Users']
|
|
|
- * ]
|
|
|
- * ]
|
|
|
- * ]);
|
|
|
- * }}}
|
|
|
- *
|
|
|
- * @param array|\ArrayAccess $entities The entities to be validated
|
|
|
- * @param array $options A list of options to use while validating, the following
|
|
|
- * keys are accepted:
|
|
|
- * - validate: The name of the validation set to use
|
|
|
- * - associated: map of association names to validate as well
|
|
|
- * @return bool true if the passed entities and their associations are valid
|
|
|
- */
|
|
|
- public function validateMany($entities, array $options = []) {
|
|
|
- if (!isset($options['associated'])) {
|
|
|
- $options['associated'] = $this->_associations->keys();
|
|
|
- }
|
|
|
-
|
|
|
- $entityValidator = $this->entityValidator();
|
|
|
- return $entityValidator->many($entities, $options);
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
* Validator method used to check the uniqueness of a value for a column.
|
|
|
* This is meant to be used with the validation API and not to be called
|
|
|
* directly.
|