Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

db_text.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 3.80 KiB


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\config;
015   
016  /**
017  * Manages configuration options with an arbitrary length value stored in a TEXT
018  * column. In constrast to class \phpbb\config\db, values are never cached and
019  * prefetched, but every get operation sends a query to the database.
020  */
021  class db_text
022  {
023      /**
024      * Database connection
025      * @var \phpbb\db\driver\driver_interface
026      */
027      protected $db;
028   
029      /**
030      * Name of the database table used.
031      * @var string
032      */
033      protected $table;
034   
035      /**
036      * @param \phpbb\db\driver\driver_interface $db        Database connection
037      * @param string          $table     Table name
038      */
039      public function __construct(\phpbb\db\driver\driver_interface $db, $table)
040      {
041          $this->db = $db;
042          $this->table = $this->db->sql_escape($table);
043      }
044   
045      /**
046      * Sets the configuration option with the name $key to $value.
047      *
048      * @param string $key       The configuration option's name
049      * @param string $value     New configuration value
050      *
051      * @return null
052      */
053      public function set($key, $value)
054      {
055          $this->set_array(array($key => $value));
056      }
057   
058      /**
059      * Gets the configuration value for the name $key.
060      *
061      * @param string $key       The configuration option's name
062      *
063      * @return string|null      String result on success
064      *                          null if there is no such option
065      */
066      public function get($key)
067      {
068          $map = $this->get_array(array($key));
069   
070          return isset($map[$key]) ? $map[$key] : null;
071      }
072   
073      /**
074      * Removes the configuration option with the name $key.
075      *
076      * @param string $key       The configuration option's name
077      *
078      * @return null
079      */
080      public function delete($key)
081      {
082          $this->delete_array(array($key));
083      }
084   
085      /**
086      * Mass set configuration options: Receives an associative array,
087      * treats array keys as configuration option names and associated
088      * array values as their configuration option values.
089      *
090      * @param array $map        Map from configuration names to values
091      *
092      * @return null
093      */
094      public function set_array(array $map)
095      {
096          $this->db->sql_transaction('begin');
097   
098          foreach ($map as $key => $value)
099          {
100              $sql = 'UPDATE ' . $this->table . "
101                  SET config_value = '" . $this->db->sql_escape($value) . "'
102                  WHERE config_name = '" . $this->db->sql_escape($key) . "'";
103              $this->db->sql_query($sql);
104   
105              if (!$this->db->sql_affectedrows())
106              {
107                  $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array(
108                      'config_name'    => (string) $key,
109                      'config_value'    => (string) $value,
110                  ));
111                  $this->db->sql_query($sql);
112              }
113          }
114   
115          $this->db->sql_transaction('commit');
116      }
117   
118      /**
119      * Mass get configuration options: Receives a set of configuration
120      * option names and returns the result as a key => value map where
121      * array keys are configuration option names and array values are
122      * associated config option values.
123      *
124      * @param array $keys       Set of configuration option names
125      *
126      * @return array            Map from configuration names to values
127      */
128      public function get_array(array $keys)
129      {
130          $sql = 'SELECT *
131              FROM ' . $this->table . '
132              WHERE ' . $this->db->sql_in_set('config_name', $keys, false, true);
133          $result = $this->db->sql_query($sql);
134   
135          $map = array();
136          while ($row = $this->db->sql_fetchrow($result))
137          {
138              $map[$row['config_name']] = $row['config_value'];
139          }
140          $this->db->sql_freeresult($result);
141   
142          return $map;
143      }
144   
145      /**
146      * Mass delete configuration options.
147      *
148      * @param array $keys       Set of configuration option names
149      *
150      * @return null
151      */
152      public function delete_array(array $keys)
153      {
154          $sql = 'DELETE
155              FROM ' . $this->table . '
156              WHERE ' . $this->db->sql_in_set('config_name', $keys, false, true);
157          $this->db->sql_query($sql);
158      }
159  }
160