本文整理汇总了PHP中Cake\ORM\Query::traverseExpressions方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::traverseExpressions方法的具体用法?PHP Query::traverseExpressions怎么用?PHP Query::traverseExpressions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Query
的用法示例。
在下文中一共展示了Query::traverseExpressions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeFind
/**
* @param \Cake\Event\Event $event
* @param \Cake\ORM\Query $query
* @param \ArrayObject $options
* @param bool $primary
* @return void
*/
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
if (!$primary && !$this->_config['recursive']) {
return;
}
$field = $this->_config['field'];
if (!$field) {
return;
}
$query->find('hashed');
$idField = $this->_primaryKey;
if ($primary && $field === $idField) {
$query->traverseExpressions(function ($expression) {
if (method_exists($expression, 'getField') && ($expression->getField() === $this->_primaryKey || $expression->getField() === $this->_table->alias() . '.' . $this->_primaryKey)) {
$expression->setValue($this->decodeHashid($expression->getValue()));
}
return $expression;
});
}
if (!$this->_config['recursive']) {
return;
}
foreach ($this->_table->associations() as $association) {
if ($association->target()->hasBehavior('Hashid') && $association->finder() === 'all') {
$association->finder('hashed');
}
}
}
示例2: beforeFind
/**
* Callback to set the `obfuscated` finder on all associations.
*
* @param \Cake\ORM\Behavior\Event $event Event.
* @param \Cake\ORM\Query $query Query.
* @param \ArrayObject $options Options.
* @param bool $primary True if this is the primary table.
* @return void
*/
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
if (empty($options['obfuscate']) || !$primary) {
return;
}
$query->traverseExpressions(function ($expression) {
$pk = $this->_table->primaryKey();
if (method_exists($expression, 'getField') && in_array($expression->getField(), [$pk, $this->_table->aliasField($pk)])) {
$expression->setValue($this->elucidate($expression->getValue()));
}
return $expression;
});
foreach ($this->_table->associations() as $association) {
if ($association->target()->hasBehavior('Obfuscate') && 'all' === $association->finder()) {
$association->finder('obfuscate');
}
}
}
示例3: beforeFind
/**
* Auto-detects find operations performed using the primary key and increments the
* associated view counter(s).
*
* @param \Cake\Event\Event $event
* @param \Cake\ORM\Query $query
* @param \ArrayObject $options
* @param $primary
*/
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
if (!$primary) {
return;
}
$query->traverseExpressions(function ($expression) use($query, $options) {
$primaryKey = $this->_table->primaryKey();
$allowedFields = [$primaryKey, $this->_table->aliasField($primaryKey)];
if (!method_exists($expression, 'getField') || !in_array($expression->getField(), $allowedFields)) {
return $expression;
}
foreach ($this->config('counters') as $counter => $config) {
$args = [$query, $options, $counter];
if (!empty($config['callback']) && is_callable($config['callback']) && !call_user_func_array($config['callback'], $args)) {
continue;
}
$config['strategy']->increment($this->_table, $counter, $expression->getValue());
}
});
}
示例4: beforeFind
/**
* Callback to always return rows that have not been `trashed`.
*
* @param \Cake\Event\Event $event Event.
* @param \Cake\ORM\Query $query Query.
* @param \ArrayObject $options Options.
* @param bool $primary Primary or associated table being queries.
* @return void
*/
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
$field = $this->getTrashField();
$check = false;
$query->traverseExpressions(function ($expression) use(&$check, $field) {
if ($expression instanceof IdentifierExpression) {
!$check && ($check = $expression->getIdentifier() === $field);
}
});
if ($check) {
return;
}
$query->andWhere($query->newExpr()->isNull($field));
}