/** * Given a query instance applies the provided token representing a search * operator. * * @param \Cake\ORM\Query $query The query to be scope * @param \Search\TokenInterface $token Token describing an operator. e.g * `-op_name:op_value` * @return \Cake\ORM\Query Scoped query */ public function applySearchOperator(Query $query, TokenInterface $token) { if (!$token->isOperator()) { return $query; } $callable = $this->_operatorCallable($token->name()); if (is_callable($callable)) { $query = $callable($query, $token); if (!$query instanceof Query) { throw new FatalErrorException(__d('search', 'Error while processing the "{0}" token in the search criteria.', $operator)); } } else { $result = $this->_triggerOperator($query, $token); if ($result instanceof Query) { $query = $result; } } return $query; }