00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 abstract class SQLChain implements LogicalObject, MappableObject
00017 {
00018 protected $chain = array();
00019 protected $logic = array();
00020
00024 protected function exp(DialectString $exp, $logic)
00025 {
00026 $this->chain[] = $exp;
00027 $this->logic[] = $logic;
00028
00029 return $this;
00030 }
00031
00032 public function getSize()
00033 {
00034 return count($this->chain);
00035 }
00036
00040 public function toMapped(StorableDAO $dao, JoinCapableQuery $query)
00041 {
00042 $size = count($this->chain);
00043
00044 Assert::isTrue($size > 0, 'empty chain');
00045
00046 $chain = new $this;
00047
00048 for ($i = 0; $i < $size; ++$i) {
00049 $chain->exp(
00050 $dao->guessAtom($this->chain[$i], $query),
00051 $this->logic[$i]
00052 );
00053 }
00054
00055 return $chain;
00056 }
00057
00058 public function toDialectString(Dialect $dialect)
00059 {
00060 if ($this->chain) {
00061 $out = $this->chain[0]->toDialectString($dialect).' ';
00062 for ($i = 1, $size = count($this->chain); $i < $size; ++$i) {
00063 $out .=
00064 $this->logic[$i]
00065 .' '
00066 .$this->chain[$i]->toDialectString($dialect)
00067 .' ';
00068 }
00069
00070 if ($size > 1)
00071 $out = rtrim($out);
00072
00073 if ($size === 1)
00074 return $out;
00075
00076 return '('.$out.')';
00077 }
00078
00079 return null;
00080 }
00081 }
00082 ?>