This commit is contained in:
CismonX 2018-03-21 16:21:28 +08:00
parent 512d04ff19
commit 7e15ed8f39
8 changed files with 355 additions and 4 deletions

35
.gitignore vendored Normal file
View File

@ -0,0 +1,35 @@
.deps
*.lo
*.la
.libs
acinclude.m4
aclocal.m4
autom4te.cache
build
config.guess
config.h
config.h.in
config.log
config.nice
config.status
config.sub
configure
configure.in
include
install-sh
libtool
ltmain.sh
Makefile
Makefile.fragments
Makefile.global
Makefile.objects
missing
mkinstalldirs
modules
run-tests.php
tests/*/*.diff
tests/*/*.out
tests/*/*.php
tests/*/*.exp
tests/*/*.log
tests/*/*.sh

59
collections.c Normal file
View File

@ -0,0 +1,59 @@
//
// ext-collections/collections.c
//
// @Author CismonX
//
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <php.h>
#include <php_ini.h>
#include <ext/standard/info.h>
#include "php_collections.h"
PHP_MINIT_FUNCTION(collections)
{
INIT_CLASS_ENTRY_EX(collections_collection_ce, "Collection", strlen("Collection"), collection_methods);
zend_register_internal_class(&collections_collection_ce);
INIT_CLASS_ENTRY_EX(collections_pair_ce, "Pair", strlen("Pair"), pair_methods);
zend_register_internal_class(&collections_pair_ce);
return SUCCESS;
}
PHP_RINIT_FUNCTION(collections)
{
#if defined(COMPILE_DL_COLLECTIONS) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
PHP_MINFO_FUNCTION(collections)
{
php_info_print_table_start();
php_info_print_table_header(2, "collections support", "enabled");
php_info_print_table_end();
}
zend_module_entry collections_module_entry = {
STANDARD_MODULE_HEADER,
"collections",
NULL,
PHP_MINIT(collections),
NULL,
PHP_RINIT(collections),
NULL,
PHP_MINFO(collections),
PHP_COLLECTIONS_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_COLLECTIONS
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(collections)
#endif

63
collections_fe.c Normal file
View File

@ -0,0 +1,63 @@
//
// ext-collections/collections_fe.c
//
// @Author CismonX
//
#include <php.h>
#include "php_collections.h"
#include "php_collections_fe.h"
ZEND_BEGIN_ARG_INFO(action_arginfo, 0)
ZEND_ARG_CALLABLE_INFO(0, action, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(element_arginfo, 0)
ZEND_ARG_INFO(0, element)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(elements_arginfo, 0)
ZEND_ARG_INFO(0, elements)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(predicate_arginfo, 0)
ZEND_ARG_CALLABLE_INFO(0, predicate, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(selector_arginfo, 0)
ZEND_ARG_CALLABLE_INFO(0, selector, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(other_arginfo, 0)
ZEND_ARG_INFO(0, other)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(transform_arginfo, 0)
ZEND_ARG_CALLABLE_INFO(0, transform, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(associate_by_arginfo, 0)
ZEND_ARG_CALLABLE_INFO(0, key_selector, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(associate_by_to_arginfo, 0)
ZEND_ARG_OBJ_INFO(0, destination, Collection, 0)
ZEND_ARG_CALLABLE_INFO(0, key_selector, 0)
ZEND_END_ARG_INFO()
const zend_function_entry collections_collection_methods[] = {
PHP_ME(Collection, __construct, NULL, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
PHP_ME(Collection, addAll, elements_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, all, predicate_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, any, predicate_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, associate, transform_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, associateBy, associate_by_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, associateByTo, associate_by_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(Collection, average, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Collection, containsAll, other_arginfo, ZEND_ACC_PUBLIC)
PHP_FE_END
};
const zend_function_entry collections_pair_methods[] = {
PHP_FE_END
};

15
config.m4 Normal file
View File

@ -0,0 +1,15 @@
PHP_ARG_ENABLE(collections, for collections support,
[ --enable-collections Enable collections support])
PHP_ARG_ENABLE(collections, for debug support,
[ --enable-collections-debug Compile with debug symbols])
if test "$PHP_COLLECTIONS" != "no"; then
if test "$PHP_COLLECTIONS_DEBUG" != "no"; then
EXTRA_CFLAGS="-O2"
else
EXTRA_CFLAGS="-g -O0"
fi
COLLECTIONS_SRC="collections.c collections_fe.c collections_methods.c"
PHP_NEW_EXTENSION(collections, $COLLECTIONS_SRC, $ext_shared,, $EXTRA_CFLAGS)
fi

5
config.w32 Normal file
View File

@ -0,0 +1,5 @@
ARG_ENABLE("collections", "enable collections support", "no");
if (PHP_COLLECTIONS != "no") {
EXTENSION("collections", "collections.c collections_fe.c collections_methods.c", true);
}

37
php_collections.h Normal file
View File

@ -0,0 +1,37 @@
//
// ext-collections/php_collections.h
//
// @Author CismonX
//
#ifndef PHP_COLLECTIONS_H
#define PHP_COLLECTIONS_H
extern zend_module_entry collections_module_entry;
#define phpext_collections_ptr &collections_module_entry
extern zend_class_entry collections_collection_ce;
extern zend_class_entry collections_pair_ce;
const zend_function_entry collection_methods[];
const zend_function_entry pair_methods[];
#define PHP_COLLECTIONS_VERSION "0.1.0"
#ifdef PHP_WIN32
#define PHP_COLLECTIONS_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
#define PHP_COLLECTIONS_API __attribute__ ((visibility("default")))
#else
#define PHP_COLLECTIONS_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#if defined(ZTS) && defined(COMPILE_DL_COLLECTIONS)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
#endif // !PHP_COLLECTIONS_FE_H

123
php_collections_fe.h Normal file
View File

@ -0,0 +1,123 @@
//
// ext-collections/php_collections_fe.h
//
// @Author CismonX
//
#ifndef PHP_COLLECTIONS_FE_H
#define PHP_COLLECTIONS_FE_H
#include <php.h>
#include "php_collections.h"
PHP_METHOD(Collection, __construct);
PHP_METHOD(Collection, addAll);
PHP_METHOD(Collection, all);
PHP_METHOD(Collection, any);
PHP_METHOD(Collection, associate);
PHP_METHOD(Collection, associateTo);
PHP_METHOD(Collection, associateBy);
PHP_METHOD(Collection, associateByTo);
PHP_METHOD(Collection, average);
PHP_METHOD(Collection, containsAll);
PHP_METHOD(Collection, containsKey);
PHP_METHOD(Collection, containsValue);
PHP_METHOD(Collection, copyOf);
PHP_METHOD(Collection, copyOfRange);
PHP_METHOD(Collection, count);
PHP_METHOD(Collection, distinct);
PHP_METHOD(Collection, distinctBy);
PHP_METHOD(Collection, drop);
PHP_METHOD(Collection, dropLast);
PHP_METHOD(Collection, dropLastWhile);
PHP_METHOD(Collection, dropWhile);
PHP_METHOD(Collection, fill);
PHP_METHOD(Collection, filter);
PHP_METHOD(Collection, filterNot);
PHP_METHOD(Collection, filterNotTo);
PHP_METHOD(Collection, filterTo);
PHP_METHOD(Collection, find);
PHP_METHOD(Collection, findLast);
PHP_METHOD(Collection, first);
PHP_METHOD(Collection, flatMap);
PHP_METHOD(Collection, flatMapTo);
PHP_METHOD(Collection, flatten);
PHP_METHOD(Collection, fold);
PHP_METHOD(Collection, foldRight);
PHP_METHOD(Collection, forEach);
PHP_METHOD(Collection, get);
PHP_METHOD(Collection, groupBy);
PHP_METHOD(Collection, groupByTo);
PHP_METHOD(Collection, indexOf);
PHP_METHOD(Collection, indexOfFirst);
PHP_METHOD(Collection, indexOfLast);
PHP_METHOD(Collection, init);
PHP_METHOD(Collection, intersect);
PHP_METHOD(Collection, isEmpty);
PHP_METHOD(Collection, isNotEmpty);
PHP_METHOD(Collection, keys);
PHP_METHOD(Collection, last);
PHP_METHOD(Collection, lastIndexOf);
PHP_METHOD(Collection, map);
PHP_METHOD(Collection, mapKeys);
PHP_METHOD(Collection, mapKeysTo);
PHP_METHOD(Collection, mapTo);
PHP_METHOD(Collection, mapValues);
PHP_METHOD(Collection, mapValuesTo);
PHP_METHOD(Collection, max);
PHP_METHOD(Collection, maxBy);
PHP_METHOD(Collection, maxWith);
PHP_METHOD(Collection, min);
PHP_METHOD(Collection, minBy);
PHP_METHOD(Collection, minWith);
PHP_METHOD(Collection, minus);
PHP_METHOD(Collection, minusAssign);
PHP_METHOD(Collection, minusKeys);
PHP_METHOD(Collection, minusKeysAssign);
PHP_METHOD(Collection, minusValues);
PHP_METHOD(Collection, minusValuesAssign);
PHP_METHOD(Collection, none);
PHP_METHOD(Collection, offsetUnset);
PHP_METHOD(Collection, offsetSet);
PHP_METHOD(Collection, offsetGet);
PHP_METHOD(Collection, offsetExists);
PHP_METHOD(Collection, onEach);
PHP_METHOD(Collection, orEmpty);
PHP_METHOD(Collection, partition);
PHP_METHOD(Collection, plus);
PHP_METHOD(Collection, plusAssign);
PHP_METHOD(Collection, plusValues);
PHP_METHOD(Collection, plusValuesAssign);
PHP_METHOD(Collection, putAll);
PHP_METHOD(Collection, reduce);
PHP_METHOD(Collection, reduceRight);
PHP_METHOD(Collection, remove);
PHP_METHOD(Collection, removeAll);
PHP_METHOD(Collection, retainAll);
PHP_METHOD(Collection, reverse);
PHP_METHOD(Collection, reversed);
PHP_METHOD(Collection, shuffle);
PHP_METHOD(Collection, single);
PHP_METHOD(Collection, slice);
PHP_METHOD(Collection, sort);
PHP_METHOD(Collection, sortBy);
PHP_METHOD(Collection, sortByDescending);
PHP_METHOD(Collection, sortDescending);
PHP_METHOD(Collection, sortWith);
PHP_METHOD(Collection, sorted);
PHP_METHOD(Collection, sortedBy);
PHP_METHOD(Collection, sortedByDescending);
PHP_METHOD(Collection, sortedDescending);
PHP_METHOD(Collection, sortedWith);
PHP_METHOD(Collection, take);
PHP_METHOD(Collection, takeLast);
PHP_METHOD(Collection, takeLastWhile);
PHP_METHOD(Collection, takeWhile);
PHP_METHOD(Collection, toArray);
PHP_METHOD(Collection, toCollection);
PHP_METHOD(Collection, toPairs);
PHP_METHOD(Collection, union);
PHP_METHOD(Collection, values);
#endif // !PHP_COLLECTIONS_FE_H

View File

@ -84,18 +84,18 @@ class Collection implements ArrayAccess, Countable
/**
* Checks if all elements in the specified collection are contained in this collection.
*
* @param Collection $collection
* @param array|Collection $other
* @return bool
*/
function containsAll($collection) {}
function containsAll($other) {}
/**
* Checks if the array contains the given key.
*
* @param int|string $element
* @param int|string $key
* @return bool
*/
function containsKey($element) {}
function containsKey($key) {}
/**
* Check if the array maps one or more keys to the specified value.
@ -391,6 +391,13 @@ class Collection implements ArrayAccess, Countable
*/
function isNotEmpty() {}
/**
* Return a collection of all keys in the collection.
*
* @return Collection
*/
function keys() {}
/**
* Returns the last element matching the given predicate.
*
@ -881,4 +888,11 @@ class Collection implements ArrayAccess, Countable
* @param array|Collection $other
*/
function union($other) {}
/**
* Return a collection of all values of the collection.
*
* @return Collection
*/
function values() {}
}