summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-04-14 00:36:01 +0600
committervalmat <ufabiz@gmail.com>2014-04-14 00:36:01 +0600
commit06ca40ff782231f58d629b09004700714d96fa0c (patch)
tree4145bb0adaa205a01eb34b50c8ff690729c5d02b
parente6660c521ea5d03e0caffa2a1f69e6e28982ab8b (diff)
Separated class IniValue from class Ini
Also replaced Ini::get() on ini_get() see https://github.com/CopernicaMarketingSoftware/PHP-CPP/issues/64#issuecomment-40313791
-rw-r--r--include/call.h11
-rw-r--r--include/ini.h128
-rw-r--r--include/inivalue.h134
-rw-r--r--phpcpp.h1
-rw-r--r--tests/cpp/include/ini_entries/001.h8
-rw-r--r--tests/cpp/main.cpp5
-rw-r--r--zend/includes.h1
-rw-r--r--zend/ini.cpp39
-rw-r--r--zend/inivalue.cpp59
9 files changed, 211 insertions, 175 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 8745fef..1d881e9 100644
--- a/include/ini.h
+++ b/include/ini.h
@@ -17,123 +17,6 @@ struct _zend_ini_entry;
*/
namespace Php {
-/**
- * Class IniValue designed for extracting values from ini entries.
- */
-class IniValue
-{
-public:
- /**
- * Constructors for floating point values
- *
- * @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);
-
/**
* Class definition
@@ -235,17 +118,6 @@ public:
*/
void fill(struct _zend_ini_entry *ini_entry, int module_number);
-
- static IniValue get(const char* name)
- {
- return IniValue(name, false);
- }
-
- static IniValue get_orig(const char* name)
- {
- return IniValue(name, true);
- }
-
private:
/**
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
+ */
+}
+
diff --git a/phpcpp.h b/phpcpp.h
index 4e9735d..3f94cef 100644
--- a/phpcpp.h
+++ b/phpcpp.h
@@ -26,6 +26,7 @@
/**
* Include all headers files that are related to this library
*/
+#include <phpcpp/inivalue.h>
#include <phpcpp/ini.h>
#include <phpcpp/exception.h>
#include <phpcpp/streams.h>
diff --git a/tests/cpp/include/ini_entries/001.h b/tests/cpp/include/ini_entries/001.h
index 440944c..ece2aa4 100644
--- a/tests/cpp/include/ini_entries/001.h
+++ b/tests/cpp/include/ini_entries/001.h
@@ -23,10 +23,10 @@ namespace TestIniEntries {
Ini::get("ini1")
*/
- Php::out << "Ini::get(ini1) = {{" << Php::Ini::get("ini1") << " | " << Php::Ini::get_orig("ini1") << "}}" << std::endl;
- Php::out << "Ini::get(ini2) = {{" << Php::Ini::get("ini2") << " | " << Php::Ini::get_orig("ini2") << "}}" << std::endl;
- Php::out << "Ini::get(ini3) = {{" << Php::Ini::get("ini3") << " | " << Php::Ini::get_orig("ini3") << "}}" << std::endl;
- Php::out << "Ini::get(ini4) = {{" << Php::Ini::get("ini4") << " | " << Php::Ini::get_orig("ini4") << "}}" << std::endl;
+ Php::out << "ini_get(ini1) = {{" << Php::ini_get("ini1") << " | " << Php::ini_get_orig("ini1") << "}}" << std::endl;
+ Php::out << "ini_get(ini2) = {{" << Php::ini_get("ini2") << " | " << Php::ini_get_orig("ini2") << "}}" << std::endl;
+ Php::out << "ini_get(ini3) = {{" << Php::ini_get("ini3") << " | " << Php::ini_get_orig("ini3") << "}}" << std::endl;
+ Php::out << "ini_get(ini4) = {{" << Php::ini_get("ini4") << " | " << Php::ini_get_orig("ini4") << "}}" << std::endl;
/*
Php::out << "extension_for_tests.some_string ={{" << Php::ini_get("extension_for_tests.some_string") << "}}" << std::endl;
Php::out << "extension_for_tests.some_string2 ={{" << Php::ini_get("extension_for_tests.some_string2") << "}}" << std::endl;
diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp
index 5fd3d87..0f36ecc 100644
--- a/tests/cpp/main.cpp
+++ b/tests/cpp/main.cpp
@@ -155,9 +155,8 @@ extern "C"
extension.add("TestIniEntries\\iniTest1", TestIniEntries::iniTest1);
extension.onStartup([](){
- Php::out << "Ini::get(ini1) = {{" << Php::Ini::get("ini1") << " | " << Php::Ini::get_orig("ini1") << "}}" << std::endl;
- Php::out << "Ini::get(ini2) = {{" << Php::Ini::get("ini2") << " | " << Php::Ini::get_orig("ini2") << "}}" << std::endl;
- //Php::out << "Ini::get(ini2) = {{" << Php::ini_get("ini2") << "}}" << std::endl; // <-- Error. Php core not loaded yet.
+ Php::out << "ini_get(ini1) = {{" << Php::ini_get("ini1") << " | " << Php::ini_get_orig("ini1") << "}}" << std::endl;
+ Php::out << "ini_get(ini2) = {{" << Php::ini_get("ini2") << " | " << Php::ini_get_orig("ini2") << "}}" << std::endl;
});
diff --git a/zend/includes.h b/zend/includes.h
index 4aa5eb0..cabb096 100644
--- a/zend/includes.h
+++ b/zend/includes.h
@@ -45,6 +45,7 @@
/**
* Include other files from this library
*/
+#include "../include/inivalue.h"
#include "../include/ini.h"
#include "../include/exception.h"
#include "../include/streams.h"
diff --git a/zend/ini.cpp b/zend/ini.cpp
index 8a6fe11..889e388 100644
--- a/zend/ini.cpp
+++ b/zend/ini.cpp
@@ -50,45 +50,6 @@ void Ini::fill(zend_ini_entry *ini_entry, int module_number)
/**
- * Cast to a number
- * @return uint64_t
- */
-int64_t IniValue::numericValue() const
-{
- return zend_ini_long(const_cast<char*>(_name.c_str()), _name.size()+1, _isorig);
-
-}
-
-/**
- * Get access to the raw buffer for read operationrs.
- * @return const char *
- */
-const char* IniValue::rawValue() const
-{
- return zend_ini_string(const_cast<char*>(_name.c_str()), _name.size()+1, _isorig);
-}
-
-/**
- * Cast to a floating point
- * @return double
- */
-IniValue::operator double() const
-{
- return zend_ini_double(const_cast<char*>(_name.c_str()), _name.size()+1, _isorig);
-}
-
-/**
- * Custom output stream operator
- * @param stream
- * @param ini_val
- * @return ostream
- */
-std::ostream &operator<<(std::ostream &stream, const IniValue &ini_val)
-{
- return stream << static_cast<const char*>(ini_val);
-}
-
-/**
* End of namespace
*/
}
diff --git a/zend/inivalue.cpp b/zend/inivalue.cpp
new file mode 100644
index 0000000..f89dcd2
--- /dev/null
+++ b/zend/inivalue.cpp
@@ -0,0 +1,59 @@
+/**
+ * IniValue.cpp
+ *
+ * Class IniValue designed for extracting values from ini entries
+ *
+ * @copyright 2013 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Cast to a number
+ * @return uint64_t
+ */
+int64_t IniValue::numericValue() const
+{
+ return zend_ini_long(const_cast<char*>(_name.c_str()), _name.size()+1, _isorig);
+
+}
+
+/**
+ * Get access to the raw buffer for read operationrs.
+ * @return const char *
+ */
+const char* IniValue::rawValue() const
+{
+ return zend_ini_string(const_cast<char*>(_name.c_str()), _name.size()+1, _isorig);
+}
+
+/**
+ * Cast to a floating point
+ * @return double
+ */
+IniValue::operator double() const
+{
+ return zend_ini_double(const_cast<char*>(_name.c_str()), _name.size()+1, _isorig);
+}
+
+/**
+ * Custom output stream operator
+ * @param stream
+ * @param ini_val
+ * @return ostream
+ */
+std::ostream &operator<<(std::ostream &stream, const IniValue &ini_val)
+{
+ return stream << static_cast<const char*>(ini_val);
+}
+
+/**
+ * End of namespace
+ */
+}
+
+