summaryrefslogtreecommitdiff
path: root/include/ini.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-10 12:36:50 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-10 12:36:50 +0200
commitec18c8779c6a806c6cbeb5fe12446955cd688221 (patch)
treeddc704bac5574d4727560469874019ecc07aed9e /include/ini.h
parentf0dec5907bd49bb468089b0fe50d8cbf2979272e (diff)
refactored ini settings
Diffstat (limited to 'include/ini.h')
-rw-r--r--include/ini.h278
1 files changed, 142 insertions, 136 deletions
diff --git a/include/ini.h b/include/ini.h
index 9d4cbd9..49587d7 100644
--- a/include/ini.h
+++ b/include/ini.h
@@ -1,16 +1,15 @@
/**
* Ini.h
*
+ * Class that can be instantiated in the get_module() startup function to
+ * define settings from the php.ini file that are supported.
*
- *
- *
- * @copyright 2013 Copernica BV
+ * @copyright 2014 Copernica BV
*/
/**
- * Forward declaration
+ * Forward declarations
*/
-
struct _zend_ini_entry;
/**
@@ -18,143 +17,150 @@ struct _zend_ini_entry;
*/
namespace Php {
+/**
+ * Class definition
+ */
+class Ini
+{
+public:
+ /**
+ * Supported place-types for ini setting
+ *
+ * The possible settings for where the configuration can be changed are:
+ * PHP_INI_USER, PHP_INI_PERDIR, PHP_INI_SYSTEM and PHP_INI_ALL
+ *
+ * Usually you would choose where the setting can be changed based on how
+ * it is used. For example if you want to access the setting during RINIT
+ * stage then you would want PHP_INI_PERDIR because the setting would have
+ * no use after RINIT.
+ */
+ enum Place : int {
+ User = (1<<0), // ZEND_INI_USER (1<<0)
+ Perdir = (1<<1), // ZEND_INI_PERDIR (1<<1)
+ System = (1<<2), // ZEND_INI_SYSTEM (1<<2)
+ All = (1<<0) | (1<<1) | (1<<2) // ZEND_INI_ALL (ZEND_INI_USER|ZEND_INI_PERDIR|ZEND_INI_SYSTEM)
+ };
+
+ /**
+ * Constructors for string values
+ *
+ * @param name Name of the php.ini variable
+ * @param value Default value
+ * @param orig Original value (if the user resets the variable, it is set back to this value)
+ * @param place Place where the ini setting can be changed
+ */
+ Ini(const char *name, const char *value, const char *orig, const Place place = Place::All) :
+ _name(name), _value(value), _orig(orig), _place(place) {}
+
+ Ini(const char *name, const char *value, const Place place = Place::All) :
+ _name(name), _value(value), _orig_empty(true), _place(place) {}
+
+ /**
+ * Constructors for bool values
+ *
+ * @param name Name of the php.ini variable
+ * @param value Default value
+ * @param orig Original value (if the user resets the variable, it is set back to this value)
+ * @param place Place where the ini setting can be changed
+ */
+ Ini(const char *name,const bool value, const bool orig, const Place place = Place::All) :
+ _name(name), _value(bool2str(value)), _orig(bool2str(orig)), _place(place) {}
+
+ Ini(const char *name, const bool value, const Place place = Place::All) :
+ _name(name), _value(bool2str(value)), _orig_empty(true), _place(place) {}
+
+ /**
+ * Constructors for integer values
+ *
+ * @param name Name of the php.ini variable
+ * @param value Default value
+ * @param orig Original value (if the user resets the variable, it is set back to this value)
+ * @param place Place where the ini setting can be changed
+ */
+ Ini(const char *name, const int16_t value, const int16_t orig, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig(std::to_string(orig)), _place(place) {}
+
+ Ini(const char *name, const int16_t value, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
+
+ Ini(const char *name, const int32_t value, const int32_t orig, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig(std::to_string(orig)), _place(place) {}
+
+ Ini(const char *name, const int32_t value, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
+
+ Ini(const char *name, const int64_t value, const int64_t orig, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig(std::to_string(orig)), _place(place) {}
+
+ Ini(const char *name, const int64_t value, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
+
+ /**
+ * Constructors for floating point values
+ *
+ * @param name Name of the php.ini variable
+ * @param value Default value
+ * @param orig Original value (if the user resets the variable, it is set back to this value)
+ * @param place Place where the ini setting can be changed
+ */
+ Ini(const char *name, const double value, const double orig, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig(std::to_string(orig)), _place(place) {}
+
+ Ini(const char *name, const double value, const Place place = Place::All) :
+ _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
+
/**
- * Class definition
+ * Filling ini_entries
+ * @param ini_entry
+ * @param module_number
*/
- class Ini
+ void fill(struct _zend_ini_entry *ini_entry, int module_number);
+
+private:
+ /**
+ * Helper function to convert a boolean to a string
+ * @param value
+ * @return string
+ */
+ static constexpr const char* bool2str(const bool value)
{
- public:
-
- /**
- * Supported place-types for ini setting
- * The possible settings for where the configuration can be changed are:
- * PHP_INI_USER, PHP_INI_PERDIR, PHP_INI_SYSTEM and PHP_INI_ALL
- * Usually you would choose where the setting can be changed based on how it is used. For example if you want to access
- * the setting during RINIT stage then you would want PHP_INI_PERDIR because the setting would have no use after RINIT.
- */
- enum Place : int {
- User = (1<<0), // ZEND_INI_USER (1<<0)
- Perdir = (1<<1), // ZEND_INI_PERDIR (1<<1)
- System = (1<<2), // ZEND_INI_SYSTEM (1<<2)
- All = (1<<0) | (1<<1) | (1<<2) // ZEND_INI_ALL (ZEND_INI_USER|ZEND_INI_PERDIR|ZEND_INI_SYSTEM)
- };
-
- /**
- * default constructors
- */
- Ini(const char *name, const char *value, const char *orig_value, const Place place = Place::All) :
- _name(name), _value(value), _orig_value(orig_value), _place(place) {}
-
- Ini(const char *name, const char *value, const Place place = Place::All) :
- _name(name), _value(value), _orig_empty(true), _place(place) {}
-
- /**
- * Constructors for bool value
- */
- Ini(const char *name,const bool value, const bool orig_value, const Place place = Place::All) :
- _name(name), _value(bool2str(value)), _orig_value(bool2str(orig_value)), _place(place) {}
-
- Ini(const char *name, const bool value, const Place place = Place::All) :
- _name(name), _value(bool2str(value)), _orig_empty(true), _place(place) {}
-
- /**
- * Constructors for integer value
- * @param value
- */
- Ini(const char *name, const int16_t value, const int16_t orig_value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_value(std::to_string(orig_value)), _place(place) {}
-
- Ini(const char *name, const int16_t value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
-
-
- Ini(const char *name, const int32_t value, const int32_t orig_value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_value(std::to_string(orig_value)), _place(place) {}
-
- Ini(const char *name, const int32_t value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
-
-
- Ini(const char *name, const int64_t value, const int64_t orig_value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_value(std::to_string(orig_value)), _place(place) {}
-
- Ini(const char *name, const int64_t value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
-
- /**
- * Constructors for float value
- * @param value
- */
- Ini(const char *name, const double value, const double orig_value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_value(std::to_string(orig_value)), _place(place) {}
-
- Ini(const char *name, const double value, const Place place = Place::All) :
- _name(name), _value(std::to_string(value)), _orig_empty(true), _place(place) {}
-
-
- /**
- * Copy constructor
- * @param Ini
- */
- Ini(const Ini &that) :
- _name(that._name), _value(that._value), _orig_value(that._orig_value), _orig_empty(that._orig_empty), _place(that._place)
- {}
-
- /**
- * Move constructor
- * @param Ini
- */
- Ini(Ini &&that) :
- _name(that._name), _value(std::move(that._value)), _orig_value(std::move(that._orig_value)), _orig_empty(that._orig_empty), _place(that._place)
- {}
-
-
- /**
- * Filling ini_entries
- * @param zend_ini_entry *ini_entry, int module_number
- * @param int module_number
- */
- void fill(_zend_ini_entry *ini_entry, int module_number);
-
-
- /**
- * Compare by name
- * A predicate that takes two arguments of type Ini.
- * Used when adding elements of type Ini in the container std::set
- */
- struct Compare
- {
- int operator()(const std::shared_ptr<Ini> &s1, const std::shared_ptr<Ini> &s2) const
- {
- return s1->_name.compare(s2->_name);
- }
- };
-
- private:
-
- static constexpr const char* bool2str(const bool value)
- {
- return ( static_cast<bool>(value) ? "On" : "Off");
- }
-
- // ini entry name
- std::string _name;
-
- // ini entry value
- std::string _value;
-
- // ini entry original value
- std::string _orig_value;
-
- // _orig_value is empty
- bool _orig_empty = false;
-
- // plase where the configuration can be changed
- Place _place;
- };
+ // cast to a string
+ return ( static_cast<bool>(value) ? "On" : "Off");
+ }
+
+ /**
+ * ini entry name
+ * @var std::string
+ */
+ std::string _name;
+
+ /**
+ * ini entry value
+ * @var std::string
+ */
+ std::string _value;
+
+ /**
+ * ini entry original value
+ * @var std::string
+ */
+ std::string _orig;
+
+ /**
+ * Is the orig value set or empty?
+ * @var bool
+ */
+ bool _orig_empty = false;
+
+ /**
+ * Place where the configuration can be changed
+ * @var Place
+ */
+ Place _place;
+};
/**
* End of namespace