_field = $field; $this->_direction = strtolower($direction) === 'asc' ? 'ASC' : 'DESC'; } /** * @inheritDoc */ public function sql(ValueBinder $binder): string { /** @var \Cake\Database\ExpressionInterface|string $field */ $field = $this->_field; if ($field instanceof Query) { $field = sprintf('(%s)', $field->sql($binder)); } elseif ($field instanceof ExpressionInterface) { $field = $field->sql($binder); } return sprintf('%s %s', $field, $this->_direction); } /** * @inheritDoc */ public function traverse(Closure $callback) { if ($this->_field instanceof ExpressionInterface) { $callback($this->_field); $this->_field->traverse($callback); } return $this; } /** * Create a deep clone of the order clause. * * @return void */ public function __clone() { if ($this->_field instanceof ExpressionInterface) { $this->_field = clone $this->_field; } } }