From 51a71ec4b9d62528054be8faee1576a8fd6d37f6 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 5 Jan 2015 16:54:16 +0100 Subject: New configuration system (not working yet) - Use only Minz_Configuration - register() method to load a new configuration file - get() to get a configuration - new exceptions related to configuration - fix a list configuration calls to have FRSS working Current problems to resolve: - How to handle configuration param verifications (i.e. check auth_type is a value from none, http_auth, persona or form) - We must use $conf = Minz_Configuration::get('system'); $general_conf = $conf->general; to access global system configuration which is quite annoying. How to change that? See https://github.com/FreshRSS/FreshRSS/issues/730 --- lib/Minz/Configuration.php | 517 +++++++++++++-------------------------------- 1 file changed, 145 insertions(+), 372 deletions(-) (limited to 'lib/Minz/Configuration.php') diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 6cbc9fc0b..66df21a31 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -1,419 +1,192 @@ -*/ /** - * La classe Configuration permet de gérer la configuration de l'application + * Manage configuration for the application. */ class Minz_Configuration { - const CONF_PATH_NAME = '/config.php'; - /** - * VERSION est la version actuelle de MINZ + * The list of configurations. */ - const VERSION = '1.3.1.freshrss'; // version spéciale FreshRSS + private static $config_list = array(); /** - * valeurs possibles pour l'"environment" - * SILENT rend l'application muette (pas de log) - * PRODUCTION est recommandée pour une appli en production - * (log les erreurs critiques) - * DEVELOPMENT log toutes les erreurs + * Add a new configuration to the list of configuration. + * + * @param $namespace the name of the current configuration + * @param $config_filename the filename of the configuration + * @param $default_filename a filename containing default values for the configuration + * @throws Minz_ConfigurationNamespaceException if the namespace already exists. */ - const SILENT = 0; - const PRODUCTION = 1; - const DEVELOPMENT = 2; + public static function register($namespace, $config_filename, $default_filename = null) { + if (isset(self::$config_list[$namespace])) { + throw new Minz_ConfigurationNamespaceException( + $namespace . ' namespace already exists' + ); + } + + self::$config_list[$namespace] = new Minz_Configuration( + $namespace, $config_filename, $default_filename + ); + } /** - * définition des variables de configuration - * $salt une chaîne de caractères aléatoires (obligatoire) - * $environment gère le niveau d'affichage pour log et erreurs - * $base_url le chemin de base pour accéder à l'application - * $title le nom de l'application - * $language la langue par défaut de l'application - * $db paramètres pour la base de données (tableau) - * - host le serveur de la base - * - user nom d'utilisateur - * - password mot de passe de l'utilisateur - * - base le nom de la base de données + * Parse a file and return its data. + * + * If the file does not contain a valid PHP code returning an array, an + * empty array is returned anyway. + * + * @param $filename the name of the file to parse. + * @return an array of values + * @throws Minz_FileNotExistException if the file does not exist. */ - private static $salt = ''; - private static $environment = Minz_Configuration::PRODUCTION; - private static $base_url = ''; - private static $title = ''; - private static $language = 'en'; - private static $default_user = ''; - private static $allow_anonymous = false; - private static $allow_anonymous_refresh = false; - private static $auth_type = 'none'; - private static $api_enabled = false; - private static $unsafe_autologin_enabled = false; - - private static $db = array ( - 'type' => 'mysql', - 'host' => '', - 'user' => '', - 'password' => '', - 'base' => '', - 'prefix' => '', - ); - - const MAX_SMALL_INT = 16384; - private static $limits = array( - 'cache_duration' => 800, //SimplePie cache duration in seconds - 'timeout' => 10, //SimplePie timeout in seconds - 'max_inactivity' => PHP_INT_MAX, //Time in seconds after which a user who has not used the account is considered inactive (no auto-refresh of feeds). - 'max_feeds' => Minz_Configuration::MAX_SMALL_INT, - 'max_categories' => Minz_Configuration::MAX_SMALL_INT, - ); + public static function parseFile($filename) { + if (!file_exists($filename)) { + throw new Minz_FileNotExistException($filename); + } - /* - * Getteurs - */ - public static function salt () { - return self::$salt; + $data = @include($filename); + if (is_array($data)) { + return $data; + } else { + return array(); + } } - public static function environment ($str = false) { - $env = self::$environment; - if ($str) { - switch (self::$environment) { - case self::SILENT: - $env = 'silent'; - break; - case self::DEVELOPMENT: - $env = 'development'; - break; - case self::PRODUCTION: - default: - $env = 'production'; - } + /** + * Return the configuration related to a given namespace. + * + * @param $namespace the name of the configuration to get. + * @return a Minz_Configuration object + * @throws Minz_ConfigurationNamespaceException if the namespace does not exist. + */ + public static function get($namespace) { + if (!isset(self::$config_list[$namespace])) { + throw new Minz_ConfigurationNamespaceException( + $namespace . ' namespace does not exist' + ); } - return $env; - } - public static function baseUrl () { - return self::$base_url; - } - public static function title () { - return self::$title; - } - public static function language () { - return self::$language; - } - public static function dataBase () { - return self::$db; - } - public static function limits() { - return self::$limits; - } - public static function defaultUser () { - return self::$default_user; - } - public static function allowAnonymous() { - return self::$allow_anonymous; - } - public static function allowAnonymousRefresh() { - return self::$allow_anonymous_refresh; - } - public static function authType() { - return self::$auth_type; - } - public static function needsLogin() { - return self::$auth_type !== 'none'; - } - public static function canLogIn() { - return self::$auth_type === 'form' || self::$auth_type === 'persona'; - } - public static function apiEnabled() { - return self::$api_enabled; - } - public static function unsafeAutologinEnabled() { - return self::$unsafe_autologin_enabled; + return self::$config_list[$namespace]; } - public static function _allowAnonymous($allow = false) { - self::$allow_anonymous = ((bool)$allow) && self::canLogIn(); - } - public static function _allowAnonymousRefresh($allow = false) { - self::$allow_anonymous_refresh = ((bool)$allow) && self::allowAnonymous(); - } - public static function _authType($value) { - $value = strtolower($value); - switch ($value) { - case 'form': - case 'http_auth': - case 'persona': - case 'none': - self::$auth_type = $value; - break; - } - self::_allowAnonymous(self::$allow_anonymous); - } + /** + * The namespace of the current configuration. + */ + private $namespace = ''; - public static function _enableApi($value = false) { - self::$api_enabled = (bool)$value; - } - public static function _enableAutologin($value = false) { - self::$unsafe_autologin_enabled = (bool)$value; - } + /** + * The filename for the current configuration. + */ + private $config_filename = ''; + + /** + * The filename for the current default values, null by default. + */ + private $default_filename = null; + + /** + * The configuration values, an empty array by default. + */ + private $data = array(); + + /** + * The default values, an empty array by default. + */ + private $data_default = array(); /** - * Initialise les variables de configuration - * @exception Minz_FileNotExistException si le CONF_PATH_NAME n'existe pas - * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté + * Create a new Minz_Configuration object. + * + * @param $namespace the name of the current configuration. + * @param $config_filename the file containing configuration values. + * @param $default_filename the file containing default values, null by default. */ - public static function init () { + private function __construct($namespace, $config_filename, $default_filename = null) { + $this->namespace = $namespace; + $this->config_filename = $config_filename; + try { - self::parseFile (); - self::setReporting (); + $this->data = self::parseFile($this->config_filename); } catch (Minz_FileNotExistException $e) { - throw $e; - } catch (Minz_BadConfigurationException $e) { - throw $e; + if (is_null($default_filename)) { + throw $e; + } } - } - public static function writeFile() { - $ini_array = array( - 'general' => array( - 'environment' => self::environment(true), - 'salt' => self::$salt, - 'base_url' => self::$base_url, - 'title' => self::$title, - 'default_user' => self::$default_user, - 'allow_anonymous' => self::$allow_anonymous, - 'allow_anonymous_refresh' => self::$allow_anonymous_refresh, - 'auth_type' => self::$auth_type, - 'api_enabled' => self::$api_enabled, - 'unsafe_autologin_enabled' => self::$unsafe_autologin_enabled, - ), - 'limits' => self::$limits, - 'db' => self::$db, - ); - @rename(DATA_PATH . self::CONF_PATH_NAME, DATA_PATH . self::CONF_PATH_NAME . '.bak.php'); - $result = file_put_contents(DATA_PATH . self::CONF_PATH_NAME, "default_filename = $default_filename; + if (!is_null($this->default_filename)) { + $this->data_default = self::parseFile($this->default_filename); } - return (bool)$result; } /** - * Parse un fichier de configuration - * @exception Minz_PermissionDeniedException si le CONF_PATH_NAME n'est pas accessible - * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté + * Return the value of the given param. + * + * @param $key the name of the param. + * @param $default default value to return if key does not exist. + * @return the value corresponding to the key. + * @throws Minz_ConfigurationParamException if the param does not exist */ - private static function parseFile () { - $ini_array = include(DATA_PATH . self::CONF_PATH_NAME); - - if (!is_array($ini_array)) { - throw new Minz_PermissionDeniedException ( - DATA_PATH . self::CONF_PATH_NAME, - Minz_Exception::ERROR + public function param($key, $default = null) { + if (isset($this->data[$key])) { + return $this->data[$key]; + } elseif (!is_null($default)) { + return $default; + } elseif (isset($this->data_default[$key])) { + return $this->data_default[$key]; + } else { + throw new Minz_ConfigurationParamException( + $key . ' param does not exist' ); } + } - // [general] est obligatoire - if (!isset ($ini_array['general'])) { - throw new Minz_BadConfigurationException ( - '[general]', - Minz_Exception::ERROR - ); - } - $general = $ini_array['general']; + /** + * A wrapper for param(). + */ + public function __get($key) { + return $this->param($key); + } - // salt est obligatoire - if (!isset ($general['salt'])) { - if (isset($general['sel_application'])) { //v0.6 - $general['salt'] = $general['sel_application']; - } else { - throw new Minz_BadConfigurationException ( - 'salt', - Minz_Exception::ERROR - ); - } + /** + * Set or remove a param. + * + * @param $key the param name to set. + * @param $value the value to set. If null, the key is removed from the configuration. + */ + public function _param($key, $value = null) { + if (isset($this->data[$key]) && is_null($value)) { + unset($this->data[$key]); + } else { + $this->data[$key] = $value; } - self::$salt = $general['salt']; - - if (isset ($general['environment'])) { - switch ($general['environment']) { - case 'silent': - self::$environment = Minz_Configuration::SILENT; - break; - case 'development': - self::$environment = Minz_Configuration::DEVELOPMENT; - break; - case 'production': - self::$environment = Minz_Configuration::PRODUCTION; - break; - default: - if ($general['environment'] >= 0 && - $general['environment'] <= 2) { - // fallback 0.7-beta - self::$environment = $general['environment']; - } else { - throw new Minz_BadConfigurationException ( - 'environment', - Minz_Exception::ERROR - ); - } - } + } - } - if (isset ($general['base_url'])) { - self::$base_url = $general['base_url']; - } + /** + * A wrapper for _param(). + */ + public function __set($key, $value) { + $this->_param($key, $value); + } - if (isset ($general['title'])) { - self::$title = $general['title']; - } - if (isset ($general['language'])) { - self::$language = $general['language']; - } - if (isset ($general['default_user'])) { - self::$default_user = $general['default_user']; - } - if (isset ($general['auth_type'])) { - self::_authType($general['auth_type']); - } - if (isset ($general['allow_anonymous'])) { - self::$allow_anonymous = ( - ((bool)($general['allow_anonymous'])) && - ($general['allow_anonymous'] !== 'no') - ); - } - if (isset ($general['allow_anonymous_refresh'])) { - self::$allow_anonymous_refresh = ( - ((bool)($general['allow_anonymous_refresh'])) && - ($general['allow_anonymous_refresh'] !== 'no') - ); - } - if (isset ($general['api_enabled'])) { - self::$api_enabled = ( - ((bool)($general['api_enabled'])) && - ($general['api_enabled'] !== 'no') - ); - } - if (isset ($general['unsafe_autologin_enabled'])) { - self::$unsafe_autologin_enabled = ( - ((bool)($general['unsafe_autologin_enabled'])) && - ($general['unsafe_autologin_enabled'] !== 'no') - ); - } + /** + * Save the current configuration in the configuration file. + */ + public function save() { + $back_filename = $this->config_filename . '.bak.php'; + @rename($this->config_filename, $back_filename); - if (isset($ini_array['limits'])) { - $limits = $ini_array['limits']; - if (isset($limits['cache_duration'])) { - $v = intval($limits['cache_duration']); - if ($v > 0) { - self::$limits['cache_duration'] = $v; - } - } - if (isset($limits['timeout'])) { - $v = intval($limits['timeout']); - if ($v > 0) { - self::$limits['timeout'] = $v; - } - } - if (isset($limits['max_inactivity'])) { - $v = intval($limits['max_inactivity']); - if ($v > 0) { - self::$limits['max_inactivity'] = $v; - } - } - if (isset($limits['max_feeds'])) { - $v = intval($limits['max_feeds']); - if ($v > 0 && $v < Minz_Configuration::MAX_SMALL_INT) { - self::$limits['max_feeds'] = $v; - } - } - if (isset($limits['max_categories'])) { - $v = intval($limits['max_categories']); - if ($v > 0 && $v < Minz_Configuration::MAX_SMALL_INT) { - self::$limits['max_categories'] = $v; - } - } + if (file_put_contents($this->config_filename, + "data, true) . ';', + LOCK_EX) === false) { + return false; } - // Base de données - if (isset ($ini_array['db'])) { - $db = $ini_array['db']; - if (empty($db['type'])) { - throw new Minz_BadConfigurationException ( - 'type', - Minz_Exception::ERROR - ); - } - switch ($db['type']) { - case 'mysql': - if (empty($db['host'])) { - throw new Minz_BadConfigurationException ( - 'host', - Minz_Exception::ERROR - ); - } - if (empty($db['user'])) { - throw new Minz_BadConfigurationException ( - 'user', - Minz_Exception::ERROR - ); - } - if (!isset($db['password'])) { - throw new Minz_BadConfigurationException ( - 'password', - Minz_Exception::ERROR - ); - } - if (empty($db['base'])) { - throw new Minz_BadConfigurationException ( - 'base', - Minz_Exception::ERROR - ); - } - self::$db['host'] = $db['host']; - self::$db['user'] = $db['user']; - self::$db['password'] = $db['password']; - self::$db['base'] = $db['base']; - if (isset($db['prefix'])) { - self::$db['prefix'] = $db['prefix']; - } - break; - case 'sqlite': - self::$db['host'] = ''; - self::$db['user'] = ''; - self::$db['password'] = ''; - self::$db['base'] = ''; - self::$db['prefix'] = ''; - break; - default: - throw new Minz_BadConfigurationException ( - 'type', - Minz_Exception::ERROR - ); - break; - } - self::$db['type'] = $db['type']; + // Clear PHP 5.5+ cache for include + if (function_exists('opcache_invalidate')) { + opcache_invalidate($this->config_filename); } - } - private static function setReporting() { - switch (self::$environment) { - case self::PRODUCTION: - error_reporting(E_ALL); - ini_set('display_errors','Off'); - ini_set('log_errors', 'On'); - break; - case self::DEVELOPMENT: - error_reporting(E_ALL); - ini_set('display_errors','On'); - ini_set('log_errors', 'On'); - break; - case self::SILENT: - error_reporting(0); - break; - } + return true; } } -- cgit v1.2.3 From 17a280230f1e47d092d8e22bc5d1041e7a84979f Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 6 Jan 2015 21:16:33 +0100 Subject: Change Minz_Configuration::parseFile() in load() See https://github.com/FreshRSS/FreshRSS/issues/730 --- lib/Minz/Configuration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/Minz/Configuration.php') diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 66df21a31..039ba9645 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -39,7 +39,7 @@ class Minz_Configuration { * @return an array of values * @throws Minz_FileNotExistException if the file does not exist. */ - public static function parseFile($filename) { + public static function load($filename) { if (!file_exists($filename)) { throw new Minz_FileNotExistException($filename); } @@ -106,7 +106,7 @@ class Minz_Configuration { $this->config_filename = $config_filename; try { - $this->data = self::parseFile($this->config_filename); + $this->data = self::load($this->config_filename); } catch (Minz_FileNotExistException $e) { if (is_null($default_filename)) { throw $e; @@ -115,7 +115,7 @@ class Minz_Configuration { $this->default_filename = $default_filename; if (!is_null($this->default_filename)) { - $this->data_default = self::parseFile($this->default_filename); + $this->data_default = self::load($this->default_filename); } } -- cgit v1.2.3 From bd199c617081f0354576afd09e9427756873afd2 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 7 Jan 2015 10:48:47 +0100 Subject: If a conf param doesn't exist, log and return null See https://github.com/FreshRSS/FreshRSS/issues/730 --- lib/Minz/Configuration.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/Minz/Configuration.php') diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 039ba9645..06a7b43b0 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -135,9 +135,8 @@ class Minz_Configuration { } elseif (isset($this->data_default[$key])) { return $this->data_default[$key]; } else { - throw new Minz_ConfigurationParamException( - $key . ' param does not exist' - ); + Minz_Log::warning($key . ' does not exist in configuration'); + return null; } } -- cgit v1.2.3 From 91e2d4936d71a72d0aefe9736879099283519239 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 7 Jan 2015 15:57:27 +0100 Subject: Add support of configuration_setter A configuration setter must implement only one method: `handle($key, $value)`. Before setting a value in configuration, the setter will be called with this method to check its validity. If a setter has been assigned to a configuration object, it will be called for each of its data so be careful to always return a value (or null if you want to delete the key). See https://github.com/FreshRSS/FreshRSS/issues/730 --- lib/Minz/Configuration.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'lib/Minz/Configuration.php') diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 06a7b43b0..5dbd55876 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -15,9 +15,11 @@ class Minz_Configuration { * @param $namespace the name of the current configuration * @param $config_filename the filename of the configuration * @param $default_filename a filename containing default values for the configuration + * @param $configuration_setter an optional helper to set values in configuration * @throws Minz_ConfigurationNamespaceException if the namespace already exists. */ - public static function register($namespace, $config_filename, $default_filename = null) { + public static function register($namespace, $config_filename, $default_filename = null, + $configuration_setter = null) { if (isset(self::$config_list[$namespace])) { throw new Minz_ConfigurationNamespaceException( $namespace . ' namespace already exists' @@ -25,7 +27,7 @@ class Minz_Configuration { } self::$config_list[$namespace] = new Minz_Configuration( - $namespace, $config_filename, $default_filename + $namespace, $config_filename, $default_filename, $configuration_setter ); } @@ -94,14 +96,21 @@ class Minz_Configuration { */ private $data_default = array(); + /** + * An object which help to set good values in configuration. + */ + private $configuration_setter = null; + /** * Create a new Minz_Configuration object. * * @param $namespace the name of the current configuration. * @param $config_filename the file containing configuration values. * @param $default_filename the file containing default values, null by default. + * @param $configuration_setter an optional helper to set values in configuration */ - private function __construct($namespace, $config_filename, $default_filename = null) { + private function __construct($namespace, $config_filename, $default_filename = null, + $configuration_setter = null) { $this->namespace = $namespace; $this->config_filename = $config_filename; @@ -117,6 +126,8 @@ class Minz_Configuration { if (!is_null($this->default_filename)) { $this->data_default = self::load($this->default_filename); } + + $this->configuration_setter = $configuration_setter; } /** @@ -154,9 +165,13 @@ class Minz_Configuration { * @param $value the value to set. If null, the key is removed from the configuration. */ public function _param($key, $value = null) { + if (!is_null($this->configuration_setter)) { + $value = $this->configuration_setter->handle($key, $value); + } + if (isset($this->data[$key]) && is_null($value)) { unset($this->data[$key]); - } else { + } elseif (!is_null($value)) { $this->data[$key] = $value; } } -- cgit v1.2.3 From 7f12058fab8a455cf33b5df614c5404f7a236d0a Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 7 Jan 2015 16:09:24 +0100 Subject: Add a method to change the configuration setter See https://github.com/FreshRSS/FreshRSS/issues/730 --- lib/Minz/Configuration.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/Minz/Configuration.php') diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 5dbd55876..019b47fae 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -127,7 +127,18 @@ class Minz_Configuration { $this->data_default = self::load($this->default_filename); } - $this->configuration_setter = $configuration_setter; + $this->_configurationSetter($configuration_setter); + } + + /** + * Set a configuration setter for the current configuration. + * @param $configuration_setter the setter to call when modifying data. It + * must implement an handle($key, $value) method. + */ + public function _configurationSetter($configuration_setter) { + if (is_callable(array($configuration_setter, 'handle'))) { + $this->configuration_setter = $configuration_setter; + } } /** -- cgit v1.2.3 From fb614ab80cf038416e5451b4f6f25f421d75d8e4 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 7 Jan 2015 17:36:29 +0100 Subject: Change way to call configuration setter. - Add a support($key) method which return if the given key is supported by the setter. - Change handle signature by adding a $data param which must be passed by reference. See https://github.com/FreshRSS/FreshRSS/issues/730 --- app/Models/ConfigurationSetter.php | 44 +++++++++++++++++++++++--------------- lib/Minz/Configuration.php | 8 +++---- 2 files changed, 30 insertions(+), 22 deletions(-) (limited to 'lib/Minz/Configuration.php') diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index e30cb0187..801e11625 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -1,37 +1,47 @@ '_language', - 'posts_per_page' => '_posts_per_page', - 'view_mode' => '_view_mode', - ); + /** + * Return if the given key is supported by this setter. + * @param $key the key to test. + * @return true if the key is supported, false else. + */ + public function support($key) { + $name_setter = '_' . $key; + return is_callable(array($this, $name_setter)); + } - public function handle($key, $value) { - if (isset($this->setters[$key])) { - $value = call_user_func(array($this, $this->setters[$key]), $value); - } - return $value; + /** + * Set the given key in data with the current value. + * @param $data an array containing the list of all configuration data. + * @param $key the key to update. + * @param $value the value to set. + */ + public function handle(&$data, $key, $value) { + $name_setter = '_' . $key; + call_user_func_array(array($this, $name_setter), array(&$data, $value)); } - private function _language($value) { + /** + * The (long) list of setters. + */ + private function _language(&$data, $value) { $languages = Minz_Translate::availableLanguages(); if (!isset($languages[$value])) { $value = 'en'; } - - return $value; + $data['language'] = $value; } - private function _posts_per_page($value) { + private function _posts_per_page(&$data, $value) { $value = intval($value); - return $value > 0 ? $value : 10; + $data['posts_per_page'] = $value > 0 ? $value : 10; } - private function _view_mode($value) { + private function _view_mode(&$data, $value) { if (!in_array($value, array('global', 'normal', 'reader'))) { $value = 'normal'; } - return $value; + $data['view_mode'] = $value; } } diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 019b47fae..6044fc269 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -176,11 +176,9 @@ class Minz_Configuration { * @param $value the value to set. If null, the key is removed from the configuration. */ public function _param($key, $value = null) { - if (!is_null($this->configuration_setter)) { - $value = $this->configuration_setter->handle($key, $value); - } - - if (isset($this->data[$key]) && is_null($value)) { + if (!is_null($this->configuration_setter) && $this->configuration_setter->support($key)) { + $this->configuration_setter->handle($this->data, $key, $value); + } elseif (isset($this->data[$key]) && is_null($value)) { unset($this->data[$key]); } elseif (!is_null($value)) { $this->data[$key] = $value; -- cgit v1.2.3