phprs\ezsql\impls\OrderByImpl::orderByArgs PHP Method

orderByArgs() public method

public orderByArgs ( $context, $orders )
    public function orderByArgs($context, $orders)
    {
        if (empty($orders)) {
            return $this;
        }
        $params = array();
        foreach ($orders as $k => $v) {
            if (is_integer($k)) {
                Verify::isTrue(preg_match('/^[a-zA-Z0-9_.]+$/', $v), new \InvalidArgumentException("invalid params for orderBy(" . json_encode($orders) . ")"));
                $params[] = $v;
            } else {
                $v = strtoupper($v);
                Verify::isTrue(preg_match('/^[a-zA-Z0-9_.]+$/', $k) && ($v == 'DESC' || $v == 'ASC'), new \InvalidArgumentException("invalid params for orderBy(" . json_encode($orders) . ")"));
                $params[] = "{$k} {$v}";
            }
        }
        if ($this->first) {
            $this->first = false;
            $context->appendSql('ORDER BY ' . implode(',', $params));
        } else {
            $context->appendSql(',' . implode(',', $params), false);
        }
        return $this;
    }