diff options
44 files changed, 635 insertions, 650 deletions
@@ -1,11 +1,11 @@ # # PHP-CPP Makefile # -# This makefile has a user friendly order: the top part of this file contains +# This makefile has a user friendly order: the top part of this file contains # all variable settings that you may alter to suit your own system, while at # the bottom you will find instructions for the compiler in which you will # probably not have to make any changes -# +# # # Php-config utility @@ -13,9 +13,9 @@ # PHP comes with a standard utility program called 'php-config'. This program # can be used to find out in which directories PHP is installed. Inside this # makefile this utility program is used to find include directories, shared -# libraries and the path to the binary file. If your php-config is not +# libraries and the path to the binary file. If your php-config is not # installed in the default directory, you can change that here. -# +# PHP_CONFIG = php-config @@ -35,12 +35,12 @@ PHP_BIN = $(shell ${PHP_CONFIG} --php-binary) # # Installation directory # -# When you install the PHP-CPP library, it will place a number of C++ *.h +# When you install the PHP-CPP library, it will place a number of C++ *.h # header files in your system include directory, and a libphpcpp.so shared # library file in your system libraries directory. Most users set this to # the regular /usr/include and /usr/lib directories, or /usr/local/include # and /usr/local/lib. You can of course change it to whatever suits you best -# +# INSTALL_PREFIX = /usr INSTALL_HEADERS = ${INSTALL_PREFIX}/include @@ -65,7 +65,7 @@ HHVM_STATIC_LIBRARY = libhhvmcpp.a # Compiler # # By default, the GNU C++ compiler is used. If you want to use a different -# compiler, you can change that here. You can change this for both the +# compiler, you can change that here. You can change this for both the # compiler (the program that turns the c++ files into object files) and for # the linker (the program that links all object files into a single .so # library file. By default, g++ (the GNU C++ compiler) is used for both. @@ -88,16 +88,16 @@ endif # # Compiler flags # -# This variable holds the flags that are passed to the compiler. By default, -# we include the -O2 flag. This flag tells the compiler to optimize the code, -# but it makes debugging more difficult. So if you're debugging your application, -# you probably want to remove this -O2 flag. At the same time, you can then +# This variable holds the flags that are passed to the compiler. By default, +# we include the -O2 flag. This flag tells the compiler to optimize the code, +# but it makes debugging more difficult. So if you're debugging your application, +# you probably want to remove this -O2 flag. At the same time, you can then # add the -g flag to instruct the compiler to include debug information in # the library (but this will make the final libphpcpp.so file much bigger, so # you want to leave that flag out on production servers). # -COMPILER_FLAGS = -Wall -c -g -std=c++11 +COMPILER_FLAGS = -Wall -c -g -std=c++11 -fvisibility=hidden -DBUILDING_PHPCPP SHARED_COMPILER_FLAGS = -fpic STATIC_COMPILER_FLAGS = PHP_COMPILER_FLAGS = ${COMPILER_FLAGS} `${PHP_CONFIG} --includes` @@ -121,7 +121,7 @@ HHVM_LINKER_FLAGS = ${LINKER_FLAGS} # # Command to remove files, copy files and create directories. # -# I've never encountered a *nix environment in which these commands do not work. +# I've never encountered a *nix environment in which these commands do not work. # So you can probably leave this as it is # @@ -134,7 +134,7 @@ MKDIR = mkdir -p # The source files # # For this we use a special Makefile function that automatically scans the -# common/, zend/ and hhvm/ directories for all *.cpp files. No changes are +# common/, zend/ and hhvm/ directories for all *.cpp files. No changes are # probably necessary here # @@ -146,8 +146,8 @@ HHVM_SOURCES = $(wildcard hhvm/*.cpp) # The object files # # The intermediate object files are generated by the compiler right before -# the linker turns all these object files into the libphpcpp.so and -# libhhvmcpp.so shared libraries. We also use a Makefile function here that +# the linker turns all these object files into the libphpcpp.so and +# libhhvmcpp.so shared libraries. We also use a Makefile function here that # takes all source files. # @@ -201,22 +201,22 @@ clean: ${RM} static ${PHP_STATIC_LIBRARY} ${HHVM_STATIC_LIBRARY} find -name *.o | xargs ${RM} -${COMMON_SHARED_OBJECTS}: +${COMMON_SHARED_OBJECTS}: ${COMPILER} ${COMPILER_FLAGS} ${SHARED_COMPILER_FLAGS} -o $@ ${@:shared/%.o=%.cpp} -${COMMON_STATIC_OBJECTS}: +${COMMON_STATIC_OBJECTS}: ${COMPILER} ${COMPILER_FLAGS} ${STATIC_COMPILER_FLAGS} -o $@ ${@:static/%.o=%.cpp} -${PHP_SHARED_OBJECTS}: +${PHP_SHARED_OBJECTS}: ${COMPILER} ${PHP_COMPILER_FLAGS} ${SHARED_COMPILER_FLAGS} -o $@ ${@:shared/%.o=%.cpp} -${PHP_STATIC_OBJECTS}: +${PHP_STATIC_OBJECTS}: ${COMPILER} ${PHP_COMPILER_FLAGS} ${STATIC_COMPILER_FLAGS} -o $@ ${@:static/%.o=%.cpp} -${HHVM_SHARED_OBJECTS}: +${HHVM_SHARED_OBJECTS}: ${COMPILER} ${HHVM_COMPILER_FLAGS} ${SHARED_COMPILER_FLAGS} -o $@ ${@:shared/%.o=%.cpp} -${HHVM_STATIC_OBJECTS}: +${HHVM_STATIC_OBJECTS}: ${COMPILER} ${HHVM_COMPILER_FLAGS} ${STATIC_COMPILER_FLAGS} -o $@ ${@:static/%.o=%.cpp} install: diff --git a/common/includes.h b/common/includes.h index db29f10..437f73e 100644 --- a/common/includes.h +++ b/common/includes.h @@ -15,6 +15,7 @@ /** * Public include files */ +#include "../include/visibility.h" #include "../include/modifiers.h" /** diff --git a/include/argument.h b/include/argument.h index f45a43a..747f7a8 100644 --- a/include/argument.h +++ b/include/argument.h @@ -6,7 +6,7 @@ * * The constructor of the argument is protected. Use the ByVal or ByRef * classes instead. - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2013, 2014 Copernica BV */ @@ -19,14 +19,14 @@ namespace Php { /** * Class definition */ -class Argument +class PHPCPP_EXPORT Argument { public: /** * Destructor */ virtual ~Argument() {} - + protected: /** * Constructor @@ -35,9 +35,9 @@ protected: * @param required Is this argument required? * @param byref Is this a reference argument */ - Argument(const char *name, Type type, bool required = true, bool byref = false) : + Argument(const char *name, Type type, bool required = true, bool byref = false) : _name(name), _type(type), _required(required), _byReference(byref) {} - + /** * Constructor * @param name Name of the argument @@ -48,7 +48,7 @@ protected: */ Argument(const char *name, const char *classname, bool nullable = true, bool required = true, bool byref = false) : _name(name), _type(Type::Object), _classname(classname), _nullable(nullable), _required(required), _byReference(byref) {} - + public: /** * Is this a required argument? @@ -59,7 +59,7 @@ public: { return _required; } - + /** * Name of the argument * @return const char * @@ -68,8 +68,8 @@ public: { return _name; } - - /** + + /** * Type-hint for the argument * @return Type */ @@ -77,7 +77,7 @@ public: { return _type; } - + /** * If the type is a class, the name of the class * @return const char * @@ -86,7 +86,7 @@ public: { return _classname; } - + /** * Is it allowed to pass parameter with a null value? * @return bool @@ -95,7 +95,7 @@ public: { return _nullable; } - + /** * Is this a parameter-by-reference? * @return bool @@ -104,14 +104,14 @@ public: { return _byReference; } - + private: /** * Name of the argument * @var const char * */ const char *_name = nullptr; - + /** * Type of argument * @var Type @@ -123,7 +123,7 @@ private: * @var std::string */ const char *_classname = nullptr; - + /** * May the parameter be null? * @var bool @@ -135,7 +135,7 @@ private: * @var bool */ bool _required = true; - + /** * Is this a 'by-reference' parameter? * @var bool @@ -156,7 +156,7 @@ using Arguments = std::vector<Argument>; /** * Other compilers, and visual C++ 2013 do support initializer lists */ -#else +#else /** * A list of arguments can be supplied to methods @@ -169,9 +169,8 @@ using Arguments = std::initializer_list<Argument>; */ #endif - + /** * End of namespace */ } - diff --git a/include/array.h b/include/array.h index 02fe4c4..c4250d4 100644 --- a/include/array.h +++ b/include/array.h @@ -1,7 +1,7 @@ /** * Array.h * - * The Array is a wrapper around the value class that ensures that a + * The Array is a wrapper around the value class that ensures that a * certain property always is an array * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> @@ -16,19 +16,19 @@ namespace Php { /** * Class definition */ -class Array : public Value +class PHPCPP_EXPORT Array : public Value { public: /** * Constructor */ Array() : Value(Type::Array) {} - + /** * Copy constructor from a value object * @param value */ - Array(const Value &value) : Value(value) + Array(const Value &value) : Value(value) { // type must be valid if (value.type() != Type::Array) throw FatalError("Assigning a non-array to an array variable"); @@ -50,7 +50,7 @@ public: */ template <typename T> Array(const std::vector<T> &input) : Value(input) {} - + /** * Constructor from a map (this will create an associative array) * @param value @@ -68,8 +68,8 @@ public: Array(const std::initializer_list<Value> &value) : Value(value) {} // end of visual c++ check -# endif - +# endif + /** * Destructor */ @@ -83,11 +83,11 @@ public: { // throw exception if things are going wrong if (type != Type::Array) throw FatalError("Changing type of a fixed array variable"); - + // call base return Value::setType(Type::Array); } - + /** * Assignment operator * @param value @@ -97,17 +97,17 @@ public: { // skip self assignment if (this == &value) return *this; - + // type must be valid if (value.type() != Type::Array) throw FatalError("Assigning a non-array to a fixed array variable"); - + // call base Value::operator=(value); // done return *this; } - + /** * Move assignment operator * @param value @@ -117,13 +117,13 @@ public: { // skip self assignment if (this == &value) return *this; - + // type must be valid if (value.type() != Type::Array) throw FatalError("Moving a non-array to a fixed array variable"); - + // call base Value::operator=(std::move(value)); - + // done return *this; } @@ -133,4 +133,3 @@ public: * End of namespace */ } - diff --git a/include/arrayaccess.h b/include/arrayaccess.h index cf8c261..4cb936f 100644 --- a/include/arrayaccess.h +++ b/include/arrayaccess.h @@ -1,11 +1,11 @@ /** * ArrayAccess.h - * + * * "Interface" that can be "implemented" by your class. If you do, you * create your class like this: - * + * * class MyClass : public Php::Base, public Php::ArrayAccess { ... } - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2014 Copernica BV */ @@ -14,11 +14,11 @@ * Set up namespace */ namespace Php { - + /** * Class definition */ -class ArrayAccess +class PHPCPP_EXPORT ArrayAccess { public: /** @@ -27,30 +27,29 @@ public: * @return bool */ virtual bool offsetExists(const Php::Value &key) = 0; - + /** * Set a member * @param key * @param value */ virtual void offsetSet(const Php::Value &key, const Php::Value &value) = 0; - + /** * Retrieve a member * @param key * @return value */ virtual Php::Value offsetGet(const Php::Value &key) = 0; - + /** * Remove a member * @param key */ virtual void offsetUnset(const Php::Value &key) = 0; }; - + /** * End namespace */ } - diff --git a/include/base.h b/include/base.h index 417aef0..1a1643b 100644 --- a/include/base.h +++ b/include/base.h @@ -19,7 +19,7 @@ class ObjectImpl; /** * Class definition */ -class Base +class PHPCPP_EXPORT Base { private: /** @@ -27,7 +27,7 @@ private: * @var ObjectImpl */ ObjectImpl *_impl = nullptr; - + protected: /** * Constructor @@ -36,16 +36,16 @@ protected: /** * Copy constructor - * + * * This copy constructor is explicitly defined to make sure that the * copied object does not already have an implementation in the zend engine. * Otherwise the copied object has the same object handle as the original * object. - * + * * @param base */ Base(const Base &base) : _impl(nullptr) {} - + public: /** * Virtual destructor @@ -71,7 +71,7 @@ public: { return Value(this)[name]; } - + /** * Retrieve a property by name * @param string @@ -81,7 +81,7 @@ public: { return Value(this)[name]; } - + /** * Retrieve a property by name * @param string @@ -111,7 +111,7 @@ public: { return Value(this).get(name); } - + /** * Retrieve a property by name * @param string @@ -121,7 +121,7 @@ public: { return Value(this).get(name); } - + /** * Retrieve a property by name * @param string @@ -131,7 +131,7 @@ public: { return Value(this).get(name); } - + /** * Overridable method that is called right before an object is destructed */ @@ -139,61 +139,61 @@ public: /** * Overridable method that is called right after an object is cloned - * + * * The default implementation does nothing */ void __clone() const {} - + /** * Overridable method that is called to check if a property is set - * + * * The default implementation does nothing, and the script will fall back * to accessing the regular object properties - * + * * @param key * @return bool */ bool __isset(const Php::Value &key) const; - + /** * Overridable method that is called to set a new property - * + * * The default implementation does nothing, and the script will fall back * to accessing the regular object properties - * + * * @param key * @param value */ void __set(const Php::Value &key, const Php::Value &value) const; - + /** * Retrieve a property - * + * * The default implementation does nothing, and the script will fall back * to accessing the regular object properties - * + * * @param key * @return value */ Php::Value __get(const Php::Value &key) const; - + /** * Remove a member - * + * * The default implementation does nothing, and the script will fall back * to accessing the regular object properties - * + * * @param key */ void __unset(const Php::Value &key) const; /** * Call a method - * + * * This method is called when a method is called from the PHP script that * was not explicitly defined. You can use this to catch variable method * names, or to support all thinkable method names. - * + * * @param method Name of the method that was called * @param params The parameters that were passed to the function * @return Value The return value @@ -202,65 +202,65 @@ public: /** * Call the class as if it was a function - * + * * This method is called when a an object is used with () operators: * $object(). You can override this method to make objects callable. - * + * * @param params The parameters that were passed to the function * @return Value The return value */ Php::Value __invoke(Php::Parameters ¶ms) const; - + /** * Cast the object to a string - * + * * This method is called when an object is casted to a string, or when * it is used in a string context - * + * * @return Value The object as a string */ Php::Value __toString() const; - + /** * Cast the object to an integer - * + * * This method is called when an object is casted to an integer, or when * it is used in an integer context - * + * * @return int Integer value */ Php::Value __toInteger() const; - + /** * Cast the object to a float - * + * * This method is called when an object is casted to a float, or when it * is used in a float context - * + * * @return double Floating point value */ Php::Value __toFloat() const; - + /** * Cast the object to a boolean - * + * * This method is called when an object is casted to a bool, or when it * is used in a boolean context - * + * * @return bool */ Value __toBool() const; /** * Compare the object with a different object - * + * * Check how a different object compares to this object - * + * * @param that Object to compare with * @return int */ int __compare(const Base &base) const; - + private: /** @@ -284,4 +284,3 @@ private: * End of namespace */ } - diff --git a/include/byref.h b/include/byref.h index 07e2e21..8d38077 100644 --- a/include/byref.h +++ b/include/byref.h @@ -15,7 +15,7 @@ namespace Php { /** * Class definition */ -class ByRef : public Argument +class PHPCPP_EXPORT ByRef : public Argument { public: /** @@ -57,4 +57,3 @@ public: * End of namespace */ } - diff --git a/include/byval.h b/include/byval.h index 38c5280..ad0126b 100644 --- a/include/byval.h +++ b/include/byval.h @@ -15,7 +15,7 @@ namespace Php { /** * Class definition */ -class ByVal : public Argument +class PHPCPP_EXPORT ByVal : public Argument { public: /** @@ -57,4 +57,3 @@ public: * End of namespace */ } - diff --git a/include/call.h b/include/call.h index e339ece..36574ce 100644 --- a/include/call.h +++ b/include/call.h @@ -15,38 +15,38 @@ namespace Php { /** * List of functions that are available for use in PHP */ -extern bool class_exists(const char *classname, size_t size, bool autoload = true); -inline bool class_exists(const char *classname, bool autoload = true) { return class_exists(classname, strlen(classname), autoload); } -inline bool class_exists(const std::string &classname, bool autoload = true) { return class_exists(classname.c_str(), classname.size(), autoload); } -extern Value constant(const char *constant); -extern Value constant(const char *constant, size_t size); -extern Value constant(const std::string &constant); -extern bool define(const char *name, size_t size, const Value &value); -extern bool define(const char *name, const Value &value); -extern bool define(const std::string &name, const Value &value); -extern bool defined(const char *constant); -extern bool defined(const char *constant, size_t size); -extern bool defined(const std::string &constant); -extern bool dl(const char *filename); -inline bool dl(const std::string &filename) { return dl(filename.c_str()); } -inline bool dl(const Value &filename) { return dl(filename.rawValue()); } -extern Value eval(const char *phpCode); -inline Value eval(const std::string &phpCode) { return eval(phpCode.c_str()); } -extern Value include(const char *filename); -inline Value include(const std::string &filename) { return include(filename.c_str()); } -extern Value include_once(const char *filename); -inline Value include_once(const std::string &filename) { return include_once(filename.c_str()); } -inline bool is_a(const Value &obj, const char *classname, size_t size, bool allow_string = false) { return obj.instanceOf(classname, size, allow_string); } -inline bool is_a(const Value &obj, const char *classname, bool allow_string = false) { return is_a(obj, classname, strlen(classname), allow_string); } -inline bool is_a(const Value &obj, const std::string &classname, bool allow_string = false) { return is_a(obj, classname.c_str(), classname.size(), allow_string); } -inline bool is_subclass_of(const Value &obj, const char *classname, size_t size, bool allow_string = true) { return obj.derivedFrom(classname, size, allow_string); } -inline bool is_subclass_of(const Value &obj, const char *classname, bool allow_string = true) { return is_subclass_of(obj, classname, strlen(classname), allow_string); } -inline bool is_subclass_of(const Value &obj, const std::string &classname, bool allow_string = true) { return is_subclass_of(obj, classname.c_str(), classname.size(), allow_string); } -extern Value require(const char *filename); -inline Value require(const std::string &filename) { return require(filename.c_str()); } -extern Value require_once(const char *filename); -inline Value require_once(const std::string &filename) { return require_once(filename.c_str()); } -extern const char *sapi_name(); +extern PHPCPP_EXPORT bool class_exists(const char *classname, size_t size, bool autoload = true); +inline PHPCPP_EXPORT bool class_exists(const char *classname, bool autoload = true) { return class_exists(classname, strlen(classname), autoload); } +inline PHPCPP_EXPORT bool class_exists(const std::string &classname, bool autoload = true) { return class_exists(classname.c_str(), classname.size(), autoload); } +extern PHPCPP_EXPORT Value constant(const char *constant); +extern PHPCPP_EXPORT Value constant(const char *constant, size_t size); +extern PHPCPP_EXPORT Value constant(const std::string &constant); +extern PHPCPP_EXPORT bool define(const char *name, size_t size, const Value &value); +extern PHPCPP_EXPORT bool define(const char *name, const Value &value); +extern PHPCPP_EXPORT bool define(const std::string &name, const Value &value); +extern PHPCPP_EXPORT bool defined(const char *constant); +extern PHPCPP_EXPORT bool defined(const char *constant, size_t size); +extern PHPCPP_EXPORT bool defined(const std::string &constant); +extern PHPCPP_EXPORT bool dl(const char *filename); +inline PHPCPP_EXPORT bool dl(const std::string &filename) { return dl(filename.c_str()); } +inline PHPCPP_EXPORT bool dl(const Value &filename) { return dl(filename.rawValue()); } +extern PHPCPP_EXPORT Value eval(const char *phpCode); +inline PHPCPP_EXPORT Value eval(const std::string &phpCode) { return eval(phpCode.c_str()); } +extern PHPCPP_EXPORT Value include(const char *filename); +inline PHPCPP_EXPORT Value include(const std::string &filename) { return include(filename.c_str()); } +extern PHPCPP_EXPORT Value include_once(const char *filename); +inline PHPCPP_EXPORT Value include_once(const std::string &filename) { return include_once(filename.c_str()); } +inline PHPCPP_EXPORT bool is_a(const Value &obj, const char *classname, size_t size, bool allow_string = false) { return obj.instanceOf(classname, size, allow_string); } +inline PHPCPP_EXPORT bool is_a(const Value &obj, const char *classname, bool allow_string = false) { return is_a(obj, classname, strlen(classname), allow_string); } +inline PHPCPP_EXPORT bool is_a(const Value &obj, const std::string &classname, bool allow_string = false) { return is_a(obj, classname.c_str(), classname.size(), allow_string); } +inline PHPCPP_EXPORT bool is_subclass_of(const Value &obj, const char *classname, size_t size, bool allow_string = true) { return obj.derivedFrom(classname, size, allow_string); } +inline PHPCPP_EXPORT bool is_subclass_of(const Value &obj, const char *classname, bool allow_string = true) { return is_subclass_of(obj, classname, strlen(classname), allow_string); } +inline PHPCPP_EXPORT bool is_subclass_of(const Value &obj, const std::string &classname, bool allow_string = true) { return is_subclass_of(obj, classname.c_str(), classname.size(), allow_string); } +extern PHPCPP_EXPORT Value require(const char *filename); +inline PHPCPP_EXPORT Value require(const std::string &filename) { return require(filename.c_str()); } +extern PHPCPP_EXPORT Value require_once(const char *filename); +inline PHPCPP_EXPORT Value require_once(const std::string &filename) { return require_once(filename.c_str()); } +extern PHPCPP_EXPORT const char *sapi_name(); /** * Call a function in PHP @@ -60,51 +60,51 @@ Value call(const char *name, Params&&... params) // the name can be turned into a Php::Value object, which implements // the operator () method to call it Value function(name); - + // invoke the operator () return function(std::forward<Params>(params)...); } /** * Long list of simply-forwarded function calls - * + * * Most functions in this list are forwarded to the call() method described - * above, which of course is slower than necessary, because they will have to + * above, which of course is slower than necessary, because they will have to * pass the entire zend engine to look up the actual implementation, while a - * direct call the C implementation was possible too. The reason for this is + * direct call the C implementation was possible too. The reason for this is * that we are lazy - if you feel like looking up the actual implementation for * each function in the PHP source, your support is more than welcome. - * + * * But since it is a stupid idea to call a PHP function from your extension * anyway (that's what people write extension for: to get away from PHP and * make the code run on the highway), it is not expected that these functions * are going to be used very often anyway. */ -inline Value array_key_exists(const Value &key, const Value &array) { return array.contains(key); } -inline Value array_key_exists(int key, const Value &array) { return array.contains(key); } -inline Value array_key_exists(const char *key, const Value &array) { return array.contains(key); } -inline Value array_key_exists(const std::string &key, const Value &array) { return array.contains(key); } -inline Value array_keys(const Value &value) { return call("array_keys", value); } -inline Value array_push(const Value &array, const Value &value) { return call("array_push", array, value); } -inline Value array_values(const Value &value) { return call("array_values", value); } -inline Value count(const Value &value) { return call("count", value); } -inline Value echo(const char *input) { out << input; return nullptr; } -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 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(); } -inline void unset(const HashMember<int> &member) { member.unset(); } -inline void unset(const HashMember<Value> &member) { member.unset(); } +inline PHPCPP_EXPORT Value array_key_exists(const Value &key, const Value &array) { return array.contains(key); } +inline PHPCPP_EXPORT Value array_key_exists(int key, const Value &array) { return array.contains(key); } +inline PHPCPP_EXPORT Value array_key_exists(const char *key, const Value &array) { return array.contains(key); } +inline PHPCPP_EXPORT Value array_key_exists(const std::string &key, const Value &array) { return array.contains(key); } +inline PHPCPP_EXPORT Value array_keys(const Value &value) { return call("array_keys", value); } +inline PHPCPP_EXPORT Value array_push(const Value &array, const Value &value) { return call("array_push", array, value); } +inline PHPCPP_EXPORT Value array_values(const Value &value) { return call("array_values", value); } +inline PHPCPP_EXPORT Value count(const Value &value) { return call("count", value); } +inline PHPCPP_EXPORT Value echo(const char *input) { out << input; return nullptr; } +inline PHPCPP_EXPORT Value echo(const std::string &input) { out << input; return nullptr; } +inline PHPCPP_EXPORT Value empty(const Value &value) { return value.isNull() || !value.boolValue(); } +inline PHPCPP_EXPORT Value empty(const HashMember<std::string> &member) { return !member.exists() || empty(member.value()); } +inline PHPCPP_EXPORT Value empty(const HashMember<int> &member) { return !member.exists() || empty(member.value()); } +inline PHPCPP_EXPORT Value is_array(const Value &value) { return value.isArray(); } +inline PHPCPP_EXPORT Value strlen(const Value &value) { return call("strlen", value); } +inline PHPCPP_EXPORT void unset(const HashMember<std::string> &member) { member.unset(); } +inline PHPCPP_EXPORT void unset(const HashMember<int> &member) { member.unset(); } +inline PHPCPP_EXPORT void unset(const HashMember<Value> &member) { member.unset(); } /** * The 'ini_get' function returns an IniValue, so that it can also be used * before the PHP engine is started. */ -inline IniValue ini_get(const char* name) { return IniValue(name, false); } -inline IniValue ini_get_orig(const char* name) { return IniValue(name, true); } +inline PHPCPP_EXPORT IniValue ini_get(const char* name) { return IniValue(name, false); } +inline PHPCPP_EXPORT IniValue ini_get_orig(const char* name) { return IniValue(name, true); } /** @@ -116,10 +116,10 @@ inline IniValue ini_get_orig(const char* name) { return IniValue(name, true); } /** * Define the isset function */ -inline Value isset(const Value &value) { return call("isset", value); } -inline Value isset(const HashMember<std::string> &member) { return member.exists() && isset(member.value()); } -inline Value isset(const HashMember<int> &member) { return member.exists() && isset(member.value()); } -inline Value isset(const HashMember<Value> &member) { return member.exists() && isset(member.value()); } +inline PHPCPP_EXPORT Value isset(const Value &value) { return call("isset", value); } +inline PHPCPP_EXPORT Value isset(const HashMember<std::string> &member) { return member.exists() && isset(member.value()); } +inline PHPCPP_EXPORT Value isset(const HashMember<int> &member) { return member.exists() && isset(member.value()); } +inline PHPCPP_EXPORT Value isset(const HashMember<Value> &member) { return member.exists() && isset(member.value()); } /** * Re-install the ISSET macro diff --git a/include/class.h b/include/class.h index c7ae32a..e92dfc3 100644 --- a/include/class.h +++ b/include/class.h @@ -24,26 +24,26 @@ namespace Php { * Class definition of the class */ template <typename T> -class Class : private ClassBase +class PHPCPP_EXPORT Class : private ClassBase { public: /** * Constructor - * + * * The flags can be a combination of Php::Final and Php::Abstract. * If no flags are set, a regular public class will be formed. - * + * * @param name Name of the class * @param flags Accessibility flags */ Class(const char *name, int flags = 0) : ClassBase(name, flags) {} - + /** * Copy constructor * @param that */ Class(const Class<T> &that) : ClassBase(that) {} - + /** * Move constructor * @param that @@ -54,17 +54,17 @@ public: * Destructor */ virtual ~Class() {} - + /** * Add a regular method to the class - * + * * The method will be accessible as one of the class methods in your PHP * code. When the method is called, it will automatically be forwarded * to the C++ implementation. The flags can be Php::Public, Php::Protected * or Php::Private (using private methods can be useful if you for example * want to make the __construct() function private). The access-modified * flag can be bitwise combined with the flag Php::Final or Php::Abstract). - * + * * @param name Name of the method * @param method The actual method * @param flags Optional flags @@ -90,18 +90,18 @@ public: /** * Add a static method to a class - * - * In C++ a static method is in reality just a plain function, that at - * compile time has access to private properties of the class that it is a - * static member of. - * - * Because a C++ static method is not a real method with a 'this' pointer, + * + * In C++ a static method is in reality just a plain function, that at + * compile time has access to private properties of the class that it is a + * static member of. + * + * Because a C++ static method is not a real method with a 'this' pointer, * it has the same signature as a normal C++ (non-method) function. Therefore, * you can register real static member functions (&MyClass::myMethod) as well * as normal functions (myFunction) as class methods. - * + * * In PHP scripts, such functions will be callable as static class methods - * + * * @param name Name of the method * @param method The actual method * @param flags Optional flags @@ -119,11 +119,11 @@ public: /** * Add an abstract method to the class - * - * This is only meaningful for classes that can be extended. Because the + * + * This is only meaningful for classes that can be extended. Because the * method is abstract, you will not have to pass an implementation. You * can pass in flags to mark the method as protected - * + * * @param name Name of the method * @param flags Optional flags * @param args Argument descriptions @@ -134,13 +134,13 @@ public: /** * Add a property to the class - * + * * Every instance of this class will have this property. The property * can be Php::Public, Php::Protected or Php::Private (altough setting * private properties is odd as the implementation of the class is in CPP, * so why use private properties while the whole implementation is already * hidden) - * + * * @param name Name of the property * @param value Actual default property value * @param flags Optional flags @@ -158,13 +158,13 @@ public: /** * Create a class constant - * + * * The class constant can be used in a php script as "ClassName::CONSTANT_NAME". * It is a good programming practive to only use uppercase characters for * constants. - * + * * This is an alias for adding a class property with the "Php::Const" flag. - * + * * @param name Name of the constant * @param value Constant value * @return Class Same object to allow chaining @@ -174,7 +174,7 @@ public: /** * Add a Php::Constant to a class to use it as a class constant - * + * * @param constant The constant to add * @return Class Same object to allow chaining */ @@ -183,13 +183,13 @@ public: /** * Properties as methods - * + * * This is a smarter way for adding properties to a class. You can define * a property and a method that gets called every time the property is * set or unset. - * + * * If you do not set a setter method, your property will be read-only. - * + * * @param name Name of the property * @param getter The getter method * @param setter The setter method @@ -203,32 +203,32 @@ public: /** * Add a PHP interface to the class - * + * * Note that the interface that you supply must already exist! Therefore * you can only supply interfaces that you created in your own extension. - * + * * @param interface Interface object * @return Class Same object to allow chaining */ Class<T> &implements(const Interface &interface) { ClassBase::implements(interface); return *this; } - + /** * Add a base class - * + * * Because PHP does not allow multiple inheritance, you can only add one * base class. If you call this method more than once, the earlier base * class is overridden. - * + * * The base class that you supply must already be registered. And because * your extension is most likely registered before any user space PHP scripts * run, you can only specify classes that you created in your own extension. - * + * * @param base Php::Class object * @return Class Same object to allow chaining */ template<typename CLASS> Class<T> &extends(const Class<CLASS> &base) { ClassBase::extends(base); return *this; } - + private: /** * Method to create the object if it is default constructable @@ -265,7 +265,7 @@ private: // construct an instance return maybeConstruct<T>(); } - + /** * Method to clone the object if it is copy constructable * @param orig @@ -296,11 +296,11 @@ private: * Is this a clonable class? * @return bool */ - virtual bool clonable() const + virtual bool clonable() const { return std::is_copy_constructible<T>::value; } - + /** * Construct a clone * @param orig @@ -311,7 +311,7 @@ private: // maybe clone it (if the class has a copy constructor) return maybeClone<T>((T*)orig); } - + /** * Is this class traversable? * @return bool @@ -336,11 +336,11 @@ private: * Call the __clone method * @param base */ - virtual void callClone(Base *base) const + virtual void callClone(Base *base) const { // cast to the user object T *object = (T *)base; - + // call the method on the base object return object->__clone(); } @@ -353,7 +353,7 @@ private: { // cast to the user object T *object = (T *)base; - + // call the method on the base object return object->__destruct(); } @@ -369,16 +369,16 @@ private: { // cast to the user object T *object = (T *)base; - + // call the method on the base object return object->__call(name, params); } /** * SFINAE test to check if the __callStatic method is defined - * + * * This type trait checks if the __callStatic method is defined in class T - * + * * @see http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence */ template <typename X> @@ -420,7 +420,7 @@ private: { // this is not implemented notImplemented(); - + // unreachable return nullptr; } @@ -446,7 +446,7 @@ private: { // cast to actual object T *obj = (T *)object; - + // pass on return obj->__invoke(params); } @@ -460,11 +460,11 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on return Value(obj->__toString()).setType(Type::String); } - + /** * Cast to integer function * @param base @@ -474,21 +474,21 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on return Value(obj->__toInteger()).setType(Type::Numeric); } - + /** * Cast to float function * @param base * @return Value */ - virtual Value callToFloat(Base *base) const override + virtual Value callToFloat(Base *base) const override { // cast to actual object T *obj = (T *)base; - + // pass on return Value(obj->__toFloat()).setType(Type::Float); } @@ -502,7 +502,7 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on return Value(obj->__toBool()).setType(Type::Bool); } @@ -518,11 +518,11 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on return obj->__get(name); } - + /** * Function to set/overwrite a property * @param base @@ -533,11 +533,11 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on obj->__set(name, value); } - + /** * Function to remove a property * @param base @@ -547,7 +547,7 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on obj->__unset(name); } @@ -562,7 +562,7 @@ private: { // cast to actual object T *obj = (T *)base; - + // pass on return obj->__isset(name); } @@ -578,29 +578,28 @@ private: // cast to the actual implementation type T *t1 = (T *)object1; T *t2 = (T *)object2; - + // compare the two objects return t1->__compare(*t2); } /** - * Namespaces and the function have access to the private base class, + * Namespaces and the function have access to the private base class, * so that the classes can be registered, and the Functor object needs * this to register the PhpCpp::Functor class. */ friend class Namespace; friend class Functor; - + /** * All Php::Class<AnyThing> also need access to the base class to * register this class as base class. */ template<typename ANYTHING> friend class Class; - + }; /** * End of namespace */ } - diff --git a/include/classbase.h b/include/classbase.h index 9e53a62..0db0c35 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -6,7 +6,7 @@ * you can not create any instances if this class yourself (and you are not * supposed to do that either). * - * Further more, because this base class is a 'private' base of Class, all + * Further more, because this base class is a 'private' base of Class, all * features of it are normally also inaccessible. * * In other words: it is not meant to be directly used by extension writers. @@ -22,7 +22,7 @@ namespace Php { /** * A couple of predefined native callback functions that can be registered. * These are functions that optional accept a Request and/or Parameters object, - * and that either return void or a Value object. + * and that either return void or a Value object. */ typedef void (*native_callback_0)(); typedef void (*native_callback_1)(Parameters &); @@ -57,7 +57,7 @@ class ClassImpl; /** * Class definition */ -class ClassBase +class PHPCPP_EXPORT ClassBase { protected: /** @@ -66,14 +66,14 @@ protected: * @param flags Class flags */ ClassBase(const char *classname, int flags); - + /** * Protected constructor * @param classname Class name * @param type Class type */ ClassBase(const char *classname, ClassType type); - + public: /** * Copy constructor @@ -115,14 +115,14 @@ public: * @return int */ virtual int callCompare(Base *object1, Base *object2) const { return 1; } - + /** * Call the __clone and __destruct magic methods * @param base */ virtual void callClone(Base *base) const {} virtual void callDestruct(Base *base) const {} - + /** * Call the __call(), __invoke() or __callStatic() method * @param base Object to call on @@ -133,7 +133,7 @@ public: virtual Value callCall(Base *base, const char *name, Parameters ¶ms) const { return nullptr; } virtual Value callInvoke(Base *base, Parameters ¶ms) const { return nullptr; } virtual Value callCallStatic(const char *name, Parameters ¶ms) const { return nullptr; } - + /** * Casting functions * @param base @@ -143,7 +143,7 @@ public: virtual Value callToInteger(Base *base) const { return Value(Type::Numeric); } virtual Value callToFloat(Base *base) const { return Value(Type::Float); } virtual Value callToBool(Base *base) const { return Value(Type::Bool); } - + /** * Function to get and set properties * @param base @@ -155,7 +155,7 @@ public: virtual void callSet(Base *base, const Value &name, const Value &value) const {} virtual void callUnset(Base *base, const Value &name) const {} virtual bool callIsset(Base *base, const Value &name) const { return false; } - + /** * Get access to the implementation object * @return std::shared_ptr @@ -171,14 +171,14 @@ protected: /** * Add a method to the class - * + * * The method will be accessible as one of the class methods in your PHP * code. When the method is called, it will automatically be forwarded * to the C++ implementation. The flags can be Php::Public, Php::Protected * or Php::Private (using private methods can be useful if you for example * want to make the __construct() function private). The access-modified * flag can be bitwise combined with the flag Php::Final or Php::Abstract). - * + * * @param name Name of the method * @param method The actual method * @param flags Optional flags @@ -195,11 +195,11 @@ protected: /** * Add a static method to the class - * + * * Because a C++ static method is just a regular function, that happens to * have access to the private variables of the class at compile time, you * can register any function that matches one of the function signatures - * + * * @param name Name of the method * @param method The actual method * @param flags Optional flags @@ -212,7 +212,7 @@ protected: /** * Add an abstract method to the class - * + * * @param name Name of the method * @param flags Optional flags (like public or protected) * @param args Description of the supported arguments @@ -221,13 +221,13 @@ protected: /** * Add a property to the class - * + * * Every instance of this class will have this property. The property * can be Php::Public, Php::Protected or Php::Private (altough setting * private properties is odd as the implementation of the class is in CPP, * so why use private properties while the whole implementation is already * hidden) - * + * * @param name Name of the property * @param value Actual property value * @param flags Optional flags @@ -273,16 +273,15 @@ private: * @var std::shared_ptr<ClassImpl> */ std::shared_ptr<ClassImpl> _impl; - + /** * Constants can be used as class properties, and need access to private * and protected methods */ friend class ConstantImpl; }; - + /** * End namespace */ } - diff --git a/include/classtype.h b/include/classtype.h index 382a8db..9b6cc9e 100644 --- a/include/classtype.h +++ b/include/classtype.h @@ -14,16 +14,16 @@ namespace Php { /** * Enumeration definition. - * + * * The PHP-CPP library tries to hide the Zend engine internals completely from * the user. Therefore, it does not include any of the Zend header files, nor - * can it refer to the constants defined in the Zend header files. The + * can it refer to the constants defined in the Zend header files. The * following constants have been copied from Zend. If the Zend engine ever * changes (which we do not expect) we should also copy the constant values * used here. - * + * */ -enum class ClassType { +enum class PHPCPP_EXPORT ClassType { Regular = 0x00, Abstract = 0x20, Final = 0x40, diff --git a/include/constant.h b/include/constant.h index 5e18792..0f2b354 100644 --- a/include/constant.h +++ b/include/constant.h @@ -1,13 +1,13 @@ /** * Constant.h - * + * * If you want to define global PHP constants, or class constants you can * use this constant class for it. Wrap the constant you'd like to create * in a Php::Constant object and add it to the extension or the class: - * + * * extension.add(Php::Constant("CONSTANT_NAME", "value")); * myclass.add(Php::Constant("CLASS_CONSTANT", "value")); - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2015 Copernica BV */ @@ -25,7 +25,7 @@ class ConstantImpl; /** * Class definition */ -class Constant +class PHPCPP_EXPORT Constant { public: /** @@ -42,27 +42,27 @@ public: Constant(const char *name, const char *value); Constant(const char *name, const char *value, size_t size); Constant(const char *name, const std::string &value); - + /** * Destructor */ virtual ~Constant() {} - + /** * Add the constant to a class - * + * * You normally do not have to call this method yourself. You can simply * do one of the following method calls to create class constants: - * + * * myclass.property("MY_CONSTANT", "value", Php::Const); * myclass.constant("MY_CONSTANT", "value"); * myclass.add(Php::Constant("MY_CONSTANT", "value")); - * + * * All of the calls have the same result, it is up to you to decide which * one suits you most. If you use the last one - using a Php::Constant * class - the PHP-CPP library will call this "addTo()" method internally * to forward the call to one of the other methods. - * + * * @param clss Class to which the constant is added * @internal */ @@ -80,16 +80,15 @@ private: * @return std::shared_ptr */ const std::shared_ptr<ConstantImpl> &implementation() const { return _impl; } - + /** * The extension object has access to privates */ friend class ExtensionImpl; -}; - +}; + /** * End of namespace */ } - diff --git a/include/countable.h b/include/countable.h index d4c1823..8ff0c61 100644 --- a/include/countable.h +++ b/include/countable.h @@ -1,11 +1,11 @@ /** * Countable.h - * + * * "Interface" that can be "implemented" by your class. If you do, you * create your class like this: - * + * * class MyClass : public Php::Base, public Php::Countable { ... } - * + * * You will have to implement the count() method, which should return the * number of elements in the object * @@ -17,11 +17,11 @@ * Set up namespace */ namespace Php { - + /** * Class definition */ -class Countable +class PHPCPP_EXPORT Countable { public: /** @@ -31,9 +31,8 @@ public: virtual long count() = 0; }; - + /** * End namespace */ } - diff --git a/include/exception.h b/include/exception.h index 15e92bc..55601c2 100644 --- a/include/exception.h +++ b/include/exception.h @@ -1,7 +1,7 @@ /** * Exception.h * Implementation of Php Exceptions. - * + * * @author Jasper van Eck <jasper.vaneck@copernica.com> * @copyright 2013, 2014 Copernica BV */ @@ -12,10 +12,10 @@ */ namespace Php { -/** +/** * Class definition */ -class Exception : public std::exception +class PHPCPP_EXPORT Exception : public std::exception { private: /** @@ -23,31 +23,31 @@ private: * @var char* */ std::string _message; - + /** * The PHP exception code * @var int */ int _code; - + /** * Has this exception been processed by native C++ code? * @var bool */ bool _processed = false; - + public: /** * Constructor * @param &string */ Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code) {} - + /** * Destructor */ virtual ~Exception() throw() {} - + /** * Overridden what method * @return const char * @@ -56,7 +56,7 @@ public: { return _message.c_str(); } - + /** * Returns the message of the exception. * @return &string @@ -75,7 +75,7 @@ public: // yes, it is native return true; } - + /** * Report this error as a fatal error * @return bool @@ -91,5 +91,3 @@ public: * End of namespace */ } - - diff --git a/include/extension.h b/include/extension.h index 15ad5e1..caa3d33 100644 --- a/include/extension.h +++ b/include/extension.h @@ -6,11 +6,11 @@ * apache process starts - and will be used for all subsequent requests that * are handled by Apache. * - * For some environments (for example CLI scripts and CGI calls) only one + * For some environments (for example CLI scripts and CGI calls) only one * request is handled by an extension instance, but for others (when PHP runs * as module in a webserver) many requests are handled by the same extension * instance. - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2013, 2014 Copernica BV */ @@ -33,7 +33,7 @@ using Callback = std::function<void()>; /** * Class definition */ -class Extension : public Namespace +class PHPCPP_EXPORT Extension : public Namespace { public: /** @@ -51,68 +51,68 @@ public: * @param apiversion PHP API version (this should always be PHPCPP_API_VERSION, so you better not supply it) */ Extension(const char *name, const char *version = "1.0", int apiversion = PHPCPP_API_VERSION); - + /** * No copy'ing and no moving */ Extension(const Extension &extension) = delete; Extension(Extension &&extension) = delete; - + /** * Destructor */ virtual ~Extension(); - + /** * Register a function to be called when the PHP engine is ready - * - * The callback will be called after all extensions are loaded, and all + * + * The callback will be called after all extensions are loaded, and all * functions and classes are available, but before the first pageview/request * is handled. You can register this callback if you want to be notified * when the engine is ready, for example to initialize certain things. - * + * * @param callback Function to be called * @return Extension Same object to allow chaining */ Extension &onStartup(const Callback &callback); - + /** * Register a function to be called when the PHP engine is going to stop - * + * * The callback will be called right before the process is going to stop. * You can register a function if you want to clean up certain things. - * + * * @param callback Function to be called * @return Extension Same object to allow chaining */ Extension &onShutdown(const Callback &callback); - + /** * Register a callback that is called at the beginning of each pageview/request - * + * * You can register a callback if you want to initialize certain things * at the beginning of each request. Remember that the extension can handle * multiple requests after each other, and you may want to set back certain * global variables to their initial variables in front of each request - * + * * @param callback Function to be called * @return Extension Same object to allow chaining */ Extension &onRequest(const Callback &callback); - + /** * Register a callback that is called to cleanup things after a pageview/request - * + * * The callback will be called after _each_ request, so that you can clean up * certain things and make your extension ready to handle the next request. * This method is called onIdle because the extension is idle in between * requests. - * + * * @param callback Function to be called * @return Extension Same object to allow chaining */ Extension &onIdle(const Callback &callback); - + /** * Add a ini entry to the extension by moving it * @param ini The php.ini setting @@ -122,10 +122,10 @@ public: { // skip when locked if (locked()) return *this; - + // and add it to the list of classes _ini_entries.emplace_back(new Ini(std::move(ini))); - + // allow chaining return *this; } @@ -142,11 +142,11 @@ public: // and add it to the list of classes _ini_entries.emplace_back(new Ini(ini)); - + // allow chaining return *this; } - + /** * Because the add function exists in both the Namespace base class * as well as this extended Extension class, we have to tell the compiler @@ -165,9 +165,9 @@ public: /** * Apply a callback to each php.ini variable - * + * * The callback will be called with a reference to the ini variable. - * + * * @param callback */ void iniVariables(const std::function<void(Ini &ini)> &callback) @@ -178,30 +178,30 @@ public: /** * Retrieve the module pointer - * + * * This is the memory address that should be exported by the get_module() * function. * * @return void* */ void *module(); - + /** * Cast to a module entry - * + * * @return void* */ operator void * () { return module(); } - + protected: /** * Is the extension object in a locked state? This happens after the * get_module() function was called for the first time ("apache reload" * forces a new call to get_module()) - * + * * @return bool */ virtual bool locked() const override; @@ -209,7 +209,7 @@ protected: private: /** * The implementation object - * + * * @var ExtensionImpl */ ExtensionImpl *_impl; @@ -226,5 +226,3 @@ private: * End of namespace */ } - - diff --git a/include/fatalerror.h b/include/fatalerror.h index b178f25..bda717a 100644 --- a/include/fatalerror.h +++ b/include/fatalerror.h @@ -1,18 +1,18 @@ /** * FatalError.h - * - * + * + * * Normally, fatal errors are reported with a call to zend_error(). - * + * * However, this will trigger a longjmp(), which will cause objects * constructed in the extension not to be destructed. We use therefore * this FatalError class, which is a normally exception that _does_ * cause objects to be destructed. - * + * * When it is caught, right before control is handed back to the Zend * engine, it will turn the exception into a zend_error() call and * thus a longjmp. - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2014 Copernica BV */ @@ -25,7 +25,7 @@ namespace Php { /** * Class definition */ -class FatalError : public Exception +class PHPCPP_EXPORT FatalError : public Exception { public: /** @@ -33,11 +33,11 @@ public: * @param message */ FatalError(const std::string &message) : Exception(message) {} - + /** * Destructor */ - virtual ~FatalError() throw() + virtual ~FatalError() throw() { } @@ -51,16 +51,15 @@ public: // as exception, but it should live on as zend_error() in stead return false; } - + /** * Report this error as a fatal error * @return bool */ virtual bool report() const override; }; - + /** * End of namespace */ } - diff --git a/include/file.h b/include/file.h index 7029bb6..fff3cd0 100644 --- a/include/file.h +++ b/include/file.h @@ -7,7 +7,7 @@ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2014 Copernica BV */ - + /** * Set up namespace */ @@ -16,23 +16,23 @@ namespace Php { /** * Class definition */ -class File +class PHPCPP_EXPORT File { public: /** * Constructor - * + * * The constructor receives a filename as parameter. It uses the normal - * PHP include path resolve algorithms to find the location of the file. - * + * PHP include path resolve algorithms to find the location of the file. + * * @param name the filename * @param size size of the filename */ File(const char *name, size_t size); - + /** * Alternative constructor with just a filename - * + * * @param name the filename */ File(const char *name) : File(name, ::strlen(name)) {} @@ -42,7 +42,7 @@ public: * @param name the filename */ File(const std::string &name) : File(name.c_str(), name.size()) {} - + /** * Alternative constructor with a Value object * @param name the filename @@ -53,13 +53,13 @@ public: * Destructor */ virtual ~File(); - + /** * Does the file exist? * @return boolean */ bool exists(); - + /** * Is this a valid file? * @return boolean @@ -71,20 +71,20 @@ public: * @return Php::Value */ Value once(); - + /** * Execute the file * @return Php::Value */ Value execute(); - + private: /** * The full resolved path name * @var const char * */ char *_path = nullptr; - + /** * The opcodes of this file * @var Opcodes @@ -96,11 +96,10 @@ private: * @return bool */ bool compile(); - + }; - + /** * End of namespace */ } - diff --git a/include/function.h b/include/function.h index e6693d7..cc8ad02 100644 --- a/include/function.h +++ b/include/function.h @@ -1,24 +1,24 @@ /** * Function.h - * - * Small extension to the Value class that allows a value to be - * constructed with a std::function. - * + * + * Small extension to the Value class that allows a value to be + * constructed with a std::function. + * * If you want to assign a std::function to a value, the following * piece of code won't work: - * + * * Php::Value value([]() { .... }); - * + * * Because the passed in function would match with many of the possible - * Value constructors. For that reason we have created a small and + * Value constructors. For that reason we have created a small and * simple Function class that can be used instead: - * + * * Php::Function valu([]() { .... }); - * + * * A Php::Function is an extended Php::Value object, so can be used * in place of Php::Values all the time. The only difference is that * it has a different constructor - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2015 Copernica BV */ @@ -27,11 +27,11 @@ * Set up namespace */ namespace Php { - + /** * Class definition */ -class Function : public Value +class PHPCPP_EXPORT Function : public Value { public: /** @@ -42,22 +42,22 @@ public: /** * Constructor to wrap a function that does not accept parameters - * + * * Old C++ compilers do not see a difference between std::function * objects based on the function signature, so these old compilers * do not see this method. - * + * * @param function The C++ function to be wrapped */ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7) || __clang__ Function(const std::function<Value()> &function) : Function([function](Parameters ¶ms) -> Value { - + // call original function, forget about the parameters return function(); - + }) {} #endif - + /** * Destructor */ @@ -77,4 +77,3 @@ private: * End namespace */ } - diff --git a/include/global.h b/include/global.h index 2757979..7a66997 100644 --- a/include/global.h +++ b/include/global.h @@ -21,7 +21,7 @@ namespace Php { /** * Class definition */ -class Global : public Value +class PHPCPP_EXPORT Global : public Value { public: /** @@ -40,7 +40,7 @@ public: * Destructor */ virtual ~Global() {} - + /** * Assignment operator * @param global @@ -51,14 +51,14 @@ public: { // skip self assignment if (&global == this) return *this; - + // call base Value::operator=(global); - + // copy name and exists setting _name = global._name; _exists = global._exists; - + // done return *this; } @@ -74,19 +74,19 @@ public: { // skip self assignment if (&global == this) return *this; - + // call base Value::operator=(std::move(global)); - + // copy name and exists setting _name = std::move(global._name); _exists = global._exists; - + // done return *this; } */ - + /** * Assignment operator * @param value @@ -110,11 +110,11 @@ public: { // update current object update(); - + // call base Value::set(index, value); } - + /** * Set a certain property * Calling this method will turn the value into an array @@ -127,7 +127,7 @@ public: { // update current object update(); - + // call base Value::set(key, size, value); } @@ -139,14 +139,14 @@ protected: * @return Value */ Global &update(); - + private: /** * Constructor for non-existing var * @param name */ Global(const char *name) : Value(), _name(name), _exists(false) {} - + /** * Alternative constructor for non-existing var * @param name @@ -159,7 +159,7 @@ private: * @param val */ Global(const char *name, struct _zval_struct *val) : Value(val, true), _name(name), _exists(true) {} - + /** * Alternative constructor to wrap zval * @param name @@ -172,13 +172,13 @@ private: * @var string */ std::string _name; - + /** * Does it already exist? * @var bool */ bool _exists; - + /** * The globals can access the private method from this class */ @@ -189,5 +189,3 @@ private: * End of namespace */ } - - diff --git a/include/globals.h b/include/globals.h index b996131..231b8bd 100644 --- a/include/globals.h +++ b/include/globals.h @@ -4,14 +4,14 @@ * Wrapper object that gives access to all global variables. You * can use it more or less the same as the $_GLOBALS object in * PHP. - * + * * The global PHP variables are acessible via the Php::globals["varname"] * variables. * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2013 Copernica BV */ - + /** * Set up namespace */ @@ -25,7 +25,7 @@ class Global; /** * Class definition */ -class Globals +class PHPCPP_EXPORT Globals { public: /** @@ -33,32 +33,32 @@ public: */ Globals(const Globals &globals) = delete; Globals(Globals &&globals) = delete; - + /** * Destructor */ virtual ~Globals() {} - + /** * Get access to a global variable * @param name * @return Global */ Global operator[](const char *name); - + /** * Get access to a global variable * @param name * @return Global */ Global operator[](const std::string &name); - + private: /** * Constructor */ Globals() {} - + public: /** * Get the one and only instance @@ -77,4 +77,3 @@ extern Globals &GLOBALS; * End of namespace */ } - diff --git a/include/hashmember.h b/include/hashmember.h index ce27192..12ee385 100644 --- a/include/hashmember.h +++ b/include/hashmember.h @@ -6,7 +6,7 @@ * keeps track of the array to which it belongs, and that will update * the array when the member is modified * - * You are not supposed to instantiate this class. An instance of it is + * You are not supposed to instantiate this class. An instance of it is * created when you call Value::operator[] * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> @@ -17,7 +17,7 @@ * Set up namespace */ namespace Php { - + /** * Forward definitions */ @@ -27,7 +27,7 @@ class Value; * Member class */ template <typename Type> -class HashMember : private HashParent +class PHPCPP_EXPORT HashMember : private HashParent { public: /** @@ -36,7 +36,7 @@ public: * @param index */ HashMember(HashParent *parent, Type index) : _parent(parent), _index(index) {} - + /** * Destructor */ @@ -111,7 +111,7 @@ public: { return value().numericValue(); } - + /** * Cast to a boolean * @return boolean @@ -120,7 +120,7 @@ public: { return value().boolValue(); } - + /** * Cast to a string * @return string @@ -129,7 +129,7 @@ public: { return value().stringValue(); } - + /** * Cast to byte array * @return const char * @@ -138,7 +138,7 @@ public: { return value().rawValue(); } - + /** * Cast to a floating point * @return double @@ -147,7 +147,7 @@ public: { return value().floatValue(); } - + /** * Array access operator * This can be used for accessing arrays @@ -210,7 +210,7 @@ public: HashMember &operator-=(const std::string &value) { return operator=(this->value() - value); } HashMember &operator-=(const char *value) { return operator=(this->value() - value); } HashMember &operator-=(double value) { return operator=(this->value() - value); } - + /** * Multiply the object with a certain value * @param value @@ -255,7 +255,7 @@ public: HashMember &operator%=(const std::string &value) { return operator=(this->value() % value); } HashMember &operator%=(const char *value) { return operator=(this->value() % value); } HashMember &operator%=(double value) { return operator=(this->value() % value); } - + /** * Assignment operator * @param value @@ -330,7 +330,7 @@ public: Value operator%(const std::string &value) { return this->value() % value; } Value operator%(const char *value) { return this->value() % value; } Value operator%(double value) { return this->value() % value; } - + /** * Comparison operators * @param value @@ -378,7 +378,7 @@ public: // object must exist, and the value must contain the key return exists() && value().contains(key); } - + /** * Check if a certain index exists in the array/object * @param index @@ -400,7 +400,7 @@ public: // object must exist, and the value must contain the key return exists() && value().contains(key); } - + /** * Retrieve the value at a string index * @param key @@ -410,11 +410,11 @@ public: { // return null if it does not exist if (!exists()) return nullptr; - + // ask the value return value().get(key); } - + /** * Retrieve the value at a numeric index * @param index @@ -424,7 +424,7 @@ public: { // return null if it does not exist if (!exists()) return nullptr; - + // ask the value return value().get(index); } @@ -438,11 +438,11 @@ public: { // return null if it does not exist if (!exists()) return nullptr; - + // ask the value return value().get(key); } - + /** * Overwrite the value at a certain string index * @param key @@ -452,14 +452,14 @@ public: { // get the current value Value current(this->value()); - + // add the value current[key] = value; - + // pass this to the base _parent->set(_index, current); } - + /** * Overwrite the value at a certain numeric index * @param index @@ -469,10 +469,10 @@ public: { // get the current value Value current(this->value()); - + // add the value current[index] = value; - + // pass this to the base _parent->set(_index, current); } @@ -486,10 +486,10 @@ public: { // get the current value Value current(this->value()); - + // add the value current[key] = value; - + // pass this to the base _parent->set(_index, current); } @@ -510,20 +510,20 @@ public: { // if the current property does not even exist, we do not have to add anything if (!exists()) return; - + // get the current value Value current(this->value()); - + // skip if the property does not exist if (!current.contains(index)) return; - + // remove the index current.unset(index); - + // pass the new value to the base _parent->set(_index, current); } - + /** * Unset a member by its key * @param key @@ -532,16 +532,16 @@ public: { // if the current property does not even exist, we do not have to add anything if (!exists()) return; - + // get the current value Value current(this->value()); - + // skip if the property does not exist if (!current.contains(key)) return; - + // remove the index current.unset(key); - + // pass the new value to the base _parent->set(_index, current); } @@ -554,16 +554,16 @@ public: { // if the current property does not even exist, we do not have to add anything if (!exists()) return; - + // get the current value Value current(this->value()); - + // skip if the property does not exist if (!current.contains(key)) return; - + // remove the index current.unset(key); - + // pass the new value to the base _parent->set(_index, current); } @@ -579,22 +579,22 @@ protected: * Move constructor * @param value Other element */ -// HashMember(HashMember<Type> &&member) _NOEXCEPT : +// HashMember(HashMember<Type> &&member) _NOEXCEPT : // _parent(std::move(member._parent)), _index(std::move(member._index)) {} private: /** * Base value - * @var + * @var */ HashParent *_parent; - + /** * The original index * @var Type */ Type _index; - + /** * Friend classes */ @@ -614,9 +614,8 @@ private: std::ostream &operator<<(std::ostream &stream, const HashMember<int> &value); std::ostream &operator<<(std::ostream &stream, const HashMember<std::string> &value); - + /** * End of namespace */ } - diff --git a/include/hashparent.h b/include/hashparent.h index 5ba05bd..b07a8f7 100644 --- a/include/hashparent.h +++ b/include/hashparent.h @@ -5,7 +5,7 @@ * array-access variables ([]). When the value of a hash-member is changed, * it will call one of the methods from this class to set the new property * - * This is an internal class that you normally not need when writing + * This is an internal class that you normally not need when writing * extensions. It is used by the PHP-CPP library when you use constructs * like value["x"]["y"] = 10; * @@ -17,7 +17,7 @@ * Set up namespace */ namespace Php { - + /** * Forwards */ @@ -26,7 +26,7 @@ class Value; /** * Class definition */ -class HashParent +class PHPCPP_EXPORT HashParent { protected: /** @@ -34,41 +34,41 @@ protected: * objects themselved. Use a Value object instead. */ HashParent() {} - + public: /** * Destructor */ virtual ~HashParent() {} - + /** * Check if a certain key exists in the array/object * @param key * @return bool */ virtual bool contains(const std::string &key) const = 0; - + /** * Check if a certain index exists in the array/object * @param key * @return bool */ virtual bool contains(int index) const = 0; - + /** * Check if a certain index exists in the array/object * @param key * @return bool */ virtual bool contains(const Value &index) const = 0; - + /** * Retrieve the value at a string index * @param key * @return Value */ virtual Value get(const std::string &key) const = 0; - + /** * Retrieve the value at a numeric index * @param index @@ -82,34 +82,34 @@ public: * @return Value */ virtual Value get(const Value &key) const = 0; - + /** * Overwrite the value at a certain string index * @param key * @param value */ virtual void set(const std::string &key, const Value &value) = 0; - + /** * Overwrite the value at a certain numeric index * @param index * @param value */ virtual void set(int index, const Value &value) = 0; - + /** * Overwrite the value at a certain variant index * @param key * @param value */ virtual void set(const Value &key, const Value &value) = 0; - + /** * Unset a member by its index * @param index */ virtual void unset(int index) = 0; - + /** * Unset a member by its key * @param key @@ -121,11 +121,10 @@ public: * @param key */ virtual void unset(const Value &key) = 0; - + }; /** * End namespace */ } - diff --git a/include/ini.h b/include/ini.h index 69137a2..592fba3 100644 --- a/include/ini.h +++ b/include/ini.h @@ -3,7 +3,7 @@ * * Class that can be instantiated in the get_module() startup function to * define settings from the php.ini file that are supported. - * + * * @copyright 2014 Copernica BV */ @@ -21,18 +21,18 @@ namespace Php { /** * Class definition */ -class Ini +class PHPCPP_EXPORT 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 + * + * 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 { @@ -44,7 +44,7 @@ public: /** * 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) @@ -58,7 +58,7 @@ public: /** * 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) @@ -72,7 +72,7 @@ public: /** * 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) @@ -98,7 +98,7 @@ public: /** * 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) @@ -134,7 +134,7 @@ private: // cast to a string return ( static_cast<bool>(value) ? "On" : "Off"); } - + /** * ini entry name * @var std::string @@ -158,7 +158,7 @@ private: * @var bool */ bool _orig_empty = false; - + /** * Place where the configuration can be changed * @var Place @@ -172,4 +172,3 @@ private: * End of namespace */ } - diff --git a/include/inivalue.h b/include/inivalue.h index fc3bc8f..9afb1a2 100644 --- a/include/inivalue.h +++ b/include/inivalue.h @@ -2,7 +2,7 @@ * IniValue.h * * Class IniValue designed for extracting values from ini entries - * + * * @copyright 2014 Copernica BV */ @@ -14,12 +14,12 @@ namespace Php { /** * Class IniValue designed for extracting values from ini entries. */ -class IniValue +class PHPCPP_EXPORT IniValue { public: /** * Constructors - * + * * @param name Name of the php.ini variable * @param isorig Is the original value */ @@ -51,7 +51,7 @@ public: { return numericValue(); } - + /** * Cast to a boolean * @return boolean @@ -60,7 +60,7 @@ public: { return boolValue(); } - + /** * Cast to a string * @return string @@ -69,7 +69,7 @@ public: { return stringValue(); } - + /** * Cast to byte array * @return const char * @@ -78,7 +78,7 @@ public: { return rawValue(); } - + /** * Cast to a floating point * @return double @@ -96,7 +96,7 @@ public: * @return int64_t */ int64_t numericValue() const; - + /** * Boolean value * @return bool @@ -121,10 +121,10 @@ public: */ const char *rawValue() const; - + private: - - + + /** * ini entry name * @var std::string @@ -151,4 +151,3 @@ std::ostream &operator<<(std::ostream &stream, const IniValue &ini_val); * End of namespace */ } - diff --git a/include/interface.h b/include/interface.h index 01bb6f5..ecb011e 100644 --- a/include/interface.h +++ b/include/interface.h @@ -13,7 +13,7 @@ namespace Php { /** * Class definition */ -class Interface : private ClassBase +class PHPCPP_EXPORT Interface : private ClassBase { public: /** @@ -21,12 +21,12 @@ public: * @param name */ Interface(const char *name) : ClassBase(name, ClassType::Interface) {} - + /** * Destructor */ virtual ~Interface() {} - + /** * Add a - of course abstract - method to the interface * @param name Name of the method @@ -37,7 +37,7 @@ public: { // call base ClassBase::method(name, Abstract | Public, arguments); - + // return self return *this; } @@ -58,7 +58,7 @@ public: * class, to actually register the interface. */ friend class Namespace; - + /** * All Php::Class<AnyThing> also need access to the base class to * register an interface. @@ -70,4 +70,3 @@ public: * End namespace */ } - diff --git a/include/iterator.h b/include/iterator.h index 331c8b3..5d49e1f 100644 --- a/include/iterator.h +++ b/include/iterator.h @@ -3,9 +3,9 @@ * * Base class for iterators. Extension writers that want to create traversable * classes, should override the Php::Traversable base class. This base class - * forces you to implement a getIterator() method that returns an instance of + * forces you to implement a getIterator() method that returns an instance of * a Php::Iterator class. - * + * * In this file you find the signature of the Php::Iterator class. It mostly has * pure virtual methods, which means that you should create a derived class * that implements all these methods. @@ -22,7 +22,7 @@ namespace Php { /** * Class definition */ -class Iterator +class PHPCPP_EXPORT Iterator { public: /** @@ -30,40 +30,40 @@ public: * @param base Class over which the iterator is iterating */ Iterator(Base *base) : _object(base) {} - + /** * Destructor */ virtual ~Iterator() {} - + /** * Is the iterator on a valid position * @return bool */ virtual bool valid() = 0; - + /** * The value at the current position * @return Value */ virtual Value current() = 0; - + /** * The key at the current position * @return Value */ virtual Value key() = 0; - + /** * Move to the next position */ virtual void next() = 0; - + /** * Rewind the iterator to the front position */ virtual void rewind() = 0; - + protected: /** * During the lifetime of the iterator, the object over which @@ -72,9 +72,9 @@ protected: * @var Value */ Value _object; - + }; - + /** * End namespace */ diff --git a/include/modifiers.h b/include/modifiers.h index e52bd14..98140bb 100644 --- a/include/modifiers.h +++ b/include/modifiers.h @@ -16,19 +16,19 @@ namespace Php { /** * The modifiers are constants */ -extern const int Static; -extern const int Abstract; -extern const int Final; -extern const int Public; -extern const int Protected; -extern const int Private; -extern const int Const; +extern PHPCPP_EXPORT const int Static; +extern PHPCPP_EXPORT const int Abstract; +extern PHPCPP_EXPORT const int Final; +extern PHPCPP_EXPORT const int Public; +extern PHPCPP_EXPORT const int Protected; +extern PHPCPP_EXPORT const int Private; +extern PHPCPP_EXPORT const int Const; /** * Modifiers that are supported for methods and properties */ -extern const int MethodModifiers; -extern const int PropertyModifiers; +extern PHPCPP_EXPORT const int MethodModifiers; +extern PHPCPP_EXPORT const int PropertyModifiers; /** * End namespace diff --git a/include/namespace.h b/include/namespace.h index 4bb23db..bdfb8c6 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -1,9 +1,9 @@ /** * Namespace.h - * + * * Class that can be used to group various functions and classes into one * namespace. - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2014 Copernica BV */ @@ -21,7 +21,7 @@ class NativeFunction; /** * Class definition */ -class Namespace +class PHPCPP_EXPORT Namespace { protected: /** @@ -41,13 +41,13 @@ protected: * @var list */ std::list<std::shared_ptr<ClassBase>> _classes; - + /** * Constants defined in the namespace * @var list */ std::list<std::shared_ptr<Constant>> _constants; - + /** * Namespaces defined inside the namespace * @var list @@ -56,19 +56,19 @@ protected: /** * Is the object locked? - * + * * After the object is locked, no more elements can be added to it. * This happens after the call to get_module - it the no longer makes * sense to add more objects. When 'apache reload' is executed, the * get_module() function is called for a second (or third, or fourth) * time, but the classes, functions and namespaces will then not be * filled. - * + * * @var bool */ virtual bool locked() const { - // by default, namespaces are not locked (only derived extension + // by default, namespaces are not locked (only derived extension // objects can end up in a locked state return false; } @@ -80,12 +80,12 @@ public: * @param name Name of the namespace */ Namespace(const char *name) : _name(name) {} - + /** * Destructor */ virtual ~Namespace() {} - + /** * Add a native function directly to the namespace * @param name Name of the function @@ -97,7 +97,7 @@ public: Namespace &add(const char *name, const native_callback_1 &function, const Arguments &arguments = {}); Namespace &add(const char *name, const native_callback_2 &function, const Arguments &arguments = {}); Namespace &add(const char *name, const native_callback_3 &function, const Arguments &arguments = {}); - + /** * Add a native class to the namespace by moving it * @param type The class implementation @@ -108,10 +108,10 @@ public: { // skip when locked if (locked()) return *this; - + // make a copy of the object, and add it to the list of classes _classes.push_back(std::unique_ptr<ClassBase>(new Class<T>(std::move(type)))); - + // allow chaining return *this; } @@ -129,7 +129,7 @@ public: // and add it to the list of classes _classes.push_back(std::unique_ptr<ClassBase>(new Class<T>(type))); - + // allow chaining return *this; } @@ -146,7 +146,7 @@ public: // make a copy and add it to the list of classes _classes.push_back(std::unique_ptr<ClassBase>(new Interface(std::move(interface)))); - + // allow chaining return *this; } @@ -163,11 +163,11 @@ public: // make a copy and add it to the list of classes _classes.push_back(std::unique_ptr<ClassBase>(new Interface(interface))); - + // allow chaining return *this; } - + /** * Add a constant to the namespace * @param constant The constant to add @@ -180,11 +180,11 @@ public: // and add it to the list of constants _constants.push_back(std::unique_ptr<Constant>(new Constant(std::move(constant)))); - + // allow chaining return *this; } - + /** * Add a constant to the namespace * @param constant The constant to add @@ -197,11 +197,11 @@ public: // and add it to the list of constants _constants.push_back(std::unique_ptr<Constant>(new Constant(constant))); - + // allow chaining return *this; } - + /** * Add a namespace to the namespace by moving it * @param ns The namespace @@ -214,7 +214,7 @@ public: // add it to the list of namespaces _namespaces.push_back(std::unique_ptr<Namespace>(new Namespace(std::move(ns)))); - + // allow chaining return *this; } @@ -231,7 +231,7 @@ public: // make a copy and add it to the list of namespaces _namespaces.push_back(std::unique_ptr<Namespace>(new Namespace(ns))); - + // allow chaining return *this; } @@ -244,48 +244,47 @@ public: { // number of functions in this namespace int result = _functions.size(); - + // number of functions in sub-namespace for (auto &ns : _namespaces) result += ns->functions(); - + // done return result; } /** * Apply a callback to each registered function - * + * * The callback will be called with the name of the namespace, and * a reference to the registered function. - * + * * @param callback */ void functions(const std::function<void(const std::string &ns, NativeFunction &func)> &callback); - + /** * Apply a callback to each registered class - * + * * The callback will be called with the name of the namespace, and * a reference to the registered class. - * + * * @param callback */ void classes(const std::function<void(const std::string &ns, ClassBase &clss)> &callback); - + /** * Apply a callback to each registered constant - * + * * The callback will be called with the name of the namespace, and * a reference to the registered constant - * + * * @param callback */ void constants(const std::function<void(const std::string &ns, Constant &constant)> &callback); }; - + /** * End namespace */ } - diff --git a/include/object.h b/include/object.h index 2eea05b..f8fea74 100644 --- a/include/object.h +++ b/include/object.h @@ -12,11 +12,11 @@ * Set up namespace */ namespace Php { - + /** * Class definition */ -class Object : public Value +class PHPCPP_EXPORT Object : public Value { public: /** @@ -33,40 +33,40 @@ public: /** * Constructor to create a new instance of a builtin class - * + * * You can use this constructor if you have created an instance of your * own class, but has not assigned it to a variable yet. This happens * for example for classes that are not constructed from PHP userspace, * but from your own functions: - * + * * Php::Value yourFunction() * { * return Php::Object("MyClass", new MyClass()); * } - * + * * When you construct objects like this, the __construct function is not * going to be called. If you want to construct the object just as if it * was constructed from PHP user space, do this: - * + * * Php::Value yourFunction() * { * return Php::Object("MyClass"); * } - * + * * @param name Name of the class to instantiate * @param base C++ object to wrap */ Object(const char *name, Base *base); - + /** * If you already have the zend_class_entry, you can also pass the * class_entry structure instead of the class name. This constructor * works exactly like the Object(name, base) constructor mentioned * above. - * + * * Note that if you normally use PHP-CPP, you do not have the class_entry, * so you probably need to pass the name anyway - * + * * @param entry The PHP class entry * @param base C++ object to wrap */ @@ -86,17 +86,17 @@ public: /** * Constructor to create a new instance - * + * * Note that it was not possible to create a constructor with signature * Object(const char *name, Args&&... args) because that overrides the * Object(const char *name, Base *base) constructor. - * + * * @param name Name of the class to instantiate * @param args Optional arguments */ template <typename ...Args> Object(const char *name, Value arg0, Args&&... args) : Value() { if (instantiate(name)) call("__construct", arg0, std::forward<Value>(args)...); } - + /** * Destructor */ @@ -110,7 +110,7 @@ public: { // throw exception if things are going wrong if (type != Type::Object) throw FatalError("Changing type of a fixed object variable"); - + // call base return Value::setType(type); } @@ -124,17 +124,17 @@ public: { // skip self assignment if (this == &value) return *this; - + // type must be valid if (value.type() != Type::Object) throw FatalError("Assigning a non-object to an object variable"); - + // call base Value::operator=(value); // done return *this; } - + /** * Move assignment operator * @param value @@ -144,10 +144,10 @@ public: { // skip self assignment if (this == &value) return *this; - + // type must be valid if (value.type() != Type::Object) throw FatalError("Moving a non-object to an object variable"); - + // call base Value::operator=(std::move(value)); @@ -158,10 +158,10 @@ public: private: /** * Helper method to instantiate an object - * + * * This method returns true if there is a __construct() function, and * false otherwise - * + * * @param name Class name * @return bool */ diff --git a/include/parameters.h b/include/parameters.h index b464260..3465863 100644 --- a/include/parameters.h +++ b/include/parameters.h @@ -1,8 +1,8 @@ /** * Parameters.h * - * Wrapper around parameters that are passed to a - + * Wrapper around parameters that are passed to a + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2013 Copernica BV */ @@ -20,7 +20,7 @@ class Base; /** * Class definition */ -class Parameters : public std::vector<Value> +class PHPCPP_EXPORT Parameters : public std::vector<Value> { private: /** @@ -32,14 +32,14 @@ private: protected: /** * Protected constructor - * + * * The constructor is protected because extension programmers are not * supposed to instantiate parameters objects themselves - * + * * @param object The 'this' object */ Parameters(Base *object) : _object(object) {} - + public: /** * Destructor @@ -60,4 +60,3 @@ public: * End of namespace */ } - diff --git a/include/script.h b/include/script.h index 6aee034..860b9bc 100644 --- a/include/script.h +++ b/include/script.h @@ -5,7 +5,7 @@ * * The difference between directly calling eval() is that the script object * will first evaluate the string, and then it can be executed multiple times. - * + * * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> * @copyright 2014 Copernica BV */ @@ -28,26 +28,26 @@ class Opcodes; /** * Class definition */ -class Script +class PHPCPP_EXPORT Script { public: /** * Constructor - * + * * The constructor will not throw any exceptions, even when invalid * PHP code is passed to it that can not be evaluated. You should call * the valid() to find out if the script was valid (could be parsed). - * + * * @param name Name of the PHP script - * @param source PHP source code to be evaluated + * @param source PHP source code to be evaluated * @param size Length of the source code */ Script(const char *name, const char *source, size_t size) _NOEXCEPT; - + /** * Alternative constructor without a size * @param name Name of the PHP script - * @param source PHP source code to be evaluated + * @param source PHP source code to be evaluated */ Script(const char *name, const char *source) _NOEXCEPT : Script(name, source, ::strlen(source)) {} @@ -63,38 +63,38 @@ public: * @param source PHP source code to be evaluated */ Script(const char *source) _NOEXCEPT : Script("Unknown", source, ::strlen(source)) {} - + /** * Constructor based on a std::string * @param source PHP source code to be evaluated */ Script(const std::string &source) _NOEXCEPT : Script("Unknown", source.c_str(), source.size()) {} - + /** * Destructor */ virtual ~Script(); - + /** * Is the script a valid PHP script without syntax errors? * @return bool */ bool valid() const; - + /** * Execute the script * The return value of the script is returned * @return Value */ Value execute() const; - + private: /** * The opcodes * @var Opcodes */ Opcodes *_opcodes; - + /** * Helper function to compile the source code * @param name name of the script @@ -105,7 +105,7 @@ private: static struct _zend_op_array *compile(const char *name, const char *phpcode, size_t size); }; - + /** * End of namespace */ diff --git a/include/serializable.h b/include/serializable.h index ce60d91..fdcffa2 100644 --- a/include/serializable.h +++ b/include/serializable.h @@ -16,22 +16,22 @@ namespace Php { /** * Class definition */ -class Serializable +class PHPCPP_EXPORT Serializable { public: /** * Method to serialize the object * - * This method should return a string representation of the object that + * This method should return a string representation of the object that * can be passed to the serialize() method and that will revive the object * * @return std::string */ virtual std::string serialize() = 0; - + /** * Unserialize the object - * + * * This method is called as an alternative __construct() method to initialize * the object. The passed in string parameter in in the format earlier returned * by a call to serialize() @@ -46,6 +46,3 @@ public: * End namespace */ } - - -
\ No newline at end of file diff --git a/include/streams.h b/include/streams.h index c4d5339..997defe 100644 --- a/include/streams.h +++ b/include/streams.h @@ -21,11 +21,11 @@ namespace Php { /** * Define the out and err objects */ -extern std::ostream out; -extern std::ostream error; -extern std::ostream notice; -extern std::ostream warning; -extern std::ostream deprecated; +extern PHPCPP_EXPORT std::ostream out; +extern PHPCPP_EXPORT std::ostream error; +extern PHPCPP_EXPORT std::ostream notice; +extern PHPCPP_EXPORT std::ostream warning; +extern PHPCPP_EXPORT std::ostream deprecated; /** * End namespace diff --git a/include/super.h b/include/super.h index 07dc4b3..154ae62 100644 --- a/include/super.h +++ b/include/super.h @@ -12,29 +12,29 @@ * Set up namespace */ namespace Php { - + /** * Class definition */ -class Super +class PHPCPP_EXPORT Super { public: /** * Constructor - * + * * Extension writers do not have to access the super-globals themselves. * They are always accessible via Php::POST, Php::GET, et cetera. - * + * * @param index index number * @param name name of the variable in PHP */ Super(int index, const char *name) : _index(index), _name(name) {} - + /** * Destructor */ virtual ~Super() {} - + /** * Array access operator * This can be used for accessing associative arrays @@ -78,7 +78,7 @@ public: // convert to value, and call begin on the value object return value().begin(); } - + /** * Return an iterator for iterating over the variables * @return iterator @@ -95,19 +95,19 @@ private: * @var int */ int _index; - + /** * Name of the variable in PHP * @var name */ const char *_name; - + /** * Turn the object into a value object * @return Value */ Value value(); - + }; /** @@ -125,4 +125,3 @@ extern Super REQUEST; * End namespace */ } - diff --git a/include/traversable.h b/include/traversable.h index f81a5b4..8ef7f5d 100644 --- a/include/traversable.h +++ b/include/traversable.h @@ -17,7 +17,7 @@ namespace Php { /** * Class definition */ -class Traversable +class PHPCPP_EXPORT Traversable { public: /** diff --git a/include/type.h b/include/type.h index d248455..151919c 100644 --- a/include/type.h +++ b/include/type.h @@ -17,7 +17,7 @@ namespace Php { * Supported types for variables * The values are the same as the ones used internally in Zend */ -enum class Type : unsigned char { +enum class PHPCPP_EXPORT Type : unsigned char { Null = 0, // Null will allow any type Numeric = 1, Float = 2, @@ -35,4 +35,3 @@ enum class Type : unsigned char { * End of namespace */ } - diff --git a/include/value.h b/include/value.h index e080df7..40327cd 100644 --- a/include/value.h +++ b/include/value.h @@ -38,7 +38,7 @@ template <class Type> class HashMember; /** * Class definition */ -class Value : private HashParent +class PHPCPP_EXPORT Value : private HashParent { public: /** @@ -1228,5 +1228,3 @@ X &operator%=(X &x, const Php::Value &value) { return x %= (X)value; } * End of namespace */ } - - diff --git a/include/valueiterator.h b/include/valueiterator.h index 95cdac6..92c26aa 100644 --- a/include/valueiterator.h +++ b/include/valueiterator.h @@ -24,7 +24,7 @@ class ValueIteratorImpl; /** * Class definition */ -class ValueIterator +class PHPCPP_EXPORT ValueIterator { public: /** @@ -32,13 +32,13 @@ public: * @param impl Implementation iterator */ ValueIterator(ValueIteratorImpl *impl) : _impl(impl) {} - + /** * Copy constructor * @param that */ ValueIterator(const ValueIterator &that); - + /** * Destructor */ @@ -49,7 +49,7 @@ public: * @return ValueIterator */ ValueIterator &operator++(); - + /** * Increment position (post-increment) * @return ValueIterator @@ -58,14 +58,14 @@ public: { // make a copy ValueIterator copy(*this); - + // increment current object ++(*this); - + // and return the unchanged original return copy; } - + /** * Decrement position (pre-decrement) * @return ValueIterator @@ -80,14 +80,14 @@ public: { // make a copy ValueIterator copy(*this); - + // decrement current object --(*this); - + // and return the unchanged original return copy; } - + /** * Compare with other iterator * @param that @@ -107,7 +107,7 @@ public: * @return std::pair */ const std::pair<Value,Value> &operator*() const; - + /** * Dereference, this returns a std::pair with the current key and value * @return std::pair @@ -127,4 +127,3 @@ private: * End namespace */ } - diff --git a/include/version.h b/include/version.h index 7038f20..f7e9ea5 100644 --- a/include/version.h +++ b/include/version.h @@ -1,7 +1,7 @@ /** * Version.h * - * Macro with API version. The API version number prevents that + * Macro with API version. The API version number prevents that * extensions are loaded that are incompatible with the libphpcpp.so * library * @@ -13,5 +13,3 @@ * Macro with version number (this is incremented with every release) */ #define PHPCPP_API_VERSION 20150126 - - diff --git a/include/visibility.h b/include/visibility.h new file mode 100644 index 0000000..afb8a6b --- /dev/null +++ b/include/visibility.h @@ -0,0 +1,30 @@ +/** + * visibility.h + * + * This file defines macros used to define whether a symbol + * should be exported. It is only used for classes and + * functions that are defined in the public API to reduce + * the size of the symbol table, make linking and loading + * of the PHP-CPP library faster and generate more + * optimized code as a result. + * + * @copyright 2015 Copernica B.V. + */ + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef BUILDING_PHPCPP + #ifdef __GNUC__ + #define PHPCPP_EXPORT __attribute__ ((dllexport)) + #else + #define PHPCPP_EXPORT __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. + #endif + #else + #ifdef __GNUC__ + #define DLL_EXPORT __attribute__ ((dllimport)) + #else + #define DLL_EXPORT __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. + #endif + #endif +#else + #define PHPCPP_EXPORT __attribute__ ((visibility ("default"))) +#endif @@ -27,6 +27,7 @@ /** * Include all headers files that are related to this library */ +#include <phpcpp/visibility.h> #include <phpcpp/noexcept.h> #include <phpcpp/platform.h> #include <phpcpp/version.h> @@ -41,7 +42,6 @@ #include <phpcpp/valueiterator.h> #include <phpcpp/array.h> #include <phpcpp/object.h> -#include <phpcpp/hiddenpointer.h> #include <phpcpp/globals.h> #include <phpcpp/argument.h> #include <phpcpp/byval.h> @@ -69,13 +69,4 @@ #include <phpcpp/file.h> #include <phpcpp/function.h> -/** - * Macro to export a function - */ -#if defined(__GNUC__) && __GNUC__ >= 4 -# define PHPCPP_EXPORT __attribute__ ((visibility("default"))) -#else -# define PHPCPP_EXPORT -#endif - #endif /* phpcpp.h */ diff --git a/include/hiddenpointer.h b/zend/hiddenpointer.h index 955e7d7..d2636e3 100644 --- a/include/hiddenpointer.h +++ b/zend/hiddenpointer.h @@ -180,4 +180,3 @@ private: * End of namespace */ } - diff --git a/zend/includes.h b/zend/includes.h index c092a07..aed5ed0 100644 --- a/zend/includes.h +++ b/zend/includes.h @@ -47,6 +47,7 @@ /** * Include other files from this library */ +#include "../include/visibility.h" #include "../include/noexcept.h" #include "../include/platform.h" #include "../include/version.h" @@ -61,7 +62,6 @@ #include "../include/valueiterator.h" #include "../include/array.h" #include "../include/object.h" -#include "../include/hiddenpointer.h" #include "../include/globals.h" #include "../include/argument.h" #include "../include/byval.h" @@ -98,6 +98,7 @@ /** * Specific zend implementation files for internal use only */ +#include "hiddenpointer.h" #include "init.h" #include "callable.h" #include "nativefunction.h" |