[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/search/sphinx/ -> config_section.php (source)

   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\sphinx;
  15  
  16  /**
  17  * \phpbb\search\sphinx\config_section
  18  * Represents a single section inside the sphinx configuration
  19  */
  20  class config_section
  21  {
  22      private $name;
  23      private $comment;
  24      private $end_comment;
  25      private $variables = array();
  26  
  27      /**
  28      * Construct a new section
  29      *
  30      * @param    string    $name        Name of the section
  31      * @param    string    $comment    Comment that should be appended after the name in the
  32      *                                textual format.
  33      *
  34      * @access    public
  35      */
  36  	function __construct($name, $comment)
  37      {
  38          $this->name = $name;
  39          $this->comment = $comment;
  40          $this->end_comment = '';
  41      }
  42  
  43      /**
  44      * Add a variable object to the list of variables in this section
  45      *
  46      * @param    \phpbb\search\sphinx\config_variable    $variable    The variable object
  47      *
  48      * @access    public
  49      */
  50  	function add_variable($variable)
  51      {
  52          $this->variables[] = $variable;
  53      }
  54  
  55      /**
  56      * Adds a comment after the closing bracket in the textual representation
  57      *
  58      * @param    string    $end_comment
  59      *
  60      * @access    public
  61      */
  62  	function set_end_comment($end_comment)
  63      {
  64          $this->end_comment = $end_comment;
  65      }
  66  
  67      /**
  68      * Getter for the name of this section
  69      *
  70      * @return    string    Section's name
  71      *
  72      * @access    public
  73      */
  74  	function get_name()
  75      {
  76          return $this->name;
  77      }
  78  
  79      /**
  80      * Get a variable object by its name
  81      *
  82      * @param    string                                 $name    The name of the variable that shall be returned
  83      * @return    \phpbb\search\sphinx\config_section            The first variable object from this section with the
  84      *                                                        given name or null if none was found
  85      *
  86      * @access    public
  87      */
  88  	function get_variable_by_name($name)
  89      {
  90          for ($i = 0, $size = count($this->variables); $i < $size; $i++)
  91          {
  92              // Make sure this is a variable object and not a comment
  93              if (($this->variables[$i] instanceof \phpbb\search\sphinx\config_variable) && $this->variables[$i]->get_name() == $name)
  94              {
  95                  return $this->variables[$i];
  96              }
  97          }
  98      }
  99  
 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 = count($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[count($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  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1