#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <main/php.h>
#include <stdio.h>


PHP_METHOD(Hello, __construct);
PHP_METHOD(Hello, say);

static const zend_function_entry hello_methods[] = {
    PHP_ME(Hello, __construct, NULL, ZEND_ACC_PUBLIC)
    PHP_ME(Hello, say, NULL, ZEND_ACC_PUBLIC)
    PHP_FE_END
};


static PHP_MINIT_FUNCTION(hello_world) {
    zend_class_entry ce;
    zend_class_entry ie;
    INIT_CLASS_ENTRY(ce, "Hello", hello_methods);
    INIT_CLASS_ENTRY(ie, "IWorld", NULL);
    zend_class_entry *rie = zend_register_internal_interface(&ie);
    zend_class_entry *rce = zend_register_internal_class(&ce);
    zend_class_implements(&*rce, 1, rie);
    rce->ce_flags |= ZEND_ACC_FINAL_CLASS;
}

// list of custom PHP functions provided by this extension
// set {NULL, NULL, NULL} as the last record to mark the end of list
static zend_function_entry my_functions[] = {
    PHP_FE_END
};

// the following code creates an entry for the module and registers it with Zend.
zend_module_entry hello_world_module_entry = {
    STANDARD_MODULE_HEADER,
    "hello_world",
    my_functions,
    PHP_MINIT(hello_world), // name of the MINIT function or NULL if not applicable
    NULL, // name of the MSHUTDOWN function or NULL if not applicable
    NULL, // name of the RINIT function or NULL if not applicable
    NULL, // name of the RSHUTDOWN function or NULL if not applicable
    NULL, // name of the MINFO function or NULL if not applicable
    NO_VERSION_YET,
    STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(hello_world)

PHP_METHOD(Hello, __construct) {
    /* nothing */
}

PHP_METHOD(Hello, say) {
    php_printf("Hello world\n");
}
