# OqlOrderByParser.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /****************************************************************************
    00003  *   Copyright (C) 2009 by Vladlen Y. Koshelev                              *
    00004  *                                                                          *
    00005  *   This program is free software; you can redistribute it and/or modify   *
    00006  *   it under the terms of the GNU Lesser General Public License as         *
    00007  *   published by the Free Software Foundation; either version 3 of the     *
    00008  *   License, or (at your option) any later version.                        *
    00009  *                                                                          *
    00010  ****************************************************************************/
    00011
    00012     final class OqlOrderByParser extends OqlParser
    00013     {
    00017         public static function create()
    00018         {
    00019             return new self;
    00020         }
    00021
    00025         protected function makeOqlObject()
    00026         {
    00027             return OqlOrderByClause::create();
    00028         }
    00029
    00030         protected function handleState()
    00031         {
    00032             if ($this->state == self::INITIAL_STATE) {
    00033                 $list = $this->getCommaSeparatedList(
    00034                     array($this, 'getArgumentExpression'),
    00035                     "expecting expression in 'order by'"
    00036                 );
    00037
    00038                 foreach ($list as $argument)
    00039                     $this->oqlObject->add($argument);
    00040             }
    00041
    00042             return self::FINAL_STATE;
    00043         }
    00044
    00048         protected function getArgumentExpression()
    00049         {
    00050             $expression = $this->getLogicExpression();
    00051
    00052             $token = $this->tokenizer->peek();
    00053             if ($this->checkKeyword($token, array('asc', 'desc'))) {
    00054                 $direction = ($token->getValue() == 'asc');
    00055                 $this->tokenizer->next();
    00056
    00057             } else
    00058                 $direction = null;
    00059
    00060             return new OqlOrderByExpression($expression, $direction);
    00061         }
    00062     }
    00063 ?>