summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-14 09:07:19 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-14 09:07:19 +0200
commit792497f731c5c3a93a442bd487bd7ae4e0ffb2bf (patch)
tree4145bb0adaa205a01eb34b50c8ff690729c5d02b /include
parent7df281b04d7286cd1cf7cad55848b6bf4a250c24 (diff)
parent06ca40ff782231f58d629b09004700714d96fa0c (diff)
Merge pull request #82 from valmat/ini
Php::Ini_get()
Diffstat (limited to 'include')
-rw-r--r--include/call.h11
-rw-r--r--include/ini.h2
-rw-r--r--include/inivalue.h134
3 files changed, 146 insertions, 1 deletions
diff --git a/include/call.h b/include/call.h
index 2fcc9b0..f881782 100644
--- a/include/call.h
+++ b/include/call.h
@@ -57,7 +57,16 @@ inline Value echo(const std::string &input) { out << input; return nullptr; }
inline Value empty(const Value &value) { return value.isNull() || !value.boolValue(); }
inline Value empty(const HashMember<std::string> &member) { return !member.exists() || empty(member.value()); }
inline Value empty(const HashMember<int> &member) { return !member.exists() || empty(member.value()); }
-inline Value ini_get(const Value &value) { return call("ini_get", value); }
+
+inline IniValue ini_get(const char* name)
+{
+ return IniValue(name, false);
+}
+inline IniValue ini_get_orig(const char* name)
+{
+ return IniValue(name, true);
+}
+
inline Value is_array(const Value &value) { return value.isArray(); }
inline Value strlen(const Value &value) { return call("strlen", value); }
inline void unset(const HashMember<std::string> &member) { member.unset(); }
diff --git a/include/ini.h b/include/ini.h
index 49587d7..1d881e9 100644
--- a/include/ini.h
+++ b/include/ini.h
@@ -17,6 +17,7 @@ struct _zend_ini_entry;
*/
namespace Php {
+
/**
* Class definition
*/
@@ -117,6 +118,7 @@ public:
*/
void fill(struct _zend_ini_entry *ini_entry, int module_number);
+
private:
/**
* Helper function to convert a boolean to a string
diff --git a/include/inivalue.h b/include/inivalue.h
new file mode 100644
index 0000000..9f2e44c
--- /dev/null
+++ b/include/inivalue.h
@@ -0,0 +1,134 @@
+/**
+ * IniValue.h
+ *
+ * Class IniValue designed for extracting values from ini entries
+ *
+ * @copyright 2014 Copernica BV
+ */
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Class IniValue designed for extracting values from ini entries.
+ */
+class IniValue
+{
+public:
+ /**
+ * Constructors
+ *
+ * @param name Name of the php.ini variable
+ * @param isorig Is the original value
+ */
+ IniValue(const char *name, const bool isorig) : _name(name), _isorig(isorig) {}
+
+ /**
+ * Cast to a number
+ * @return int32_t
+ */
+ operator int16_t () const
+ {
+ return (int16_t)numericValue();
+ }
+
+ /**
+ * Cast to a number
+ * @return int32_t
+ */
+ operator int32_t () const
+ {
+ return (int32_t)numericValue();
+ }
+
+ /**
+ * Cast to a number
+ * @return uint64_t
+ */
+ operator int64_t () const
+ {
+ return numericValue();
+ }
+
+ /**
+ * Cast to a boolean
+ * @return boolean
+ */
+ operator bool () const
+ {
+ return (bool)numericValue();
+ }
+
+ /**
+ * Cast to a string
+ * @return string
+ */
+ operator std::string () const
+ {
+ return rawValue();
+ }
+
+ /**
+ * Cast to byte array
+ * @return const char *
+ */
+ operator const char * () const
+ {
+ return rawValue();
+ }
+
+ /**
+ * Cast to a floating point
+ * @return double
+ */
+ operator double() const;
+
+private:
+
+ /**
+ * Retrieve the value as number
+ *
+ * We force this to be a int64_t because we assume that most
+ * servers run 64 bits nowadays, and because we use int32_t, int64_t
+ * almost everywhere, instead of 'long' and on OSX neither of
+ * these intxx_t types is defined as 'long'...
+ *
+ * @return int64_t
+ */
+ int64_t numericValue() const;
+
+ /**
+ * Get access to the raw buffer for read operationrs.
+ * @return const char *
+ */
+ const char *rawValue() const;
+
+ /**
+ * ini entry name
+ * @var std::string
+ */
+ std::string _name;
+
+ /**
+ * Is the orig value?
+ * @var bool
+ */
+ bool _isorig = false;
+};
+
+/**
+ * Custom output stream operator
+ * @param stream
+ * @param ini_val
+ * @return ostream
+ */
+std::ostream &operator<<(std::ostream &stream, const IniValue &ini_val);
+
+
+/**
+ * End of namespace
+ */
+}
+