/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/LinkConstraint.php (6166B)
_association = $association; $this->_requiredLinkState = $requiredLinkStatus; } /** * Callable handler. * * Performs the actual link check. * * @param \Cake\Datasource\EntityInterface $entity The entity involved in the operation. * @param array $options Options passed from the rules checker. * @return bool Whether the check was successful. */ public function __invoke(EntityInterface $entity, array $options): bool { $table = $options['repository'] ?? null; if (!($table instanceof Table)) { throw new \InvalidArgumentException( 'Argument 2 is expected to have a `repository` key that holds an instance of `\Cake\ORM\Table`.' ); } $association = $this->_association; if (!$association instanceof Association) { $association = $table->getAssociation($association); } $count = $this->_countLinks($association, $entity); if ( ( $this->_requiredLinkState === static::STATUS_LINKED && $count < 1 ) || ( $this->_requiredLinkState === static::STATUS_NOT_LINKED && $count !== 0 ) ) { return false; } return true; } /** * Alias fields. * * @param array $fields The fields that should be aliased. * @param \Cake\ORM\Table $source The object to use for aliasing. * @return array The aliased fields */ protected function _aliasFields(array $fields, Table $source): array { foreach ($fields as $key => $value) { $fields[$key] = $source->aliasField($value); } return $fields; } /** * Build conditions. * * @param array $fields The condition fields. * @param array $values The condition values. * @return array A conditions array combined from the passed fields and values. */ protected function _buildConditions(array $fields, array $values): array { if (count($fields) !== count($values)) { throw new \InvalidArgumentException(sprintf( 'The number of fields is expected to match the number of values, got %d field(s) and %d value(s).', count($fields), count($values) )); } return array_combine($fields, $values); } /** * Count links. * * @param \Cake\ORM\Association $association The association for which to count links. * @param \Cake\Datasource\EntityInterface $entity The entity involved in the operation. * @return int The number of links. */ protected function _countLinks(Association $association, EntityInterface $entity): int { $source = $association->getSource(); $primaryKey = (array)$source->getPrimaryKey(); if (!$entity->has($primaryKey)) { throw new \RuntimeException(sprintf( 'LinkConstraint rule on `%s` requires all primary key values for building the counting ' . 'conditions, expected values for `(%s)`, got `(%s)`.', $source->getAlias(), implode(', ', $primaryKey), implode(', ', $entity->extract($primaryKey)) )); } $aliasedPrimaryKey = $this->_aliasFields($primaryKey, $source); $conditions = $this->_buildConditions( $aliasedPrimaryKey, $entity->extract($primaryKey) ); return $source ->find() ->matching($association->getName()) ->where($conditions) ->count(); } }