X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FCell.php;h=3c69a1294d015111db7629aee7234cb5e550dc45;hp=efa5fcbb3cd1154ecd99321bdddaf9e093a7a5c2;hb=409fca54acfee2db6c62540a8f67b1adfa695a38;hpb=dc87da9c4ec52918e34f2e43eac3014f0f99a8bc diff --git a/lib/pq/Gateway/Cell.php b/lib/pq/Gateway/Cell.php index efa5fcb..3c69a12 100644 --- a/lib/pq/Gateway/Cell.php +++ b/lib/pq/Gateway/Cell.php @@ -4,7 +4,7 @@ namespace pq\Gateway; use \pq\Query\Expressible; -class Cell extends Expressible +class Cell extends Expressible implements \ArrayAccess { /** * @var \pq\Gateway\Row @@ -39,7 +39,7 @@ class Cell extends Expressible * @return bool */ function isDirty() { - return $this->dirty; + return (bool) $this->dirty; } /** @@ -48,6 +48,14 @@ class Cell extends Expressible * @return \pq\Gateway\Cell */ function set($data) { + if ($data instanceof Row) { + $this->row->__set($data->getTable()->getName() . "_id", $data->id); + $this->row->__unset($this->name); + return $this; + } + if ($data instanceof Cell) { + $data = $data->get(); + } parent::set($data); $this->dirty = true; return $this; @@ -65,4 +73,37 @@ class Cell extends Expressible return $this; } + function offsetGet($o) { + if (isset($this->data) && !is_array($this->data)) { + throw new \UnexpectedValueException("Cell data is not an array"); + } + return $this->data[$o]; + } + + function offsetSet($o, $v) { + if (isset($this->data) && !is_array($this->data)) { + throw new \UnexpectedValueException("Cell data is not an array"); + } + if (isset($o)) { + $this->data[$o] = $v; + } else { + $this->data[] = $v; + } + $this->dirty = true; + } + + function offsetExists($o) { + if (isset($this->data) && !is_array($this->data)) { + throw new \UnexpectedValueException("Cell data is not an array"); + } + return isset($this->data[$o]); + } + + function offsetUnset($o) { + if (isset($this->data) && !is_array($this->data)) { + throw new \UnexpectedValueException("Cell data is not an array"); + } + unset($this->data[$o]); + $this->dirty = true; + } }