[feature/sphinx-fulltext-search] improve classes in functions-sphinx.php

PHPBB3-10946
This commit is contained in:
Dhruv Goel 2012-06-27 00:17:39 +05:30 committed by Dhruv
parent 02588069f0
commit 74a7407927

View file

@ -46,16 +46,14 @@ class sphinx_config
*/ */
function &get_section_by_name($name) function &get_section_by_name($name)
{ {
for ($i = 0, $n = sizeof($this->sections); $i < $n; $i++) for ($i = 0, $size = sizeof($this->sections); $i < $size; $i++)
{ {
// make sure this is really a section object and not a comment // make sure this is really a section object and not a comment
if (is_a($this->sections[$i], 'sphinx_config_section') && $this->sections[$i]->get_name() == $name) if (($this->sections[$i] instanceof sphinx_config_section) && $this->sections[$i]->get_name() == $name)
{ {
return $this->sections[$i]; return $this->sections[$i];
} }
} }
$null = null;
return $null;
} }
/** /**
@ -116,7 +114,7 @@ class sphinx_config
$section_name = ''; $section_name = '';
$section_name_comment = ''; $section_name_comment = '';
$found_opening_bracket = false; $found_opening_bracket = false;
for ($j = 0, $n = strlen($line); $j < $n; $j++) for ($j = 0, $length = strlen($line); $j < $length; $j++)
{ {
if ($line[$j] == '#') if ($line[$j] == '#')
{ {
@ -189,15 +187,15 @@ class sphinx_config
$in_value = false; $in_value = false;
$end_section = false; $end_section = false;
// ... then we should prase this line char by char: /* ... then we should prase this line char by char:
// - first there's the variable name - first there's the variable name
// - then an equal sign - then an equal sign
// - the variable value - the variable value
// - possibly a backslash before the linefeed in this case we need to continue - possibly a backslash before the linefeed in this case we need to continue
// parsing the value in the next line parsing the value in the next line
// - a # indicating that the rest of the line is a comment - a # indicating that the rest of the line is a comment
// - a closing curly bracket indicating the end of this section - a closing curly bracket indicating the end of this section*/
for ($j = 0, $n = strlen($line); $j < $n; $j++) for ($j = 0, $length = strlen($line); $j < $length; $j++)
{ {
if ($line[$j] == '#') if ($line[$j] == '#')
{ {
@ -223,7 +221,7 @@ class sphinx_config
} }
else else
{ {
if ($line[$j] == '\\' && $j == $n - 1) if ($line[$j] == '\\' && $j == $length - 1)
{ {
$value .= "\n"; $value .= "\n";
$in_value = true; $in_value = true;
@ -349,16 +347,14 @@ class sphinx_config_section
*/ */
function &get_variable_by_name($name) function &get_variable_by_name($name)
{ {
for ($i = 0, $n = sizeof($this->variables); $i < $n; $i++) for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)
{ {
// make sure this is a variable object and not a comment // make sure this is a variable object and not a comment
if (is_a($this->variables[$i], 'sphinx_config_variable') && $this->variables[$i]->get_name() == $name) if (($this->variables[$i] instanceof sphinx_config_variable) && $this->variables[$i]->get_name() == $name)
{ {
return $this->variables[$i]; return $this->variables[$i];
} }
} }
$null = null;
return $null;
} }
/** /**
@ -368,10 +364,10 @@ class sphinx_config_section
*/ */
function delete_variables_by_name($name) function delete_variables_by_name($name)
{ {
for ($i = 0; $i < sizeof($this->variables); $i++) for ($i = 0, $size = sizeof($this->variables); $i < $size; $i++)
{ {
// make sure this is a variable object and not a comment // make sure this is a variable object and not a comment
if (is_a($this->variables[$i], 'sphinx_config_variable') && $this->variables[$i]->get_name() == $name) if (($this->variables[$i] instanceof sphinx_config_variable) && $this->variables[$i]->get_name() == $name)
{ {
array_splice($this->variables, $i, 1); array_splice($this->variables, $i, 1);
$i--; $i--;