X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FRow.php;h=cda8d4af67a0ba857a6854b4f8c262f016f5e34d;hp=bba7c09c07642c90fe1d877f18c7462da40e7bfe;hb=b39e14404cfeac177d41b152690b6adbb2b1e4bf;hpb=580991717f5e8bb237403757e2111a8d04aca616 diff --git a/lib/pq/Gateway/Row.php b/lib/pq/Gateway/Row.php index bba7c09..cda8d4a 100644 --- a/lib/pq/Gateway/Row.php +++ b/lib/pq/Gateway/Row.php @@ -65,8 +65,8 @@ class Row implements \JsonSerializable } /** - * Export current state with security sensitive data removed. You should override that, just - * calls export() by default. + * Export current state with security sensitive data removed. You should override that. + * Just calls export() by default. * @return array */ function exportPublic() { @@ -167,10 +167,6 @@ class Row implements \JsonSerializable $where["$col IS"] = new QueryExpr("NULL"); } } - - if (($lock = $this->getTable()->getLock())) { - $lock->criteria($this, $where); - } return $where; } @@ -188,6 +184,18 @@ class Row implements \JsonSerializable return $changes; } + /** + * Cell accessor + * @param string $p column name + * @return \pq\Gateway\Cell + */ + protected function cell($p) { + if (!isset($this->cell[$p])) { + $this->cell[$p] = new Cell($this, $p, isset($this->data[$p]) ? $this->data[$p] : null); + } + return $this->cell[$p]; + } + /** * Get a cell or parent rows * @param string $p @@ -197,10 +205,7 @@ class Row implements \JsonSerializable if ($this->table->hasRelation($p)) { return $this->table->by($this, $p); } - if (!isset($this->cell[$p])) { - $this->cell[$p] = new Cell($this, $p, isset($this->data[$p]) ? $this->data[$p] : null); - } - return $this->cell[$p]; + return $this->cell($p); } /** @@ -209,7 +214,7 @@ class Row implements \JsonSerializable * @param mixed $v */ function __set($p, $v) { - $this->__get($p)->set($v); + $this->cell($p)->set($v); } /** @@ -262,7 +267,11 @@ class Row implements \JsonSerializable * @return \pq\Gateway\Row */ function update() { - $rowset = $this->table->update($this->criteria(), $this->changes()); + $criteria = $this->criteria(); + if (($lock = $this->getTable()->getLock())) { + $lock->onUpdate($this, $criteria); + } + $rowset = $this->table->update($criteria, $this->changes()); if (!count($rowset)) { throw new \UnexpectedValueException("No row updated"); }