public function orderBy($type = null)
    {
        if ($type === null) {
            $target = null;

        } elseif ($type instanceof RawSqlFragmentInterface) {
            $target = $type->getFragment();

        } elseif (is_array($type)) {
            // Special case for non-associative array
            if (!ArrayUtils::isAssoc($type)) {
                // Check if at least one value represents a raw fragment
                foreach ($type as &$option) {
                    // If raw, then do nothing but get it
                    if ($option instanceof RawSqlFragmentInterface) {
                        $option = $option->getFragment();
                    } else {
                        // Not raw - OK, then just quote it
                        $option = $this->quote($option);
                    }
                }
            } else {
                // If associative array supplied then assume that values represent sort orders
                $result = array();

                foreach ($type as $column => $sortOrder) {
                    // Force sorting method to be in upper case
                    $sortOrder = strtoupper($sortOrder);

                    // Ensure that only valid sorting methods provided
                    if (!in_array($sortOrder, array('ASC', 'DESC'))) {
                        throw new LogicException(sprintf(
                            'Only ASC and DESC methods are supported. You provided "%s"', $sortOrder
                        ));
                    }

                    // Only column names should be wrapped around backticks
                    array_push($result, sprintf('%s %s', $this->quote($column), $sortOrder));
                }

                $type = $result;
            }

            $target = implode(', ', $type);

        } else {
            $target = $this->quote($type);
        }

        $this->append(' ORDER BY '.$target);
        return $this;
    }
public function orderBy($type = null)
    {
        if ($type === null) {
            $target = null;

        } elseif ($type instanceof RawSqlFragmentInterface) {
            $target = $type->getFragment();

        } elseif (is_array($type)) {
            // Special case for non-associative array
            if (!ArrayUtils::isAssoc($type)) {
                // Check if at least one value represents a raw fragment
                foreach ($type as &$option) {
                    // If raw, then do nothing but get it
                    if ($option instanceof RawSqlFragmentInterface) {
                        $option = $option->getFragment();
                    } else {
                        // Not raw - OK, then just quote it
                        $option = $this->quote($option);
                    }
                }
            } else {
                // If associative array supplied then assume that values represent sort orders
                $result = array();

                foreach ($type as $column => $sortOrder) {
                    // Force sorting method to be in upper case
                    $sortOrder = strtoupper($sortOrder);

                    // Ensure that only valid sorting methods provided
                    if (!in_array($sortOrder, array('ASC', 'DESC'))) {
                        throw new LogicException(sprintf(
                            'Only ASC and DESC methods are supported. You provided "%s"', $sortOrder
                        ));
                    }

                    // Only column names should be wrapped around backticks
                    array_push($result, sprintf('%s %s', $this->quote($column), $sortOrder));
                }

                $type = $result;
            }

            $target = implode(', ', $type);

        } else {
            $target = $this->quote($type);
        }

        $this->append(' ORDER BY '.$target);
        return $this;
    }
public function orderBy ( $ type = null ) { if ( $ type === null ) { $ target = null ; } elseif ( $ type instanceof RawSqlFragmentInterface ) { $ target = $ type -> getFragment ( ) ; } elseif ( is_array ( $ type ) ) { // Special case for non-associative array if ( ! ArrayUtils :: isAssoc ( $ type ) ) { // Check if at least one value represents a raw fragment foreach ( $ type as & $ option ) { // If raw, then do nothing but get it if ( $ option instanceof RawSqlFragmentInterface ) { $ option = $ option -> getFragment ( ) ; } else { // Not raw - OK, then just quote it $ option = $ this -> quote ( $ option ) ; } } } else { // If associative array supplied then assume that values represent sort orders $ result = array ( ) ; foreach ( $ type as $ column => $ sortOrder ) { // Force sorting method to be in upper case $ sortOrder = strtoupper ( $ sortOrder ) ; // Ensure that only valid sorting methods provided if ( ! in_array ( $ sortOrder , array ( 'ASC' , 'DESC' ) ) ) { throw new LogicException ( sprintf ( 'Only ASC and DESC methods are supported. You provided "%s"' , $ sortOrder ) ) ; } // Only column names should be wrapped around backticks array_push ( $ result , sprintf ( '%s %s' , $ this -> quote ( $ column ) , $ sortOrder ) ) ; } $ type = $ result ; } $ target = implode ( ', ' , $ type ) ; } else { $ target = $ this -> quote ( $ type ) ; } $ this -> append ( ' ORDER BY ' . $ target ) ; return $ this ; }
Appends ORDER BY expression

@param string|array|\Krystal\Db\Sql\RawSqlFragmentInterface $type
@return \Krystal\Db\Sql\QueryBuilder
Appends ORDER BY expression