X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FQuery%2FExecutor.php;fp=lib%2Fpq%2FQuery%2FExecutor.php;h=d1c75210d9a7e38a6ea33ac3b06a823c6d569b09;hp=a01580a030231116fc1465526e29e4218bb7f522;hb=580991717f5e8bb237403757e2111a8d04aca616;hpb=0e2eb1f13ef60ce9a8709354136c42f7d87b2345 diff --git a/lib/pq/Query/Executor.php b/lib/pq/Query/Executor.php index a01580a..d1c7521 100644 --- a/lib/pq/Query/Executor.php +++ b/lib/pq/Query/Executor.php @@ -12,12 +12,28 @@ class Executor implements ExecutorInterface */ protected $conn; + /** + * @var \SplObjectStorage + */ + protected $observers; + + /** + * @var WriterInterface + */ + protected $query; + + /** + * @var \pq\Result + */ + protected $result; + /** * Create a synchronous query executor * @param \pq\Connection $conn */ function __construct(\pq\Connection $conn) { $this->conn = $conn; + $this->observers = new \SplObjectStorage; } /** @@ -38,6 +54,22 @@ class Executor implements ExecutorInterface return $this; } + /** + * @inheritdoc + * @return WriterInterface + */ + function getQuery() { + return $this->query; + } + + /** + * @inheritdoc + * @return \pq\Result + */ + function getResult() { + return $this->result; + } + /** * Execute the query synchronously through \pq\Connection::execParams() * @param \pq\Query\WriterInterface $query @@ -45,6 +77,36 @@ class Executor implements ExecutorInterface * @return mixed */ function execute(WriterInterface $query, callable $callback) { - return $callback($this->getConnection()->execParams($query, $query->getParams(), $query->getTypes())); + $this->result = null; + $this->query = $query; + $this->notify(); + $this->result = $this->getConnection()->execParams($query, $query->getParams(), $query->getTypes()); + $this->notify(); + return $callback($this->result); + } + + /** + * @implements \SplSubject + * @param \SplObserver $observer + */ + function attach(\SplObserver $observer) { + $this->observers->attach($observer); + } + + /** + * @implements \SplSubject + * @param \SplObserver $observer + */ + function detach(\SplObserver $observer) { + $this->observers->detach($observer); + } + + /** + * @implements \SplSubject + */ + function notify() { + foreach ($this->observers as $observer){ + $observer->update($this); + } } }