. */ namespace Doctrine\ORM\Query\Expr; /** * Expression class for building DQL Order By parts * * * @link www.doctrine-project.org * @since 2.0 * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel */ class OrderBy { /** * @var string */ protected $preSeparator = ''; /** * @var string */ protected $separator = ', '; /** * @var string */ protected $postSeparator = ''; /** * @var array */ protected $allowedClasses = array(); /** * @var array */ protected $parts = array(); /** * @param string $sort * @param string $order */ public function __construct($sort = null, $order = null) { if ($sort) { $this->add($sort, $order); } } /** * @param string $sort * @param string $order */ public function add($sort, $order = null) { $order = ! $order ? 'ASC' : $order; $this->parts[] = $sort . ' '. $order; } /** * @return integer */ public function count() { return count($this->parts); } /** * @return array */ public function getParts() { return $this->parts; } /** * @return string */ public function __tostring() { return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator; } }