From 35fd3ccbeb4def71b4d8a59dfbb5c31201b099b9 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 6 Apr 2014 21:53:24 +0200 Subject: renamed src directory to zend directory, disabled TSRM debug code --- zend/extensionimpl.cpp | 300 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 zend/extensionimpl.cpp (limited to 'zend/extensionimpl.cpp') diff --git a/zend/extensionimpl.cpp b/zend/extensionimpl.cpp new file mode 100644 index 0000000..9562362 --- /dev/null +++ b/zend/extensionimpl.cpp @@ -0,0 +1,300 @@ +/** + * Extension.cpp + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * If this extension is compiled for a PHP version with multi + * threading support, we need an additional header file + */ +#ifdef ZTS +#include "TSRM.h" +#endif + +/** + * We're almost there, we now need to declare an instance of the + * structure defined above (if building for a single thread) or some + * sort of impossible to understand magic pointer-to-a-pointer (for + * multi-threading builds). We make this a static variable because + * this already is bad enough. + */ +ZEND_DECLARE_MODULE_GLOBALS(phpcpp) + +/** + * Function that must be defined to initialize the "globals" + * We do not have to initialize anything, but PHP needs to call this + * method (crazy) + * @param globals + */ +static void init_globals(zend_phpcpp_globals *globals) {} + +/** + * The *startup() and *shutdown() callback functions are passed a module_number + * variable. However, there does not seem to be a decent API call in Zend to + * get back the original module_entry linked to this number. So we have to + * look up entries in a hash table to find the right module entry. To make things + * even worse, the records in this hash table are copies of the original + * zend_module_entry structure, so we can also not hide the C++ extension + * object pointer in the entry that we created ourselves. + * + * We have an ugly solution, we keep track of a map of all C++ extension names + * and their associated extension object, and a map of all module number and + * the linked extension object. + * + * @var map + */ +static std::map name2extension; +static std::map number2extension; + +/** + * Handler function that is used in combination with zend_hash_apply() + * + * This function is called when we need to find an extension object based on + * an extension number. We loop through the list of all registered modules, and + * for each module we check if we know the extension based on the name + * + * @param zend_module_entry + */ +static int match_module(zend_module_entry *entry) +{ + // check if there is an extension with this name + auto iter = name2extension.find(entry->name); + if (iter == name2extension.end()) return ZEND_HASH_APPLY_KEEP; + + // we have the extension, store in combination with the number + number2extension[entry->module_number] = iter->second; + + // done + return ZEND_HASH_APPLY_KEEP; +} + +/** + * Find an extension based on the module number + * @param number + * @param tsrm_ls + * @return Extension* + */ +static ExtensionImpl *find(int number TSRMLS_DC) +{ + // do we already have an extension with this number? + auto iter = number2extension.find(number); + if (iter != number2extension.end()) return iter->second; + + // no, not yet, loop through all modules + zend_hash_apply(&module_registry, (apply_func_t)match_module TSRMLS_CC); + + // find again + iter = number2extension.find(number); + if (iter == number2extension.end()) return nullptr; + + // found! + return iter->second; +} + +/** + * Function that is called when the extension initializes + * @param type Module type + * @param number Module number + * @param tsrm_ls + * @return int 0 on success + */ +int ExtensionImpl::onStartup(int type, int module_number TSRMLS_DC) +{ + // initialize and allocate the "global" variables + ZEND_INIT_MODULE_GLOBALS(phpcpp, init_globals, NULL); + + // get the extension + auto *extension = find(module_number TSRMLS_CC); + + // initialize the extension + extension->initialize(TSRMLS_C); + + // is the callback registered? + if (extension->_onStartup) extension->_onStartup(); + + // done + return BOOL2SUCCESS(true); +} + +/** + * Function that is called when the extension is about to be stopped + * @param type Module type + * @param number Module number + * @param tsrm_ls + * @return int + */ +int ExtensionImpl::onShutdown(int type, int module_number TSRMLS_DC) +{ + // get the extension + auto *extension = find(module_number TSRMLS_CC); + + // is the callback registered? + if (extension->_onShutdown) extension->_onShutdown(); + + // done + return BOOL2SUCCESS(true); +} + +/** + * Function that is called when a request starts + * @param type Module type + * @param number Module number + * @param tsrm_ls + * @return int 0 on success + */ +int ExtensionImpl::onRequest(int type, int module_number TSRMLS_DC) +{ + // get the extension + auto *extension = find(module_number TSRMLS_CC); + + // is the callback registered? + if (extension->_onRequest) extension->_onRequest(); + + // done + return BOOL2SUCCESS(true); +} + +/** + * Function that is called when a request is ended + * @param type Module type + * @param number Module number + * @param tsrm_ls + * @return int 0 on success + */ +int ExtensionImpl::onIdle(int type, int module_number TSRMLS_DC) +{ + // get the extension + auto *extension = find(module_number TSRMLS_CC); + + // is the callback registered? + if (extension->_onIdle) extension->_onIdle(); + + // done + return BOOL2SUCCESS(true); +} + +/** + * Constructor + * @param data Pointer to the extension object created by the extension programmer + * @param name Name of the extension + * @param version Version number + */ +ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *version) : _data(data) +{ + // keep extension pointer based on the name + name2extension[name] = this; + + // assign all members (apart from the globals) + _entry.size = sizeof(zend_module_entry); // size of the data + _entry.zend_api = ZEND_MODULE_API_NO; // api number + _entry.zend_debug = ZEND_DEBUG; // debug mode enabled? + _entry.zts = USING_ZTS; // is thread safety enabled? + _entry.ini_entry = NULL; // the php.ini record + _entry.deps = NULL; // dependencies on other modules + _entry.name = name; // extension name + _entry.functions = NULL; // functions supported by this module (none for now) + _entry.module_startup_func = &ExtensionImpl::onStartup; // startup function for the whole extension + _entry.module_shutdown_func = &ExtensionImpl::onShutdown; // shutdown function for the whole extension + _entry.request_startup_func = &ExtensionImpl::onRequest; // startup function per request + _entry.request_shutdown_func = &ExtensionImpl::onIdle; // shutdown function per request + _entry.info_func = NULL; // information for retrieving info + _entry.version = version; // version string + _entry.globals_size = 0; // size of the global variables + _entry.globals_ctor = NULL; // constructor for global variables + _entry.globals_dtor = NULL; // destructor for global variables + _entry.post_deactivate_func = NULL; // unknown function + _entry.module_started = 0; // module is not yet started + _entry.type = 0; // temporary or persistent module, will be filled by Zend engine + _entry.handle = NULL; // dlopen() handle, will be filled by Zend engine + _entry.module_number = 0; // module number will be filled in by Zend engine + _entry.build_id = (char *)ZEND_MODULE_BUILD_ID; // check if extension and zend engine are compatible + + // things that only need to be initialized +#ifdef ZTS + _entry.globals_id_ptr = NULL; +#else + _entry.globals_ptr = NULL; +#endif + +} + +/** + * Destructor + */ +ExtensionImpl::~ExtensionImpl() +{ + // deallocate functions + if (_entry.functions) delete[] _entry.functions; +} + +/** + * Retrieve the module entry + * @return zend_module_entry + */ +zend_module_entry *ExtensionImpl::module() +{ + // check if functions we're already defined + if (_entry.functions) return &_entry; + + // the number of functions + int count = _data->functions(); + + // skip if there are no functions + if (count == 0) return &_entry; + + // allocate memory for the functions + zend_function_entry *entries = new zend_function_entry[count + 1]; + + // index being processed + int i = 0; + + // apply a function to each function + _data->apply([&i, entries](const std::string &prefix, Function &function) { + + // initialize the function + function.initialize(prefix, &entries[i]); + + // move on to the next iteration + i++; + }); + + // last entry should be set to all zeros + zend_function_entry *last = &entries[count]; + + // all should be set to zero + memset(last, 0, sizeof(zend_function_entry)); + + // store functions in entry object + _entry.functions = entries; + + // return the entry + return &_entry; +} + +/** + * Initialize the extension after it was started + * @param tsrm_ls + */ +void ExtensionImpl::initialize(TSRMLS_D) +{ + // we need to register each class, find out all classes + _data->apply([TSRMLS_C](const std::string &prefix, ClassBase &c) { + + // forward to implementation class + c.implementation()->initialize(&c, prefix TSRMLS_CC); + }); +} + +/** + * End of namespace + */ +} + -- cgit v1.2.3 From 43cfaa8a4730ea1fa7d9c01f58ddcf6f42b4fb46 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 6 Apr 2014 22:51:12 +0200 Subject: introduced common directory that will contain implementation files that are used for hhvm and zend, and introduced hhvm file for the implementation of hhvmcpp --- Makefile | 20 ++++--- common/extensionbase.h | 138 +++++++++++++++++++++++++++++++++++++++++++++++++ hhvm/extension.cpp | 103 ++++++++++++++++++++++++++++++++++++ hhvm/extensionimpl.h | 55 ++++++++++++++++++++ hhvm/includes.h | 53 +++++++++++++++++++ zend/extensionimpl.cpp | 56 ++++++++++---------- zend/extensionimpl.h | 105 +++---------------------------------- zend/includes.h | 7 ++- 8 files changed, 401 insertions(+), 136 deletions(-) create mode 100644 common/extensionbase.h create mode 100644 hhvm/extension.cpp create mode 100644 hhvm/extensionimpl.h create mode 100644 hhvm/includes.h (limited to 'zend/extensionimpl.cpp') diff --git a/Makefile b/Makefile index 5955a3d..c883d2f 100644 --- a/Makefile +++ b/Makefile @@ -120,11 +120,11 @@ MKDIR = mkdir -p # The source files # # For this we use a special Makefile function that automatically scans the -# src/, 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 # -SOURCES = $(wildcard src/*.cpp) +COMMON_SOURCES = $(wildcard common/*.cpp) PHP_SOURCES = $(wildcard zend/*.cpp) HHVM_SOURCES = $(wildcard hhvm/*.cpp) @@ -137,7 +137,7 @@ HHVM_SOURCES = $(wildcard hhvm/*.cpp) # takes all source files. # -OBJECTS = $(SOURCES:%.cpp=%.o) +COMMON_OBJECTS = $(COMMON_SOURCES:%.cpp=%.o) PHP_OBJECTS = $(PHP_SOURCES:%.cpp=%.o) HHVM_OBJECTS = $(HHVM_SOURCES:%.cpp=%.o) @@ -149,17 +149,21 @@ HHVM_OBJECTS = $(HHVM_SOURCES:%.cpp=%.o) all: ${PHP_LIBRARY} -${PHP_LIBRARY}: ${OBJECTS} ${PHP_OBJECTS} +phpcpp: ${PHP_LIBRARY} + +hhvmcpp: ${HHVM_LIBRARY} + +${PHP_LIBRARY}: ${COMMON_OBJECTS} ${PHP_OBJECTS} ${LINKER} ${PHP_LINKER_FLAGS} -o $@ ${OBJECTS} ${PHP_OBJECTS} -${HHVM_LIBRARY}: ${OBJECTS} ${HHVM_OBJECTS} +${HHVM_LIBRARY}: ${COMMON_OBJECTS} ${HHVM_OBJECTS} ${LINKER} ${HHVM_LINKER_FLAGS} -o $@ ${OBJECTS} ${HHVM_OBJECTS} clean: - ${RM} ${OBJECTS} ${PHP_OBJECTS} ${HHVM_OBJECTS} ${PHP_LIBRARY} ${HHVM_LIBRARY} + ${RM} ${COMMON_OBJECTS} ${PHP_OBJECTS} ${HHVM_OBJECTS} ${PHP_LIBRARY} ${HHVM_LIBRARY} -${OBJECTS}: - ${COMPILER} ${PHP_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp} +${COMMON_OBJECTS}: + ${COMPILER} ${COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp} ${PHP_OBJECTS}: ${COMPILER} ${PHP_COMPILER_FLAGS} -o $@ ${@:%.o=%.cpp} diff --git a/common/extensionbase.h b/common/extensionbase.h new file mode 100644 index 0000000..bf7f128 --- /dev/null +++ b/common/extensionbase.h @@ -0,0 +1,138 @@ +/** + * ExtensionBase.h + * + * Base class for ExtensionImpl objects. Common code used by both the Zend + * and HHVM engine. + * + * @author Emiel Bruijntjes + * @copyright 2013, 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Class definition + */ +class ExtensionBase +{ +protected: + /** + * Pointer to the extension object that is filled by the extension programmer + * @var Extension + */ + Extension *_data; + + /** + * Callback that is called after the engine is initialized and before the + * pageviews are going to be handled + * @var Callback + */ + Callback _onStartup; + + /** + * Callback that is called in front of each request + * @var Callback + */ + Callback _onRequest; + + /** + * Callback that is called right after each request + * @var Callback + */ + Callback _onIdle; + + /** + * Callback that is called right before the engine is closing down + * @var Callback + */ + Callback _onShutdown; + +public: + /** + * Constructor + * @param data Extension object created by the extension programmer + */ + ExtensionBase(Extension *data) : _data(data) {} + + /** + * No copy'ing and no moving + */ + ExtensionBase(const ExtensionImpl &extension) = delete; + ExtensionBase(ExtensionImpl &&extension) = delete; + + /** + * Destructor + */ + virtual ~ExtensionBase() {} + + /** + * Register a function to be called when the PHP engine is ready + * + * 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 + */ + void onStartup(const Callback &callback) + { + // copy callback + _onStartup = 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 + */ + void onShutdown(const Callback &callback) + { + // copy callback + _onShutdown = 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 + */ + void onRequest(const Callback &callback) + { + // copy callback + _onRequest = 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 + */ + void onIdle(const Callback &callback) + { + // copy callback + _onIdle = callback; + } +}; + +/** + * End of namespace + */ +} + diff --git a/hhvm/extension.cpp b/hhvm/extension.cpp new file mode 100644 index 0000000..9685b32 --- /dev/null +++ b/hhvm/extension.cpp @@ -0,0 +1,103 @@ +/** + * Extension.cpp + * + * @author Emiel Bruijntjes + * @copyright 2013, 2014 Copernica BV + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * Constructor that defines a number of functions right away + * @param name Extension name + * @param version Extension version string + */ +Extension::Extension(const char *name, const char *version) : + Namespace(""), _impl(new ExtensionImpl(this, name, version)) {} + +/** + * Destructor + */ +Extension::~Extension() +{ + // get rid of the implementation object + delete _impl; +} + +/** + * Register a function to be called when the PHP engine is ready + * @param callback + * @return Extension + */ +Extension &Extension::onStartup(const Callback &callback) +{ + // pass on to the implementation + _impl->onStartup(callback); + + // allow chaining + return *this; +} + +/** + * Register a function to be called when the PHP engine is going to stop + * @param callback + * @return Extension + */ +Extension &Extension::onShutdown(const Callback &callback) +{ + // pass on to the implementation + _impl->onShutdown(callback); + + // allow chaining + return *this; +} + +/** + * Register a callback that is called at the beginning of each pageview/request + * @param callback + */ +Extension &Extension::onRequest(const Callback &callback) +{ + // pass on to the implementation + _impl->onRequest(callback); + + // allow chaining + return *this; +} + +/** + * Register a callback that is called to cleanup things after a pageview/request + * @param callback + */ +Extension &Extension::onIdle(const Callback &callback) +{ + // pass on to the implementation + _impl->onIdle(callback); + + // allow chaining + return *this; +} + +/** + * Retrieve the module pointer + * + * This is the memory address that should be exported by the get_module() + * function. + * + * @return void* + */ +void *Extension::module() +{ + // pass on to the implementation + return _impl->module(); +} + +/** + * End of namespace + */ +} + diff --git a/hhvm/extensionimpl.h b/hhvm/extensionimpl.h new file mode 100644 index 0000000..deb80a6 --- /dev/null +++ b/hhvm/extensionimpl.h @@ -0,0 +1,55 @@ +/** + * ExtensionImpl.h + * + * Implementation of the extension object for the HHVM engine + * + * @author Emiel Bruijntjes + * @copyright 2014 Copernica BV + */ + +/** + * Namespace + */ +namespace Php { + +/** + * Class definition + */ +class ExtensionImpl : public ExtensionBase +{ +private: + /** + * Pointer to the extension object that is filled by the extension programmer + * @var Extension + */ + Extension *_data; + +public: + /** + * Constructor + * @param data Pointer to the extension object created by the extension programmer + * @param name Name of the extension + * @param version Version identifier of the extension + */ + ExtensionImpl(Extension *data, const char *name, const char *version) : ExtensionBase(data) {} + + /** + * Destructor + */ + virtual ~ExtensionImpl() {} + + /** + * Pointer to the module that is loaded by HHVM + * @return void* + */ + void *module() + { + return nullptr; + } +}; + +/** + * End of namespace + */ +} + diff --git a/hhvm/includes.h b/hhvm/includes.h new file mode 100644 index 0000000..b6f25c1 --- /dev/null +++ b/hhvm/includes.h @@ -0,0 +1,53 @@ +/** + * Includes.h + * + * All includes for compiling the HHVM implementation of PHP-CPP + * + * @author Emiel Bruijntjes + * @copyright 2014 Copernica BV + */ + +/** + * Standard C and C++ libraries + */ +#include +#include +#include +#include +#include +#include + +/** + * HHVM includes + */ + + +/** + * Public include files + */ +#include "../include/type.h" +#include "../include/hashparent.h" +#include "../include/value.h" +#include "../include/parameters.h" +#include "../include/classtype.h" +#include "../include/argument.h" +#include "../include/modifiers.h" +#include "../include/classbase.h" +#include "../include/interface.h" +#include "../include/iterator.h" +#include "../include/traversable.h" +#include "../include/serializable.h" +#include "../include/class.h" +#include "../include/namespace.h" +#include "../include/extension.h" + +/** + * Generic implementation header files + */ +#include "../common/extensionbase.h" + +/** + * Specific HHVM header files for the implementation only + */ +#include "extensionimpl.h" + diff --git a/zend/extensionimpl.cpp b/zend/extensionimpl.cpp index 9562362..77b9985 100644 --- a/zend/extensionimpl.cpp +++ b/zend/extensionimpl.cpp @@ -106,7 +106,7 @@ static ExtensionImpl *find(int number TSRMLS_DC) * @param tsrm_ls * @return int 0 on success */ -int ExtensionImpl::onStartup(int type, int module_number TSRMLS_DC) +int ExtensionImpl::processStartup(int type, int module_number TSRMLS_DC) { // initialize and allocate the "global" variables ZEND_INIT_MODULE_GLOBALS(phpcpp, init_globals, NULL); @@ -131,7 +131,7 @@ int ExtensionImpl::onStartup(int type, int module_number TSRMLS_DC) * @param tsrm_ls * @return int */ -int ExtensionImpl::onShutdown(int type, int module_number TSRMLS_DC) +int ExtensionImpl::processShutdown(int type, int module_number TSRMLS_DC) { // get the extension auto *extension = find(module_number TSRMLS_CC); @@ -150,7 +150,7 @@ int ExtensionImpl::onShutdown(int type, int module_number TSRMLS_DC) * @param tsrm_ls * @return int 0 on success */ -int ExtensionImpl::onRequest(int type, int module_number TSRMLS_DC) +int ExtensionImpl::processRequest(int type, int module_number TSRMLS_DC) { // get the extension auto *extension = find(module_number TSRMLS_CC); @@ -169,7 +169,7 @@ int ExtensionImpl::onRequest(int type, int module_number TSRMLS_DC) * @param tsrm_ls * @return int 0 on success */ -int ExtensionImpl::onIdle(int type, int module_number TSRMLS_DC) +int ExtensionImpl::processIdle(int type, int module_number TSRMLS_DC) { // get the extension auto *extension = find(module_number TSRMLS_CC); @@ -187,35 +187,35 @@ int ExtensionImpl::onIdle(int type, int module_number TSRMLS_DC) * @param name Name of the extension * @param version Version number */ -ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *version) : _data(data) +ExtensionImpl::ExtensionImpl(Extension *data, const char *name, const char *version) : ExtensionBase(data) { // keep extension pointer based on the name name2extension[name] = this; // assign all members (apart from the globals) - _entry.size = sizeof(zend_module_entry); // size of the data - _entry.zend_api = ZEND_MODULE_API_NO; // api number - _entry.zend_debug = ZEND_DEBUG; // debug mode enabled? - _entry.zts = USING_ZTS; // is thread safety enabled? - _entry.ini_entry = NULL; // the php.ini record - _entry.deps = NULL; // dependencies on other modules - _entry.name = name; // extension name - _entry.functions = NULL; // functions supported by this module (none for now) - _entry.module_startup_func = &ExtensionImpl::onStartup; // startup function for the whole extension - _entry.module_shutdown_func = &ExtensionImpl::onShutdown; // shutdown function for the whole extension - _entry.request_startup_func = &ExtensionImpl::onRequest; // startup function per request - _entry.request_shutdown_func = &ExtensionImpl::onIdle; // shutdown function per request - _entry.info_func = NULL; // information for retrieving info - _entry.version = version; // version string - _entry.globals_size = 0; // size of the global variables - _entry.globals_ctor = NULL; // constructor for global variables - _entry.globals_dtor = NULL; // destructor for global variables - _entry.post_deactivate_func = NULL; // unknown function - _entry.module_started = 0; // module is not yet started - _entry.type = 0; // temporary or persistent module, will be filled by Zend engine - _entry.handle = NULL; // dlopen() handle, will be filled by Zend engine - _entry.module_number = 0; // module number will be filled in by Zend engine - _entry.build_id = (char *)ZEND_MODULE_BUILD_ID; // check if extension and zend engine are compatible + _entry.size = sizeof(zend_module_entry); // size of the data + _entry.zend_api = ZEND_MODULE_API_NO; // api number + _entry.zend_debug = ZEND_DEBUG; // debug mode enabled? + _entry.zts = USING_ZTS; // is thread safety enabled? + _entry.ini_entry = NULL; // the php.ini record + _entry.deps = NULL; // dependencies on other modules + _entry.name = name; // extension name + _entry.functions = NULL; // functions supported by this module (none for now) + _entry.module_startup_func = &ExtensionImpl::processStartup; // startup function for the whole extension + _entry.module_shutdown_func = &ExtensionImpl::processShutdown; // shutdown function for the whole extension + _entry.request_startup_func = &ExtensionImpl::processRequest; // startup function per request + _entry.request_shutdown_func = &ExtensionImpl::processIdle; // shutdown function per request + _entry.info_func = NULL; // information for retrieving info + _entry.version = version; // version string + _entry.globals_size = 0; // size of the global variables + _entry.globals_ctor = NULL; // constructor for global variables + _entry.globals_dtor = NULL; // destructor for global variables + _entry.post_deactivate_func = NULL; // unknown function + _entry.module_started = 0; // module is not yet started + _entry.type = 0; // temporary or persistent module, will be filled by Zend engine + _entry.handle = NULL; // dlopen() handle, will be filled by Zend engine + _entry.module_number = 0; // module number will be filled in by Zend engine + _entry.build_id = (char *)ZEND_MODULE_BUILD_ID; // check if extension and zend engine are compatible // things that only need to be initialized #ifdef ZTS diff --git a/zend/extensionimpl.h b/zend/extensionimpl.h index cc37354..e58ce66 100644 --- a/zend/extensionimpl.h +++ b/zend/extensionimpl.h @@ -15,15 +15,9 @@ namespace Php { /** * Class definition */ -class ExtensionImpl +class ExtensionImpl : public ExtensionBase { protected: - /** - * Pointer to the extension object that is filled by the extension programmer - * @var Extension - */ - Extension *_data; - /** * The information that is passed to the Zend engine * @@ -34,32 +28,7 @@ protected: * @var zend_module_entry */ zend_module_entry _entry; - - /** - * Callback that is called after the engine is initialized and before the - * pageviews are going to be handled - * @var Callback - */ - Callback _onStartup; - - /** - * Callback that is called in front of each request - * @var Callback - */ - Callback _onRequest; - - /** - * Callback that is called right after each request - * @var Callback - */ - Callback _onIdle; - - /** - * Callback that is called right before the engine is closing down - * @var Callback - */ - Callback _onShutdown; - + public: /** * Constructor @@ -80,68 +49,6 @@ public: */ virtual ~ExtensionImpl(); - /** - * Register a function to be called when the PHP engine is ready - * - * 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 - */ - void onStartup(const Callback &callback) - { - // copy callback - _onStartup = 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 - */ - void onShutdown(const Callback &callback) - { - // copy callback - _onShutdown = 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 - */ - void onRequest(const Callback &callback) - { - // copy callback - _onRequest = 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 - */ - void onIdle(const Callback &callback) - { - // copy callback - _onIdle = callback; - } - /** * Retrieve the module entry * @@ -175,7 +82,7 @@ private: * @param tsrm_ls * @return int 0 on success */ - static int onStartup(int type, int module_number TSRMLS_DC); + static int processStartup(int type, int module_number TSRMLS_DC); /** * Function that is called when the extension is about to be stopped @@ -184,7 +91,7 @@ private: * @param tsrm_ls * @return int */ - static int onShutdown(int type, int module_number TSRMLS_DC); + static int processShutdown(int type, int module_number TSRMLS_DC); /** * Function that is called when a request starts @@ -193,7 +100,7 @@ private: * @param tsrm_ls * @return int 0 on success */ - static int onRequest(int type, int module_number TSRMLS_DC); + static int processRequest(int type, int module_number TSRMLS_DC); /** * Function that is called when a request is ended @@ -202,7 +109,7 @@ private: * @param tsrm_ls * @return int 0 on success */ - static int onIdle(int type, int module_number TSRMLS_DC); + static int processIdle(int type, int module_number TSRMLS_DC); }; /** diff --git a/zend/includes.h b/zend/includes.h index f547eb2..50eb4d5 100644 --- a/zend/includes.h +++ b/zend/includes.h @@ -76,7 +76,12 @@ #include "../include/call.h" /** - * Interface files for internal use only + * Common header files for internal use only + */ +#include "../common/extensionbase.h" + +/** + * Specific zend implementation files for internal use only */ #include "init.h" #include "callable.h" -- cgit v1.2.3