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 OqlQueryParameter 00016 { 00017 private $value = null; 00018 private $bindable = false; 00019 00023 public static function create() 00024 { 00025 return new self; 00026 } 00027 00028 public function getValue() 00029 { 00030 return $this->value; 00031 } 00032 00036 public function setValue($value) 00037 { 00038 $this->value = $value; 00039 00040 return $this; 00041 } 00042 00043 public function isBindable() 00044 { 00045 return $this->bindable; 00046 } 00047 00051 public function setBindable($orly = true) 00052 { 00053 $this->bindable = ($orly === true); 00054 00055 return $this; 00056 } 00057 00058 public function evaluate($values) 00059 { 00060 if ($this->isBindable()) { 00061 Assert::isPositiveInteger( 00062 $this->getValue(), 00063 'wrong substitution number: $'.$this->getValue() 00064 ); 00065 Assert::isIndexExists( 00066 $values, 00067 $this->getValue(), 00068 'parameter $'.$this->getValue().' is not binded' 00069 ); 00070 00071 $value = $values[$this->getValue()]; 00072 00073 } else 00074 $value = $this->getValue(); 00075 00076 if ($value instanceof Query) { 00077 return $value; 00078 00079 } elseif ($value instanceof Identifiable) { 00080 return $value->getId(); 00081 00082 } elseif (is_array($value)) { 00083 $list = array(); 00084 foreach ($value as $key => $parameter) { 00085 if ($parameter instanceof OqlQueryParameter) 00086 $list[$key] = $parameter->evaluate($values); 00087 else 00088 $list[$key] = $parameter; 00089 } 00090 00091 return $list; 00092 } 00093 00094 return $value; 00095 } 00096 } 00097 ?>