# OqlQueryExpression.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /****************************************************************************
    00003  *   Copyright (C) 2008 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
    00015     class OqlQueryExpression extends OqlQueryParameter
    00016     {
    00017         private static $classes = array();
    00018
    00019         private $className  = null;
    00020         private $parameters = array();
    00021
    00025         public static function create()
    00026         {
    00027             return new self;
    00028         }
    00029
    00030         public function getClassName()
    00031         {
    00032             return $this->className;
    00033         }
    00034
    00038         public function setClassName($className)
    00039         {
    00040             $this->className = $className;
    00041
    00042             return $this;
    00043         }
    00044
    00045         public function getParameters()
    00046         {
    00047             return $this->parameters;
    00048         }
    00049
    00050         public function hasParameter($index)
    00051         {
    00052             return isset($this->parameters[$index]);
    00053         }
    00054
    00058         public function getParameter($index)
    00059         {
    00060             return $this->parameters[$index];
    00061         }
    00062
    00066         public function addParameter(OqlQueryParameter $parameter)
    00067         {
    00068             $this->parameters[] = $parameter;
    00069
    00070             return $this;
    00071         }
    00072
    00076         public function setParameter($index, OqlQueryParameter $parameter)
    00077         {
    00078             $this->parameters[$index] = $parameter;
    00079
    00080             return $this;
    00081         }
    00082
    00083         public function evaluate($values)
    00084         {
    00085             $className = $this->getClassName();
    00086
    00087             if (!isset(self::$classes[$className]))
    00088                 self::$classes[$className] = new ReflectionClass($className);
    00089
    00090             $class = self::$classes[$className];
    00091             $parametersCount = count($class->getConstructor()->getParameters());
    00092             $parameters = array();
    00093
    00094             for ($i = 0; $i < $parametersCount; $i++) {
    00095                 if (!$this->hasParameter($i))
    00096                     break;
    00097
    00098                 $parameters[$i] = $this->getParameter($i)->evaluate($values);
    00099             }
    00100
    00101             return $class->newInstanceArgs($parameters);
    00102         }
    00103     }
    00104 ?>