Repository navigation
Expand file tree
/
Copy pathTableGateway.php
More file actions
75 lines (65 loc) · 2.43 KB
/
Copy pathTableGateway.php
File metadata and controls
75 lines (65 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace PhpDb\TableGateway;
use PhpDb\Adapter\AdapterInterface;
use PhpDb\ResultSet\ResultSet;
use PhpDb\ResultSet\ResultSetInterface;
use PhpDb\Sql\Sql;
use PhpDb\Sql\TableIdentifier;
use function is_array;
use function is_string;
class TableGateway extends AbstractTableGateway
{
/**
* Constructor
*
* @param string|TableIdentifier|array $table
* @param Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[]|null $features
* @throws Exception\InvalidArgumentException
*/
public function __construct(
$table,
AdapterInterface $adapter,
$features = null,
?ResultSetInterface $resultSetPrototype = null,
?Sql $sql = null
) {
// table
if (! (is_string($table) || $table instanceof TableIdentifier || is_array($table))) {
throw new Exception\InvalidArgumentException(
'Table name must be a string or an instance of PhpDb\Sql\TableIdentifier'
);
}
$this->table = $table;
// adapter
$this->adapter = $adapter;
// process features
if ($features !== null) {
if ($features instanceof Feature\AbstractFeature) {
$features = [$features];
}
if (is_array($features)) {
$this->featureSet = new Feature\FeatureSet($features);
} elseif ($features instanceof Feature\FeatureSet) {
$this->featureSet = $features;
} else {
throw new Exception\InvalidArgumentException(
'TableGateway expects $feature to be an instance of an AbstractFeature or a FeatureSet, or an '
. 'array of AbstractFeatures'
);
}
} else {
$this->featureSet = new Feature\FeatureSet();
}
// result prototype
$this->resultSetPrototype = $resultSetPrototype ?: new ResultSet();
// Sql object (factory for select, insert, update, delete)
$this->sql = $sql ?: new Sql($this->adapter, $this->table);
// check sql object bound to same table
if ($this->sql->getTable() !== $this->table) {
throw new Exception\InvalidArgumentException(
'The table inside the provided Sql object must match the table of this TableGateway'
);
}
$this->initialize();
}
}