This commit is contained in:
CismonX 2018-03-23 17:06:05 +08:00
parent ef1254ed94
commit 4498f7f5a9
8 changed files with 658 additions and 19 deletions

View File

@ -14,12 +14,32 @@
#include "php_collections.h"
zend_string* collection_property_name;
zend_string* pair_first_name;
zend_string* pair_second_name;
zend_class_entry* collections_collection_ce;
zend_class_entry* collections_pair_ce;
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);
collection_property_name = zend_string_init("_a", strlen("_a"), 1);
pair_first_name = zend_string_init("first", strlen("first"), 1);
pair_second_name = zend_string_init("first", strlen("second"), 1);
zend_class_entry collection_ce;
INIT_CLASS_ENTRY_EX(collection_ce, "Collection", strlen("Collection"), collection_methods);
collections_collection_ce = zend_register_internal_class(&collection_ce);
zend_class_entry pair_ce;
INIT_CLASS_ENTRY_EX(pair_ce, "Pair", strlen("Pair"), pair_methods);
collections_pair_ce = zend_register_internal_class(&pair_ce);
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(collections)
{
zend_string_release(collection_property_name);
zend_string_release(pair_first_name);
zend_string_release(pair_second_name);
return SUCCESS;
}
@ -43,7 +63,7 @@ zend_module_entry collections_module_entry = {
"collections",
NULL,
PHP_MINIT(collections),
NULL,
PHP_MSHUTDOWN(collections),
PHP_RINIT(collections),
NULL,
PHP_MINFO(collections),

View File

@ -3,6 +3,7 @@
//
// @Author CismonX
//
#include <php.h>
#include "php_collections.h"

606
collections_methods.c Normal file
View File

@ -0,0 +1,606 @@
//
// ext-collections/collections_methods.c
//
// @Author CismonX
//
#include <php.h>
#include "php_collections.h"
#include "php_collections_fe.h"
#define NEW_COLLECTION_OBJ(name) \
zend_object* (name) = (zend_object*)ecalloc(1, sizeof(zend_object) + \
zend_object_properties_size(collections_collection_ce)); \
zend_object_std_init(name, collections_collection_ce); \
object_properties_init(name, collections_collection_ce); \
obj->handlers = &std_object_handlers;
#define IS_COLLECTION(zval) \
Z_TYPE_P(elements) == IS_OBJECT && Z_OBJCE_P(elements) == collections_collection_ce
#define COLLECTION_UPDATE(obj, value) \
zend_update_property_ex(zend_get_executed_scope(), obj, collection_property_name, value)
#define COLLECTION_UPDATE_EX(value) COLLECTION_UPDATE(getThis(), value)
#define COLLECTION_FETCH(obj) \
zend_read_property_ex(zend_get_executed_scope(), obj, collection_property_name, 1, &rv)
#define COLLECTION_FETCH_EX() COLLECTION_FETCH(getThis())
#define PHP_COLLECTIONS_ERROR(type, msg) php_error_docref(NULL, type, msg)
#define ERR_BAD_ARGUMENT_TYPE() PHP_COLLECTIONS_ERROR(E_WARNING, "Bad argument type")
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)
{
zval* elements = NULL;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(elements)
ZEND_PARSE_PARAMETERS_END();
NEW_COLLECTION_OBJ(obj);
zval retval;
ZVAL_OBJ(&retval, obj);
if (elements) {
if (IS_COLLECTION(elements)) {
zval rv;
elements = COLLECTION_FETCH(elements);
} else if (UNEXPECTED(Z_TYPE_P(elements) != IS_ARRAY)) {
ERR_BAD_ARGUMENT_TYPE();
RETVAL_NULL();
}
COLLECTION_UPDATE(&retval, elements);
} else {
zval collection;
ZVAL_NEW_ARR(&collection);
zend_hash_init(Z_ARRVAL(collection), 0, NULL, ZVAL_PTR_DTOR, 0);
COLLECTION_UPDATE(&retval, &collection);
zval_ptr_dtor(&collection);
}
ZVAL_COPY_VALUE(return_value, &retval);
}
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, sliceRange)
{
}
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)
{
zval rv;
zval* data = COLLECTION_FETCH_EX();
RETVAL_ZVAL(data, 1, 0);
}
PHP_METHOD(Collection, toCollection)
{
}
PHP_METHOD(Collection, toPairs)
{
}
PHP_METHOD(Collection, union)
{
}
PHP_METHOD(Collection, values)
{
}
PHP_METHOD(Pair, __construct)
{
}

View File

@ -6,9 +6,9 @@ PHP_ARG_ENABLE(collections, for debug support,
if test "$PHP_COLLECTIONS" != "no"; then
if test "$PHP_COLLECTIONS_DEBUG" != "no"; then
CFLAGS="-O2"
else
CFLAGS="-g -O0"
else
CFLAGS="-O2"
fi
COLLECTIONS_SRC="collections.c collections_fe.c collections_methods.c"
PHP_NEW_EXTENSION(collections, $COLLECTIONS_SRC, $ext_shared)

View File

@ -10,12 +10,6 @@
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;
extern const zend_function_entry collection_methods[];
extern const zend_function_entry pair_methods[];
#define PHP_COLLECTIONS_VERSION "0.1.0"
#ifdef PHP_WIN32
@ -26,6 +20,16 @@ extern const zend_function_entry pair_methods[];
#define PHP_COLLECTIONS_API
#endif
extern zend_string* collection_property_name;
extern zend_string* pair_first_name;
extern zend_string* pair_second_name;
extern PHP_COLLECTIONS_API zend_class_entry* collections_collection_ce;
extern PHP_COLLECTIONS_API zend_class_entry* collections_pair_ce;
extern const zend_function_entry collection_methods[];
extern const zend_function_entry pair_methods[];
#ifdef ZTS
#include "TSRM.h"
#endif

View File

@ -7,8 +7,6 @@
#ifndef PHP_COLLECTIONS_FE_H
#define PHP_COLLECTIONS_FE_H
#include <php.h>
PHP_METHOD(Collection, __construct);
PHP_METHOD(Collection, addAll);
PHP_METHOD(Collection, all);

View File

@ -418,7 +418,7 @@ class Collection implements ArrayAccess, Countable
* Returns a collection containing the results of applying the given transform function
* to each element in the original collection.
*
* @param callable $transform ($value, $key) -> $new_value
* @param callable $transform ($value, $key) -> Pair
* @return Collection
*/
function map($transform) {}
@ -447,7 +447,7 @@ class Collection implements ArrayAccess, Countable
* results to the given destination.
*
* @param Collection $destination
* @param callable $transform ($value, $key) -> $new_value
* @param callable $transform ($value, $key) -> Pair
* @return Collection
*/
function mapTo($destination, $transform) {}

View File

@ -5,15 +5,25 @@
*/
class Pair
{
/**
* First value of the pair.
*
* @var mixed $first
*/
public $first;
/**
* Second value of the pair.
*
* @var mixed $second
*/
public $second;
/**
* Constructor.
*
* @param $first
* @param $second
* @param mixed $first
* @param mixed $second
*/
function __construct($first, $second) {}
}