Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
config | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
get_section_by_name | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
add_section | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
get_data | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\search\backend\sphinx; |
15 | |
16 | /** |
17 | * An object representing the sphinx configuration |
18 | * Can read it from file and write it back out after modification |
19 | */ |
20 | class config |
21 | { |
22 | /** @var array Sections array */ |
23 | private $sections = []; |
24 | |
25 | /** |
26 | * Get a section object by its name |
27 | * |
28 | * @param string $name The name of the section that shall be returned |
29 | * @return config_section|null The section object or null if none was found |
30 | */ |
31 | public function get_section_by_name(string $name): ?config_section |
32 | { |
33 | for ($i = 0, $size = count($this->sections); $i < $size; $i++) |
34 | { |
35 | // Make sure this is really a section object and not a comment |
36 | if (($this->sections[$i] instanceof config_section) && $this->sections[$i]->get_name() == $name) |
37 | { |
38 | return $this->sections[$i]; |
39 | } |
40 | } |
41 | |
42 | return null; |
43 | } |
44 | |
45 | /** |
46 | * Appends a new empty section to the end of the config |
47 | * |
48 | * @param string $name The name for the new section |
49 | * @return config_section The newly created section object |
50 | */ |
51 | public function add_section(string $name): config_section |
52 | { |
53 | $this->sections[] = new config_section($name, ''); |
54 | return $this->sections[count($this->sections) - 1]; |
55 | } |
56 | |
57 | /** |
58 | * Returns the config data |
59 | * |
60 | * @return string $data The config data that is generated |
61 | */ |
62 | public function get_data(): string |
63 | { |
64 | $data = ""; |
65 | foreach ($this->sections as $section) |
66 | { |
67 | $data .= $section->to_string(); |
68 | } |
69 | |
70 | return $data; |
71 | } |
72 | } |