-
Notifications
You must be signed in to change notification settings - Fork 503
/
AbstractDataset.php
79 lines (60 loc) · 1.72 KB
/
AbstractDataset.php
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
76
77
78
79
<?php
namespace Ushahidi\Tests\Integration\Bootstrap\Database\Dataset;
abstract class AbstractDataset
{
public function __toString()
{
$iterator = $this->getIterator();
$dataSetString = '';
foreach ($iterator as $table) {
$dataSetString .= $table->__toString();
}
return $dataSetString;
}
public function getTableNames()
{
$tableNames = [];
foreach ($this->getIterator() as $table) {
$tableNames[] = $table->getTableMetaData()->getTableName();
}
return $tableNames;
}
public function getTableMetaData($tableName)
{
return $this->getTable($tableName)->getTableMetaData();
}
public function getTable($tableName)
{
foreach ($this->getIterator() as $table) {
if ($table->getTableMetaData()->getTableName() == $tableName) {
return $table;
}
}
}
public function getIterator()
{
return $this->createIterator();
}
public function getReverseIterator()
{
return $this->createIterator(true);
}
public function matches($other)
{
$thisTableNames = $this->getTableNames();
$otherTableNames = $other->getTableNames();
\sort($thisTableNames);
\sort($otherTableNames);
if ($thisTableNames != $otherTableNames) {
return false;
}
foreach ($thisTableNames as $tableName) {
$table = $this->getTable($tableName);
if (!$table->matches($other->getTable($tableName))) {
return false;
}
}
return true;
}
abstract protected function createIterator($reverse = false);
}