add identity and lock
[m6w6/pq-gateway] / lib / pq / Gateway / Table / OptimisticLock.php
1 <?php
2
3 namespace pq\Gateway\Table;
4
5 use \pq\Gateway\Row;
6
7 /**
8 * An optimistic row lock implementation using a versioning column
9 */
10 class OptimisticLock implements LockInterface
11 {
12 /**
13 * The name of the versioning column
14 * @var string
15 */
16 protected $column;
17
18 /**
19 * @param string $column
20 */
21 function __construct($column = "version") {
22 $this->column = $column;
23 }
24
25 /**
26 * @implements LockInterface
27 * @param \pq\Gateway\Row $row
28 * @param array $where reference to the criteria
29 */
30 function criteria(Row $row, array &$where) {
31 $where["{$this->column}="] = $row->getData()[$this->column];
32 $row->{$this->column}->mod(+1);
33 }
34 }