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

//точки входа в интерфейс и класс
static zend_class_entry *iworldEntry;
static zend_class_entry *helloEntry;

//декларация метода Hello::say
PHP_METHOD(Hello, say);

//таблица функций для интерфейса IWorld
static const zend_function_entry iworld_methods[] = {
    PHP_ABSTRACT_ME(IWorld, say, NULL)
    PHP_FE_END
};

//таблица функций для класса Hello
static const zend_function_entry hello_methods[] = {
    PHP_ME(Hello, say, NULL, ZEND_ACC_PUBLIC)
    PHP_FE_END
};


static PHP_MINIT_FUNCTION(hello_world) {
    //инициализируем интерефейс IWorld с таблицей методов iworld_methods
    zend_class_entry ie;
    INIT_CLASS_ENTRY(ie, "IWorld", iworld_methods);
    iworldEntry = zend_register_internal_interface(&ie);

    //инициализируем класс Hello с таблицей методов hello_methods
    zend_class_entry ce;
    INIT_CLASS_ENTRY(ce, "Hello", hello_methods);
    //делаем класс не абстрактным
    ce.ce_flags ^= ZEND_ACC_ABSTRACT;
    helloEntry = zend_register_internal_class(&ce);
    //реализуем интерфейс IWorld
    zend_class_implements(&*helloEntry, 1, iworldEntry);
}

// 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, say) {
    printf("Hello World\n");
}