Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-10-09 07:17:28 +0400
committermattab <matthieu.aubry@gmail.com>2013-10-09 07:17:28 +0400
commit6d46df58dd4b16a5c8402e34ed018439cbbadee1 (patch)
treeefaeabfe94ab8a601a96c80e1333ae83513f803e /core/Option.php
parent9fb5490490913717ccfacec6f597181091be214f (diff)
Refs #4202 removing functions Piwik_GetOption and SetOption. Now use: Option::get and Option::set and Option::delete
Diffstat (limited to 'core/Option.php')
-rw-r--r--core/Option.php106
1 files changed, 64 insertions, 42 deletions
diff --git a/core/Option.php b/core/Option.php
index 3e4ad542d3..b784fe0f63 100644
--- a/core/Option.php
+++ b/core/Option.php
@@ -21,6 +21,65 @@ namespace Piwik;
class Option
{
/**
+ * Returns the option value for the requested option $name, fetching from database, if not in cache.
+ *
+ * @param string $name Key
+ * @return string|bool Value or false, if not found
+ */
+ public static function get($name)
+ {
+ return self::getInstance()->getValue($name);
+ }
+
+ /**
+ * Sets the option value in the database and cache
+ *
+ * @param string $name
+ * @param string $value
+ * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request.
+ */
+ public static function set($name, $value, $autoload = 0)
+ {
+ return self::getInstance()->setValue($name, $value, $autoload);
+ }
+
+ /**
+ * Delete key-value pair from database and reload cache.
+ *
+ * @param string $name Key to match exactly
+ * @param string $value Optional value
+ */
+ public static function delete($name, $value = null)
+ {
+ return self::getInstance()->deleteValue($name, $value);
+ }
+
+ /**
+ * Delete key-value pair(s) from database and reload cache.
+ * The supplied pattern should use '%' as wildcards, and literal '_' should be escaped.
+ *
+ * @param string $name Pattern of key to match.
+ * @param string $value Optional value
+ */
+ public static function deleteLike($name, $value = null)
+ {
+ return self::getInstance()->deleteNameLike($name, $value);
+ }
+
+ /**
+ * Clears the cache
+ * Used in unit tests to reset the state of the object between tests
+ *
+ * @return void
+ */
+ public static function clearCache()
+ {
+ $option = self::getInstance();
+ $option->loaded = false;
+ $option->all = array();
+ }
+
+ /**
* @var array
*/
private $all = array();
@@ -41,7 +100,7 @@ class Option
*
* @return \Piwik\Option
*/
- static public function getInstance()
+ static private function getInstance()
{
if (self::$instance == null) {
self::$instance = new self;
@@ -56,13 +115,7 @@ class Option
{
}
- /**
- * Returns the option value for the requested option $name, fetching from database, if not in cache.
- *
- * @param string $name Key
- * @return string|bool Value or false, if not found
- */
- public function get($name)
+ private function getValue($name)
{
$this->autoload();
if (isset($this->all[$name])) {
@@ -78,14 +131,7 @@ class Option
return $value;
}
- /**
- * Sets the option value in the database and cache
- *
- * @param string $name
- * @param string $value
- * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request.
- */
- public function set($name, $value, $autoLoad = 0)
+ private function setValue($name, $value, $autoLoad = 0)
{
$autoLoad = (int)$autoLoad;
Db::query('INSERT INTO `' . Common::prefixTable('option') . '` (option_name, option_value, autoload) ' .
@@ -95,13 +141,7 @@ class Option
$this->all[$name] = $value;
}
- /**
- * Delete key-value pair from database and reload cache.
- *
- * @param string $name Key to match exactly
- * @param string $value Optional value
- */
- public function delete($name, $value = null)
+ private function deleteValue($name, $value)
{
$sql = 'DELETE FROM `' . Common::prefixTable('option') . '` WHERE option_name = ?';
$bind[] = $name;
@@ -116,14 +156,7 @@ class Option
$this->clearCache();
}
- /**
- * Delete key-value pair(s) from database and reload cache.
- * The supplied pattern should use '%' as wildcards, and literal '_' should be escaped.
- *
- * @param string $name Pattern of key to match.
- * @param string $value Optional value
- */
- public function deleteLike($name, $value = null)
+ private function deleteNameLike($name, $value = null)
{
$sql = 'DELETE FROM `' . Common::prefixTable('option') . '` WHERE option_name LIKE ?';
$bind[] = $name;
@@ -159,15 +192,4 @@ class Option
$this->loaded = true;
}
- /**
- * Clears the cache
- * Used in unit tests to reset the state of the object between tests
- *
- * @return void
- */
- public function clearCache()
- {
- $this->loaded = false;
- $this->all = array();
- }
}