This repository has been archived on 2020-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
ext-collections/src/collections.c

93 lines
2.8 KiB
C
Raw Normal View History

2018-03-21 08:21:28 +00:00
//
// ext-collections/collections.c
//
// @Author CismonX
//
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2018-09-07 08:00:08 +00:00
#include "php_collections.h"
#include <zend_interfaces.h>
2018-03-21 08:21:28 +00:00
#include <ext/standard/info.h>
2018-08-09 08:33:39 +00:00
zend_object_handlers collection_handlers;
2018-03-23 09:06:05 +00:00
zend_class_entry* collections_collection_ce;
zend_class_entry* collections_pair_ce;
ZEND_DECLARE_MODULE_GLOBALS(collections)
static zend_always_inline void collection_ce_init()
2018-03-21 08:21:28 +00:00
{
2018-03-23 09:06:05 +00:00
zend_class_entry collection_ce;
2018-03-26 05:54:01 +00:00
INIT_CLASS_ENTRY_EX(collection_ce, "Collection", sizeof "Collection" - 1, collection_methods);
2018-03-23 09:06:05 +00:00
collections_collection_ce = zend_register_internal_class(&collection_ce);
2018-08-20 14:47:23 +00:00
zend_declare_class_constant_long(collections_collection_ce,
"COMPARE_NATRUAL", sizeof "COMPARE_NATRUAL" - 1, PHP_COLLECTIONS_COMPARE_NATURAL);
zend_declare_class_constant_long(collections_collection_ce,
"FOLD_CASE", sizeof "FOLD_CASE" - 1, PHP_COLLECTIONS_FOLD_CASE);
zend_class_implements(collections_collection_ce,
#if PHP_VERSION_ID < 70200
1,
#else
2, zend_ce_countable,
#endif
zend_ce_arrayaccess);
2018-08-09 08:33:39 +00:00
memcpy(&collection_handlers, &std_object_handlers, sizeof(zend_object_handlers));
collection_handlers.unset_dimension = collection_offset_unset;
collection_handlers.unset_property = collection_property_unset;
2018-08-09 08:33:39 +00:00
collection_handlers.write_dimension = collection_offset_set;
collection_handlers.write_property = collection_property_set;
2018-08-09 08:33:39 +00:00
collection_handlers.read_dimension = collection_offset_get;
collection_handlers.read_property = collection_property_get;
2018-08-09 08:33:39 +00:00
collection_handlers.has_dimension = collection_offset_exists;
collection_handlers.has_property = collection_property_exists;
collection_handlers.count_elements = count_collection;
}
static zend_always_inline void pair_ce_init()
{
2018-03-23 09:06:05 +00:00
zend_class_entry pair_ce;
2018-03-26 05:54:01 +00:00
INIT_CLASS_ENTRY_EX(pair_ce, "Pair", sizeof "Pair" - 1, pair_methods);
2018-03-23 09:06:05 +00:00
collections_pair_ce = zend_register_internal_class(&pair_ce);
zend_declare_property_null(collections_pair_ce, "first", sizeof "first" - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(collections_pair_ce, "second", sizeof "second" - 1, ZEND_ACC_PUBLIC);
}
PHP_MINIT_FUNCTION(collections)
{
#ifdef ZTS
ZEND_INIT_MODULE_GLOBALS(collections, NULL, NULL);
#endif
collection_ce_init();
pair_ce_init();
2018-03-21 08:26:14 +00:00
return SUCCESS;
2018-03-21 08:21:28 +00:00
}
PHP_MINFO_FUNCTION(collections)
{
2018-03-21 08:26:14 +00:00
php_info_print_table_start();
php_info_print_table_header(2, "collections support", "enabled");
php_info_print_table_end();
2018-03-21 08:21:28 +00:00
}
zend_module_entry collections_module_entry = {
2018-03-21 08:26:14 +00:00
STANDARD_MODULE_HEADER,
"collections",
NULL,
PHP_MINIT(collections),
2018-03-26 05:54:01 +00:00
NULL,
NULL,
2018-03-21 08:26:14 +00:00
NULL,
PHP_MINFO(collections),
PHP_COLLECTIONS_VERSION,
STANDARD_MODULE_PROPERTIES
2018-03-21 08:21:28 +00:00
};
#ifdef COMPILE_DL_COLLECTIONS
ZEND_GET_MODULE(collections)
#endif