当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::traverseExpressions方法代码示例

本文整理汇总了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');
         }
     }
 }
开发者ID:dereuromark,项目名称:cakephp-hashid,代码行数:35,代码来源:HashidBehavior.php

示例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');
         }
     }
 }
开发者ID:UseMuffin,项目名称:Obfuscate,代码行数:27,代码来源:ObfuscateBehavior.php

示例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());
         }
     });
 }
开发者ID:UseMuffin,项目名称:Hits,代码行数:29,代码来源:HitsBehavior.php

示例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));
 }
开发者ID:makamo,项目名称:Trash,代码行数:23,代码来源:TrashBehavior.php


注:本文中的Cake\ORM\Query::traverseExpressions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。