mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-19 06:51:33 +02:00
[ticket/16935] Refactor sphinx to use new clases and remove unused parts
PHPBB3-16935
This commit is contained in:
@@ -14,15 +14,19 @@
|
||||
namespace phpbb\search\backend\sphinx;
|
||||
|
||||
/**
|
||||
* \phpbb\search\sphinx\config_section
|
||||
* \phpbb\search\backend\sphinx\config_section
|
||||
* Represents a single section inside the sphinx configuration
|
||||
*/
|
||||
class config_section
|
||||
class config_section extends config_item
|
||||
{
|
||||
private $name;
|
||||
/** @var string Section comment */
|
||||
private $comment;
|
||||
|
||||
/** @var string Section end comment */
|
||||
private $end_comment;
|
||||
private $variables = array();
|
||||
|
||||
/** @var array Section variables array */
|
||||
private $variables = [];
|
||||
|
||||
/**
|
||||
* Construct a new section
|
||||
@@ -30,86 +34,57 @@ class config_section
|
||||
* @param string $name Name of the section
|
||||
* @param string $comment Comment that should be appended after the name in the
|
||||
* textual format.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct($name, $comment)
|
||||
public function __construct(string $name, string $comment)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->comment = $comment;
|
||||
$this->end_comment = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a variable object to the list of variables in this section
|
||||
*
|
||||
* @param \phpbb\search\sphinx\config_variable $variable The variable object
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function add_variable($variable)
|
||||
{
|
||||
$this->variables[] = $variable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment after the closing bracket in the textual representation
|
||||
*
|
||||
* @param string $end_comment
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function set_end_comment($end_comment)
|
||||
public function set_end_comment(string $end_comment): void
|
||||
{
|
||||
$this->end_comment = $end_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the name of this section
|
||||
*
|
||||
* @return string Section's name
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a variable object by its name
|
||||
*
|
||||
* @param string $name The name of the variable that shall be returned
|
||||
* @return \phpbb\search\sphinx\config_section The first variable object from this section with the
|
||||
* given name or null if none was found
|
||||
* @param string $name The name of the variable that shall be returned
|
||||
*
|
||||
* @access public
|
||||
* @return config_variable|null The first variable object from this section with the
|
||||
* given name or null if none was found
|
||||
*/
|
||||
function get_variable_by_name($name)
|
||||
public function get_variable_by_name(string $name): ?config_variable
|
||||
{
|
||||
for ($i = 0, $size = count($this->variables); $i < $size; $i++)
|
||||
{
|
||||
// Make sure this is a variable object and not a comment
|
||||
if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)
|
||||
if ($this->variables[$i]->get_name() == $name)
|
||||
{
|
||||
return $this->variables[$i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all variables with the given name
|
||||
*
|
||||
* @param string $name The name of the variable objects that are supposed to be removed
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function delete_variables_by_name($name)
|
||||
public function delete_variables_by_name(string $name)
|
||||
{
|
||||
for ($i = 0, $size = count($this->variables); $i < $size; $i++)
|
||||
{
|
||||
// Make sure this is a variable object and not a comment
|
||||
if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)
|
||||
if ($this->variables[$i]->get_name() == $name)
|
||||
{
|
||||
array_splice($this->variables, $i, 1);
|
||||
$i--;
|
||||
@@ -118,17 +93,16 @@ class config_section
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new variable object and append it to the variable list of this section
|
||||
* Create a new variable object and append it to the variables list of this section
|
||||
*
|
||||
* @param string $name The name for the new variable
|
||||
* @param string $value The value for the new variable
|
||||
* @return \phpbb\search\sphinx\config_variable Variable object that was created
|
||||
* @param string $name The name for the new variable
|
||||
* @param string $value The value for the new variable
|
||||
*
|
||||
* @access public
|
||||
* @return config_variable Variable object that was created
|
||||
*/
|
||||
function create_variable($name, $value)
|
||||
public function create_variable(string $name, string $value): config_variable
|
||||
{
|
||||
$this->variables[] = new \phpbb\search\sphinx\config_variable($name, $value, '');
|
||||
$this->variables[] = new config_variable($name, $value);
|
||||
return $this->variables[count($this->variables) - 1];
|
||||
}
|
||||
|
||||
@@ -136,10 +110,8 @@ class config_section
|
||||
* Turns this object into a string which can be written to a config file
|
||||
*
|
||||
* @return string Config data in textual form, parsable for sphinx
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function to_string()
|
||||
public function to_string(): string
|
||||
{
|
||||
$content = $this->name . ' ' . $this->comment . "\n{\n";
|
||||
|
||||
|
Reference in New Issue
Block a user