Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
config_section.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\search\sphinx;
015
016 /**
017 * \phpbb\search\sphinx\config_section
018 * Represents a single section inside the sphinx configuration
019 */
020 class config_section
021 {
022 private $name;
023 private $comment;
024 private $end_comment;
025 private $variables = array();
026
027 /**
028 * Construct a new section
029 *
030 * @param string $name Name of the section
031 * @param string $comment Comment that should be appended after the name in the
032 * textual format.
033 *
034 * @access public
035 */
036 function __construct($name, $comment)
037 {
038 $this->name = $name;
039 $this->comment = $comment;
040 $this->end_comment = '';
041 }
042
043 /**
044 * Add a variable object to the list of variables in this section
045 *
046 * @param \phpbb\search\sphinx\config_variable $variable The variable object
047 *
048 * @access public
049 */
050 function add_variable($variable)
051 {
052 $this->variables[] = $variable;
053 }
054
055 /**
056 * Adds a comment after the closing bracket in the textual representation
057 *
058 * @param string $end_comment
059 *
060 * @access public
061 */
062 function set_end_comment($end_comment)
063 {
064 $this->end_comment = $end_comment;
065 }
066
067 /**
068 * Getter for the name of this section
069 *
070 * @return string Section's name
071 *
072 * @access public
073 */
074 function get_name()
075 {
076 return $this->name;
077 }
078
079 /**
080 * Get a variable object by its name
081 *
082 * @param string $name The name of the variable that shall be returned
083 * @return \phpbb\search\sphinx\config_section The first variable object from this section with the
084 * given name or null if none was found
085 *
086 * @access public
087 */
088 function get_variable_by_name($name)
089 {
090 for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)
091 {
092 // Make sure this is a variable object and not a comment
093 if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)
094 {
095 return $this->variables[$i];
096 }
097 }
098 }
099
100 /**
101 * Deletes all variables with the given name
102 *
103 * @param string $name The name of the variable objects that are supposed to be removed
104 *
105 * @access public
106 */
107 function delete_variables_by_name($name)
108 {
109 for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)
110 {
111 // Make sure this is a variable object and not a comment
112 if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)
113 {
114 array_splice($this->variables, $i, 1);
115 $i--;
116 }
117 }
118 }
119
120 /**
121 * Create a new variable object and append it to the variable list of this section
122 *
123 * @param string $name The name for the new variable
124 * @param string $value The value for the new variable
125 * @return \phpbb\search\sphinx\config_variable Variable object that was created
126 *
127 * @access public
128 */
129 function create_variable($name, $value)
130 {
131 $this->variables[] = new \phpbb\search\sphinx\config_variable($name, $value, '');
132 return $this->variables[sizeof($this->variables) - 1];
133 }
134
135 /**
136 * Turns this object into a string which can be written to a config file
137 *
138 * @return string Config data in textual form, parsable for sphinx
139 *
140 * @access public
141 */
142 function to_string()
143 {
144 $content = $this->name . ' ' . $this->comment . "\n{\n";
145
146 // Make sure we don't get too many newlines after the opening bracket
147 while (trim($this->variables[0]->to_string()) == '')
148 {
149 array_shift($this->variables);
150 }
151
152 foreach ($this->variables as $variable)
153 {
154 $content .= $variable->to_string();
155 }
156 $content .= '}' . $this->end_comment . "\n";
157
158 return $content;
159 }
160 }
161