Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00021 final class Queue implements Query
00022 {
00023 private $queue = array();
00024
00028 public static function create()
00029 {
00030 return new self;
00031 }
00032
00033 public function getId()
00034 {
00035 return sha1(serialize($this->queue));
00036 }
00037
00038 public function setId($id)
00039 {
00040 throw new UnsupportedMethodException();
00041 }
00042
00043 public function getQueue()
00044 {
00045 return $this->queue;
00046 }
00047
00051 public function add(Query $query)
00052 {
00053 $this->queue[] = $query;
00054
00055 return $this;
00056 }
00057
00061 public function remove(Query $query)
00062 {
00063 if (!$id = array_search($query, $this->queue))
00064 throw new MissingElementException();
00065
00066 unset($this->queue[$id]);
00067
00068 return $this;
00069 }
00070
00074 public function drop()
00075 {
00076 $this->queue = array();
00077
00078 return $this;
00079 }
00080
00084 public function run(DB $db)
00085 {
00086 $db->queryRaw($this->toDialectString($db->getDialect()));
00087
00088 return $this;
00089 }
00090
00094 public function flush(DB $db)
00095 {
00096 return $this->run($db)->drop();
00097 }
00098
00099
00100 public function toString()
00101 {
00102 return $this->toDialectString(ImaginaryDialect::me());
00103 }
00104
00105 public function toDialectString(Dialect $dialect)
00106 {
00107 $out = array();
00108
00109 foreach ($this->queue as $query)
00110 $out[] = $query->toDialectString($dialect);
00111
00112 return implode(";\n", $out);
00113 }
00114 }
00115 ?>