/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/ORM/Rule
NameSizeModeActions
ExistsIn.php55320644editdlrm
IsUnique.php25970644editdlrm
LinkConstraint.php61660644editdlrm
ValidCount.php16850644editdlrm
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/ORM/Rule/ExistsIn.php (5532B)
false]; $this->_options = $options; $this->_fields = (array)$fields; $this->_repository = $repository; } /** * Performs the existence check * * @param \Cake\Datasource\EntityInterface $entity The entity from where to extract the fields * @param array $options Options passed to the check, * where the `repository` key is required. * @throws \RuntimeException When the rule refers to an undefined association. * @return bool */ public function __invoke(EntityInterface $entity, array $options): bool { if (is_string($this->_repository)) { if (!$options['repository']->hasAssociation($this->_repository)) { throw new RuntimeException(sprintf( "ExistsIn rule for '%s' is invalid. '%s' is not associated with '%s'.", implode(', ', $this->_fields), $this->_repository, get_class($options['repository']) )); } $repository = $options['repository']->getAssociation($this->_repository); $this->_repository = $repository; } $fields = $this->_fields; $source = $target = $this->_repository; if ($target instanceof Association) { $bindingKey = (array)$target->getBindingKey(); $realTarget = $target->getTarget(); } else { $bindingKey = (array)$target->getPrimaryKey(); $realTarget = $target; } if (!empty($options['_sourceTable']) && $realTarget === $options['_sourceTable']) { return true; } if (!empty($options['repository'])) { $source = $options['repository']; } if ($source instanceof Association) { $source = $source->getSource(); } if (!$entity->extract($this->_fields, true)) { return true; } if ($this->_fieldsAreNull($entity, $source)) { return true; } if ($this->_options['allowNullableNulls']) { $schema = $source->getSchema(); foreach ($fields as $i => $field) { if ($schema->getColumn($field) && $schema->isNullable($field) && $entity->get($field) === null) { unset($bindingKey[$i], $fields[$i]); } } } $primary = array_map( function ($key) use ($target) { return $target->aliasField($key) . ' IS'; }, $bindingKey ); $conditions = array_combine( $primary, $entity->extract($fields) ); return $target->exists($conditions); } /** * Checks whether or not the given entity fields are nullable and null. * * @param \Cake\Datasource\EntityInterface $entity The entity to check. * @param \Cake\ORM\Table $source The table to use schema from. * @return bool */ protected function _fieldsAreNull(EntityInterface $entity, Table $source): bool { $nulls = 0; $schema = $source->getSchema(); foreach ($this->_fields as $field) { if ($schema->getColumn($field) && $schema->isNullable($field) && $entity->get($field) === null) { $nulls++; } } return $nulls === count($this->_fields); } }