|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Classes\Db\Iterators; |
|
4
|
|
|
|
|
5
|
|
|
use Classes\Db\DbTable; |
|
6
|
|
|
use Classes\Maker\AbstractMaker; |
|
7
|
|
|
|
|
8
|
|
|
class DbTables implements \ArrayAccess , \SeekableIterator , \Countable |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @type DbTable[] |
|
13
|
|
|
*/ |
|
14
|
|
|
private $objDbTables = array (); |
|
15
|
|
|
|
|
16
|
|
|
private $position = 0; |
|
17
|
|
|
|
|
18
|
|
|
public function offsetExists ( $offset ) |
|
19
|
|
|
{ |
|
20
|
|
|
return isset( $this->objDbTables[ trim ( $offset ) ] ); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function offsetGet ( $offset ) |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->objDbTables[ trim ( $offset ) ]; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function offsetSet ( $offset , $value ) |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->objDbTables[ trim ( $offset ) ] = $value; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function offsetUnset ( $offset ) |
|
34
|
|
|
{ |
|
35
|
|
|
unset( $this->objDbTables[ trim ( $offset ) ] ); |
|
36
|
|
|
|
|
37
|
|
|
return $this; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function count () |
|
41
|
|
|
{ |
|
42
|
|
|
return count ( $this->objDbTables ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* convert array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function toArrayFileName () |
|
49
|
|
|
{ |
|
50
|
|
|
if ( ! empty( $this->toArrayFileName ) ) |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->toArrayFileName; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
foreach ( $this->objDbTables as $objDbTable ) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->toArrayFileName[] = AbstractMaker::getClassName ( $objDbTable->getName () ) |
|
58
|
|
|
. '.php'; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->toArrayFileName; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/* Method required for SeekableIterator interface */ |
|
65
|
|
|
|
|
66
|
|
|
public function seek ( $position ) |
|
67
|
|
|
{ |
|
68
|
|
|
$current = array_keys ( $this->objDbTables ); |
|
69
|
|
|
if ( ! isset( $this->objDbTables[ $current[ $position ] ] ) ) |
|
70
|
|
|
{ |
|
71
|
|
|
throw new OutOfBoundsException( "invalid seek position ($position)" ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$this->position = $position; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/* Methods required for Iterator interface */ |
|
78
|
|
|
|
|
79
|
|
|
public function rewind () |
|
80
|
|
|
{ |
|
81
|
|
|
$this->position = 0; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function current () |
|
85
|
|
|
{ |
|
86
|
|
|
$current = array_keys ( $this->objDbTables ); |
|
87
|
|
|
|
|
88
|
|
|
return $this->objDbTables[ $current[ $this->position ] ]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function key () |
|
92
|
|
|
{ |
|
93
|
|
|
$current = array_keys ( $this->objDbTables ); |
|
94
|
|
|
|
|
95
|
|
|
return $current[ $this->position ]; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function next () |
|
99
|
|
|
{ |
|
100
|
|
|
++ $this->position; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function valid () |
|
104
|
|
|
{ |
|
105
|
|
|
$current = array_keys ( $this->objDbTables ); |
|
106
|
|
|
|
|
107
|
|
|
return isset( $current[ $this->position ] ); |
|
108
|
|
|
} |
|
109
|
|
|
} |