1 | <?php |
||
18 | class IndexDBReader { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $tables; |
||
23 | |||
24 | /** |
||
25 | * Lists of fields that contain an id. |
||
26 | * |
||
27 | * @var array<string,int> |
||
28 | */ |
||
29 | protected $id_fields; |
||
30 | |||
31 | /** |
||
32 | * List of all fields that contain an integer. |
||
33 | * |
||
34 | * @var array<string,0> |
||
35 | */ |
||
36 | protected $int_fields; |
||
37 | |||
38 | /** |
||
39 | * @var \Closure |
||
40 | */ |
||
41 | protected $get_query_builder; |
||
42 | |||
43 | /** |
||
44 | * @var Insert |
||
45 | */ |
||
46 | protected $other; |
||
47 | |||
48 | /** |
||
49 | * @var bool |
||
50 | */ |
||
51 | protected $already_run; |
||
52 | |||
53 | /** |
||
54 | * @param array $tables list of tables and fields according to IndexDB |
||
55 | * @param array $id_fields list of fields that contain a id |
||
56 | * @param array $int_fields list of fields that contain an int |
||
57 | * @param \Closure $get_query_builder to get a QueryBuilder |
||
58 | */ |
||
59 | public function __construct($tables, $id_fields, $int_fields, \Closure $get_query_builder, Insert $insert) { |
||
67 | |||
68 | |||
69 | /** |
||
70 | * Read the index from the database and put it to insert. |
||
71 | */ |
||
72 | public function run() { |
||
82 | |||
83 | /** |
||
84 | * Builds a list of inserts ordered by the id. |
||
85 | * |
||
86 | * @return \Iterator $table => $values |
||
87 | */ |
||
88 | protected function get_inserts() { |
||
131 | |||
132 | /** |
||
133 | * Initialize all tables that contain an id with their results. |
||
134 | * |
||
135 | * @return array[] containing [$table_name, null, $results] |
||
136 | */ |
||
137 | protected function build_results_with_id() { |
||
147 | |||
148 | /** |
||
149 | * @param string $table |
||
150 | * @return \Iterator |
||
151 | */ |
||
152 | protected function select_all_from($table) { |
||
164 | |||
165 | /** |
||
166 | * Transforms results as retreived from sql to their appropriate internal |
||
167 | * representation. |
||
168 | * |
||
169 | * @param array $results from database |
||
170 | * @return array |
||
171 | */ |
||
172 | public function transform_results(array $results) { |
||
183 | |||
184 | /** |
||
185 | * @param \Iterator $inserts |
||
186 | * @return null |
||
187 | */ |
||
188 | protected function write_inserts(\Iterator $inserts) { |
||
202 | } |
||
203 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: