1 Star 0 Fork 347

Yurnero/swoole-src

forked from swoole/swoole-src 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PHP_API.hpp 74.02 KB
一键复制 编辑 原始数据 按行查看 历史
韩天峰 提交于 2017-03-28 18:38 . update c++ api.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828
/*
+----------------------------------------------------------------------+
| Swoole |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| license@swoole.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Tianfeng Han <mikan.tenny@gmail.com> |
+----------------------------------------------------------------------+
*/
#pragma once
extern "C"
{
#include "php.h"
#include "php_ini.h"
#include "php_globals.h"
#include "php_main.h"
#include "zend_API.h"
#include "php_streams.h"
#include "php_network.h"
#if PHP_MAJOR_VERSION < 7
#error "only supports PHP7 or later."
#endif
#include "zend_interfaces.h"
#include "zend_exceptions.h"
#include "zend_variables.h"
#include "zend_inheritance.h"
#include <ext/date/php_date.h>
#include <ext/standard/url.h>
#include <ext/standard/info.h>
#include <ext/standard/php_array.h>
#include "ext/standard/php_var.h"
}
#include <unordered_map>
#include <string>
#include <vector>
#ifdef ECLIPSE_HELPER
#include <map>
#define unordered_map map
#define nullptr_t void*
#endif
#define MAX_ARGC 20
#define VAR_DUMP_LEVEL 10
using namespace std;
namespace PHP
{
struct Resource
{
const char *name;
int type;
};
static unordered_map<string, Resource *> resource_map;
class Variant
{
public:
Variant()
{
init();
ZVAL_NULL(&val);
}
Variant(nullptr_t v)
{
init();
ZVAL_NULL(&val);
}
Variant(long v)
{
init();
ZVAL_LONG(&val, v);
}
Variant(int v)
{
init();
ZVAL_LONG(&val, (long )v);
}
Variant(const char *str)
{
init();
ZVAL_STRING(&val, str);
}
Variant(const char *str, size_t len)
{
init();
ZVAL_STRINGL(&val, str, len);
}
Variant(string &str)
{
init();
ZVAL_STRINGL(&val, str.c_str(), str.length());
}
Variant(double v)
{
init();
ZVAL_DOUBLE(&val, v);
}
Variant(float v)
{
init();
ZVAL_DOUBLE(&val, (double )v);
}
Variant(bool v)
{
init();
ZVAL_BOOL(&val, v);
}
Variant(zval *v)
{
reference = false;
ref_val = NULL;
memcpy(&val, v, sizeof(zval));
zval_add_ref(&val);
}
Variant(zval *v, bool ref)
{
ref_val = v;
reference = ref;
}
Variant(zend_resource *res)
{
init();
ZVAL_RES(ptr(), res);
}
~Variant()
{
if (!reference)
{
zval_ptr_dtor(&val);
}
}
void operator =(int v)
{
ZVAL_LONG(ptr(), (long )v);
}
void operator =(long v)
{
ZVAL_LONG(ptr(), v);
}
void operator =(string &str)
{
ZVAL_STRINGL(ptr(), str.c_str(), str.length());
}
void operator =(const char *str)
{
ZVAL_STRING(ptr(), str);
}
void operator =(double v)
{
ZVAL_DOUBLE(ptr(), v);
}
void operator =(float v)
{
ZVAL_DOUBLE(ptr(), (double )v);
}
void operator =(bool v)
{
ZVAL_BOOL(ptr(), v);
}
inline zval *ptr(void)
{
if (reference)
{
return ref_val;
}
else
{
return &val;
}
}
inline void addRef()
{
zval_add_ref(ptr());
}
inline int type()
{
return Z_TYPE_P(ptr());
}
inline bool isString()
{
return Z_TYPE_P(ptr()) == IS_STRING;
}
inline bool isArray()
{
return Z_TYPE_P(ptr()) == IS_ARRAY;
}
inline bool isObject()
{
return Z_TYPE_P(ptr()) == IS_OBJECT;
}
inline bool isInt()
{
return Z_TYPE_P(ptr()) == IS_LONG;
}
inline bool isFloat()
{
return Z_TYPE_P(ptr()) == IS_DOUBLE;
}
inline bool isBool()
{
return Z_TYPE_P(ptr()) == IS_TRUE || Z_TYPE_P(ptr()) == IS_FALSE;
}
inline bool isNull()
{
return Z_TYPE_P(ptr()) == IS_NULL;
}
inline bool isResource()
{
return Z_TYPE_P(ptr()) == IS_RESOURCE;
}
inline bool isReference()
{
return Z_TYPE_P(ptr()) == IS_REFERENCE;
}
inline string toString()
{
if (!isString())
{
convert_to_string(ptr());
}
return string(Z_STRVAL_P(ptr()), Z_STRLEN_P(ptr()));
}
inline char* toCString()
{
if (!isString())
{
convert_to_string(ptr());
}
return Z_STRVAL_P(ptr());
}
inline long toInt()
{
if (!isInt())
{
convert_to_long(ptr());
}
return Z_LVAL_P(ptr());
}
inline double toFloat()
{
if (!isFloat())
{
convert_to_double(ptr());
}
return Z_DVAL_P(ptr());
}
inline bool toBool()
{
if (!isBool())
{
convert_to_boolean(ptr());
}
return Z_TYPE_P(ptr()) == IS_TRUE;
}
void copy(Variant &v)
{
ZVAL_COPY_VALUE(ptr(), v.ptr());
addRef();
}
inline int length()
{
if (!isString())
{
convert_to_string(ptr());
}
return Z_STRLEN_P(ptr());
}
template<class T>
T* toResource(const char *name)
{
if (!isResource())
{
php_error_docref(NULL, E_WARNING, "Variant is not a resource type.");
return NULL;
}
void *_ptr = NULL;
Resource *_c = resource_map[name];
if ((_ptr = zend_fetch_resource(Z_RES_P(ptr()), name, _c->type)) == NULL)
{
return NULL;
}
return static_cast<T *>(_ptr);
}
protected:
bool reference;
zval *ref_val;
zval val;
inline void init()
{
reference = false;
ref_val = NULL;
memset(&val, 0, sizeof(val));
}
};
class String
{
public:
String(const char *str)
{
value = zend_string_init(str, strlen(str), 0);
}
String(const char *str, size_t len)
{
value = zend_string_init(str, len, 0);
}
String(string &str)
{
value = zend_string_init(str.c_str(), str.length(), 0);
}
size_t length()
{
return value->len;
}
char* c_str()
{
return value->val;
}
~String()
{
zend_string_free(value);
}
void extend(size_t new_size)
{
value = zend_string_extend(value, new_size, 0);
}
void tolower()
{
zend_str_tolower(value->val, value->len);
}
zend_string* ptr()
{
return value;
}
protected:
zend_string *value;
};
class ArrayIterator
{
public:
ArrayIterator(Bucket *p)
{
_ptr = p;
_key = _ptr->key;
_val = &_ptr->val;
_index = _ptr->h;
pe = p;
}
ArrayIterator(Bucket *p, Bucket *_pe)
{
_ptr = p;
_key = _ptr->key;
_val = &_ptr->val;
_index = _ptr->h;
pe = _pe;
}
void operator ++(int i)
{
while (1)
{
_ptr++;
_val = &_ptr->val;
if (_val && Z_TYPE_P(_val) == IS_INDIRECT)
{
_val = Z_INDIRECT_P(_val);
}
if (UNEXPECTED(Z_TYPE_P(_val) == IS_UNDEF) && pe != _ptr)
{
continue;
}
if (_ptr->key)
{
_key = _ptr->key;
_index = 0;
}
else
{
_index = _ptr->h;
_key = NULL;
}
break;
}
}
bool operator !=(ArrayIterator b)
{
return b.ptr() != _ptr;
}
Variant key()
{
if (_key)
{
return Variant(_key->val, _key->len);
}
else
{
return Variant((long) _index);
}
}
Variant value()
{
return Variant(_val);
}
Bucket *ptr()
{
return _ptr;
}
private:
zval *_val;
zend_string *_key;
Bucket *_ptr;
Bucket *pe;
zend_ulong _index;
};
class Array: public Variant
{
public:
Array() :
Variant()
{
array_init(&val);
}
Array(zval *v) :
Variant(v)
{
ref_val = v;
reference = true;
if (Z_TYPE_P(v) == IS_NULL)
{
array_init(v);
}
else if (Z_TYPE_P(v) != IS_ARRAY)
{
php_error_docref(NULL, E_ERROR, "cpp moudle array construct args must be zend array");
}
}
Array(Variant &v)
{
ref_val = v.ptr();
reference = true;
if (v.isNull())
{
array_init(ref_val);
}
else if (!v.isArray())
{
php_error_docref(NULL, E_ERROR, "cpp moudle array construct args must be zend array");
}
}
void append(Variant v)
{
v.addRef();
add_next_index_zval(ptr(), v.ptr());
}
void append(const char *str)
{
add_next_index_string(ptr(), str);
}
void append(string &str)
{
add_next_index_stringl(ptr(), str.c_str(), str.length());
}
void append(long v)
{
add_next_index_long(ptr(), v);
}
void append(int v)
{
add_next_index_long(ptr(), (long) v);
}
void append(bool v)
{
add_next_index_bool(ptr(), v ? 1 : 0);
}
void append(double v)
{
add_next_index_double(ptr(), (double) v);
}
void append(float v)
{
add_next_index_double(ptr(), (double) v);
}
void append(zval *v)
{
zval_add_ref(v);
add_next_index_zval(ptr(), v);
}
void append(void *v)
{
add_next_index_null(ptr());
}
void append(Array &v)
{
zend_array *arr = zend_array_dup(Z_ARR_P(v.ptr()));
zval array;
ZVAL_ARR(&array, arr);
add_next_index_zval(ptr(), &array);
}
//------------------assoc-array------------------
void set(const char *key, Variant &v)
{
add_assoc_zval(ptr(), key, v.ptr());
}
void set(const char *key, int v)
{
add_assoc_long(ptr(), key, (long) v);
}
void set(const char *key, long v)
{
add_assoc_long(ptr(), key, v);
}
void set(const char *key, const char *v)
{
add_assoc_string(ptr(), key, (char * )v);
}
void set(const char *key, string &v)
{
add_assoc_stringl(ptr(), key, (char* )v.c_str(), v.length());
}
void set(const char *key, double v)
{
add_assoc_double(ptr(), key, v);
}
void set(const char *key, float v)
{
add_assoc_double(ptr(), key, (double ) v);
}
void set(const char *key, bool v)
{
add_assoc_bool(ptr(), key, v ? 1 : 0);
}
void set(int i, Variant &v)
{
add_index_zval(ptr(), (zend_ulong) i, v.ptr());
}
//-------------------------------------------
Variant operator [](int i)
{
zval *ret = zend_hash_index_find(Z_ARRVAL_P(ptr()), (zend_ulong) i);
if (ret == NULL)
{
return Variant(nullptr);
}
return Variant(ret);
}
Variant operator [](const char *key)
{
zval *ret = zend_hash_str_find(Z_ARRVAL_P(ptr()), key, strlen(key));
if (ret == NULL)
{
return Variant(nullptr);
}
return Variant(ret);
}
bool remove(const char *key)
{
String _key(key);
bool ret = zend_hash_del(Z_ARRVAL_P(ptr()), _key.ptr()) == SUCCESS;
return ret;
}
void clean()
{
zend_hash_clean(Z_ARRVAL_P(ptr()));
}
bool exists(const char *key)
{
String _key(key);
bool ret = zend_hash_exists(Z_ARRVAL_P(ptr()), _key.ptr()) == SUCCESS;
return ret;
}
ArrayIterator begin()
{
return ArrayIterator(Z_ARRVAL_P(ptr())->arData, Z_ARRVAL_P(ptr())->arData + Z_ARRVAL_P(ptr())->nNumUsed);
}
ArrayIterator end()
{
return ArrayIterator(Z_ARRVAL_P(ptr())->arData + Z_ARRVAL_P(ptr())->nNumUsed);
}
size_t count()
{
return Z_ARRVAL_P(ptr())->nNumOfElements;
}
bool empty()
{
return Z_ARRVAL_P(ptr())->nNumOfElements == 0;
}
};
class Args
{
public:
Args()
{
argc = 0;
}
void append(zval *v)
{
assert(argc < MAX_ARGC);
argv[argc++] = v;
}
size_t count()
{
return argc;
}
bool empty()
{
return argc == 0;
}
Array toArray()
{
Array array;
for (int i = 0; i < argc; i++)
{
array.append(Variant(argv[i]));
}
array.addRef();
return array;
}
Variant operator [](int i)
{
if (i >= argc)
{
return Variant(nullptr);
}
return Variant(argv[i], true);
}
private:
int argc;
zval *argv[MAX_ARGC];
};
static inline Variant _call(zval *object, zval *func, Array &args)
{
Variant retval = false;
if (args.count() > MAX_ARGC)
{
return retval;
}
zval params[MAX_ARGC];
for (int i = 0; i < args.count(); i++)
{
ZVAL_COPY_VALUE(&params[i], args[i].ptr());
}
zval _retval;
if (call_user_function(EG(function_table), object, func, &_retval, args.count(), params) == 0)
{
retval = Variant(&_retval);
retval.addRef();
}
return retval;
}
static inline Variant _call(zval *object, zval *func)
{
Variant retval = false;
zval params[0];
zval _retval;
if (call_user_function(EG(function_table), object, func, &_retval, 0, params) == 0)
{
retval = Variant(&_retval);
}
return retval;
}
Variant call(Variant &func, Array &args)
{
return _call(NULL, func.ptr(), args);
}
Variant call(const char *func, Array &args)
{
Variant _func(func);
return _call(NULL, _func.ptr(), args);
}
/*generator*/
Variant exec(const char *func, Variant v1)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
args.append(v18.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18, Variant v19)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
args.append(v18.ptr());
args.append(v19.ptr());
return _call(NULL, _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18, Variant v19, Variant v20)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
args.append(v18.ptr());
args.append(v19.ptr());
args.append(v20.ptr());
return _call(NULL, _func.ptr(), args);
}/*generator*/
void var_dump(Variant &v)
{
php_var_dump(v.ptr(), VAR_DUMP_LEVEL);
}
static inline zend_class_entry *getClassEntry(const char *name)
{
String class_name(name, strlen(name));
return zend_lookup_class(class_name.ptr());
}
void throwException(const char *name, const char *message, int code = 0)
{
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' undefined.", name);
return;
}
zend_throw_exception(ce, message, code TSRMLS_CC);
}
Variant getGlobalVariant(const char *name)
{
zend_string *key = zend_string_init(name, strlen(name), 0);
zval *var = zend_hash_find_ind(&EG(symbol_table), key);
if (!var)
{
return false;
}
return Variant(var, true);
}
class Object: public Variant
{
public:
Object(Variant &v) :
Variant()
{
memcpy(&val, v.ptr(), sizeof(val));
zval_add_ref(&val);
}
Object(zval *v) :
Variant(v)
{
}
Object(zval *v, bool ref) :
Variant(v, ref)
{
}
Object() :
Variant()
{
}
Variant call(Variant &func, Array &args)
{
return _call(ptr(), func.ptr(), args);
}
Variant call(const char *func, Array &args)
{
Variant _func(func);
return _call(ptr(), _func.ptr(), args);
}
/**
* call php function with 0 params.
*/
Variant call(Variant &func)
{
return _call(ptr(), func.ptr());
}
Variant call(const char *func)
{
Variant _func(func);
return _call(ptr(), _func.ptr());
}
/*generator*/
Variant exec(const char *func, Variant v1)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
args.append(v18.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18, Variant v19)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
args.append(v18.ptr());
args.append(v19.ptr());
return _call(ptr(), _func.ptr(), args);
}
Variant exec(const char *func, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18, Variant v19, Variant v20)
{
Variant _func(func);
Array args;
args.append(v1.ptr());
args.append(v2.ptr());
args.append(v3.ptr());
args.append(v4.ptr());
args.append(v5.ptr());
args.append(v6.ptr());
args.append(v7.ptr());
args.append(v8.ptr());
args.append(v9.ptr());
args.append(v10.ptr());
args.append(v11.ptr());
args.append(v12.ptr());
args.append(v13.ptr());
args.append(v14.ptr());
args.append(v15.ptr());
args.append(v16.ptr());
args.append(v17.ptr());
args.append(v18.ptr());
args.append(v19.ptr());
args.append(v20.ptr());
return _call(ptr(), _func.ptr(), args);
}
/*generator*/
Variant get(const char *name)
{
Variant retval;
zval rv;
zval *member_p = zend_read_property(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), 0, &rv);
if (member_p != &rv)
{
ZVAL_COPY(retval.ptr(), member_p);
}
else
{
ZVAL_COPY_VALUE(retval.ptr(), member_p);
}
retval.addRef();
return retval;
}
void set(const char *name, Variant &v)
{
zend_update_property(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v.ptr());
}
void set(const char *name, Array &v)
{
v.addRef();
zend_update_property(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v.ptr());
}
void set(const char *name, string &v)
{
zend_update_property_stringl(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v.c_str(), v.length());
}
void set(const char *name, string v)
{
zend_update_property_stringl(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v.c_str(), v.length());
}
void set(const char *name, const char *v)
{
zend_update_property_string(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v);
}
void set(const char *name, long v)
{
zend_update_property_long(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v);
}
void set(const char *name, double v)
{
zend_update_property_double(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v);
}
void set(const char *name, float v)
{
zend_update_property_double(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), (double) v);
}
void set(const char *name, bool v)
{
zend_update_property_bool(Z_OBJCE_P(ptr()), ptr(), name, strlen(name), v ? 1 : 0);
}
string getClassName()
{
return string(Z_OBJCE_P(ptr())->name->val, Z_OBJCE_P(ptr())->name->len);
}
bool methodExists(const char *name)
{
return zend_hash_str_exists(&Z_OBJCE_P(ptr())->function_table, name, strlen(name));
}
bool propertyExists(const char *name)
{
return zend_hash_str_exists(&Z_OBJCE_P(ptr())->properties_info, name, strlen(name));
}
};
Object create(const char *name, Array &args)
{
zend_class_entry *ce = getClassEntry(name);
Object object;
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
object.call("__construct", args);
return object;
}
Object create(const char *name)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
return object;
}
#define function(f) #f, f
#define defineMethod(c, m) void c##_##m(Object &_this, Args &args, Variant &retval)
typedef void (*function_t)(Args &, Variant &retval);
typedef void (*resource_dtor)(zend_resource *);
typedef void (*method_t)(Object &, Args &, Variant &retval);
static unordered_map<string, function_t> function_map;
static unordered_map<string, unordered_map<string, method_t> > method_map;
static void _exec_function(zend_execute_data *data, zval *return_value)
{
const char *name = data->func->common.function_name->val;
function_t func = function_map[name];
Args args;
zval *param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
int arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
while (arg_count-- > 0)
{
args.append(param_ptr);
param_ptr++;
}
Variant _retval(return_value, true);
func(args, _retval);
}
static void _exec_method(zend_execute_data *data, zval *return_value)
{
const char *method_name = data->func->common.function_name->val;
const char *class_name = data->func->common.scope->name->val;
method_t func = method_map[class_name][method_name];
Args args;
Object _this(&data->This, true);
zval *param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
int arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
while (arg_count-- > 0)
{
args.append(param_ptr);
param_ptr++;
}
Variant _retval(return_value, true);
func(_this, args, _retval);
}
typedef struct _zend_internal_arg_info ArgInfo;
bool registerFunction(const char *name, function_t func)
{
zend_function_entry _functions[] = {
{name, _exec_function, NULL, 0, 0},
{NULL, NULL, NULL,}
};
if (zend_register_functions(NULL, _functions, NULL, MODULE_PERSISTENT) == SUCCESS)
{
function_map[name] = func;
return true;
}
else
{
return false;
}
}
bool registerResource(const char *name, resource_dtor dtor)
{
Resource *res = new Resource;
int type = zend_register_list_destructors_ex(dtor, NULL, name, 0);
if (type < 0)
{
return false;
}
res->type = type;
res->name = name;
resource_map[name] = res;
return true;
}
void unregisterFunction(string &name)
{
zend_function_entry _functions[] = {
{name.c_str(), _exec_function, NULL, 0, 0},
{NULL, NULL, NULL,}
};
zend_unregister_functions(_functions, 1, NULL);
}
void registerConstant(const char *name, long v)
{
zend_constant c;
ZVAL_LONG(&c.value, v);
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, int v)
{
zend_constant c;
ZVAL_LONG(&c.value, v);
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, bool v)
{
zend_constant c;
if (v)
{
ZVAL_TRUE(&c.value);
}
else
{
ZVAL_FALSE(&c.value);
}
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, double v)
{
zend_constant c;
ZVAL_DOUBLE(&c.value, v);
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, float v)
{
zend_constant c;
ZVAL_DOUBLE(&c.value, v);
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, const char *v)
{
zend_constant c;
ZVAL_STRING(&c.value, (char* )v);
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, string &v)
{
zend_constant c;
ZVAL_STRINGL(&c.value, (char * )v.c_str(), v.length());
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
void registerConstant(const char *name, Variant &v)
{
zend_constant c;
ZVAL_COPY(&c.value, v.ptr());
c.flags = CONST_CS;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = 0;
zend_register_constant(&c);
}
Variant constant(const char *name)
{
zend_string *_name = zend_string_init(name, strlen(name), 0);
zval *val = zend_get_constant_ex(_name, NULL, ZEND_FETCH_CLASS_SILENT);
zend_string_free(_name);
if (val == NULL)
{
return nullptr;
}
Variant retval(val);
return retval;
}
enum ClassFlags
{
STATIC = ZEND_ACC_STATIC,
ABSTRACT = ZEND_ACC_ABSTRACT,
FINAL = ZEND_ACC_FINAL,
INTERFACE = ZEND_ACC_INTERFACE,
TRAIT = ZEND_ACC_TRAIT,
PUBLIC = ZEND_ACC_PUBLIC,
PROTECTED = ZEND_ACC_PROTECTED,
PRIVATE = ZEND_ACC_PRIVATE,
CONSTRUCT = ZEND_ACC_CTOR,
DESTRUCT = ZEND_ACC_DTOR,
CLONE = ZEND_ACC_CLONE,
};
class Class
{
struct Method
{
string name;
int flags;
method_t method;
};
struct Property
{
string name;
zval value;
int flags;
};
struct Constant
{
string name;
zval value;
};
public:
Class(const char *name)
{
class_name = name;
INIT_CLASS_ENTRY_EX(_ce, name, strlen(name), NULL);
parent_ce = NULL;
ce = NULL;
activated = false;
}
bool extends(const char *_parent_class)
{
if (activated)
{
return false;
}
parent_class_name = _parent_class;
parent_ce = getClassEntry(_parent_class);
return parent_ce != NULL;
}
bool implements(const char *name)
{
if (activated)
{
return false;
}
if (interfaces.find(name) != interfaces.end())
{
return false;
}
zend_class_entry *interface_ce = getClassEntry(name);
if (interface_ce == NULL)
{
return false;
}
printf("name%s\n", name);
interfaces[name] = interface_ce;
return true;
}
bool addConstant(const char *name, Variant v)
{
if (activated)
{
return false;
}
Constant c;
c.name = name;
ZVAL_COPY(&c.value, v.ptr());
constants.push_back(c);
return true;
}
bool addProperty(const char *name, Variant v, int flags = PUBLIC)
{
if (activated)
{
return false;
}
Property p;
p.name = name;
ZVAL_COPY(&p.value, v.ptr());
p.flags = flags;
propertys.push_back(p);
return true;
}
bool addMethod(const char *name, method_t method, int flags = PUBLIC)
{
if (activated)
{
return false;
}
if ((flags & CONSTRUCT) || (flags & DESTRUCT) || !(flags & ZEND_ACC_PPP_MASK))
{
flags |= PUBLIC;
}
Method m;
m.flags = flags;
m.method = method;
m.name = name;
methods.push_back(m);
return false;
}
bool activate()
{
if (activated)
{
return false;
}
/**
* register methods
*/
int n = methods.size();
zend_function_entry *_methods = (zend_function_entry *) ecalloc(n + 1, sizeof(zend_function_entry));
for (int i = 0; i < n; i++)
{
_methods[i].fname = methods[i].name.c_str();
_methods[i].handler = _exec_method;
_methods[i].arg_info = NULL;
_methods[i].num_args = (uint32_t) (sizeof(void*) / sizeof(struct _zend_internal_arg_info) - 1);
_methods[i].flags = methods[i].flags;
method_map[class_name][methods[i].name] = methods[i].method;
}
memset(&_methods[n], 0, sizeof(zend_function_entry));
_ce.info.internal.builtin_functions = _methods;
if (parent_ce)
{
ce = zend_register_internal_class_ex(ce, parent_ce);
}
else
{
ce = zend_register_internal_class(&_ce TSRMLS_CC);
}
efree(_methods);
if (ce == NULL)
{
return false;
}
/**
* implements interface
*/
for (auto i = interfaces.begin(); i != interfaces.end(); i++)
{
zend_do_implement_interface(ce, interfaces[i->first]);
}
/**
* register property
*/
for (int i = 0; i != propertys.size(); i++)
{
Property p = propertys[i];
zval_add_ref(&p.value);
zend_declare_property(ce, p.name.c_str(), p.name.length(), &p.value, p.flags);
}
/**
* register constant
*/
for (int i = 0; i != constants.size(); i++)
{
if (Z_TYPE(constants[i].value) == IS_STRING)
{
zend_declare_class_constant_stringl(ce, constants[i].name.c_str(), constants[i].name.length(),
Z_STRVAL(constants[i].value), Z_STRLEN(constants[i].value));
}
else
{
zend_declare_class_constant(ce, constants[i].name.c_str(), constants[i].name.length(),
&constants[i].value);
}
}
activated = true;
return true;
}
bool deactivate()
{
if (!activated)
{
return false;
}
zend_string *lowercase_name = zend_string_alloc(class_name.length(), 1);
zend_str_tolower_copy(ZSTR_VAL(lowercase_name), class_name.c_str(), class_name.length());
lowercase_name = zend_new_interned_string(lowercase_name);
zend_hash_del(CG(class_table), lowercase_name);
zend_string_release(lowercase_name);
activated = false;
return true;
}
bool alias(const char *alias_name)
{
if (!activated)
{
php_error_docref(NULL, E_WARNING, "Please execute alias method after activate.");
return false;
}
if (zend_register_class_alias_ex(alias_name, strlen(alias_name), ce) < 0)
{
return false;
}
return true;
}
string getName()
{
return class_name;
}
Variant getStaticProperty(string p_name)
{
if (!activated)
{
return nullptr;
}
return Variant(zend_read_static_property(ce, p_name.c_str(), p_name.length(), 1));
}
bool setStaticProperty(string p_name, Variant value)
{
if (!activated)
{
return false;
}
value.addRef();
return zend_update_static_property(ce, p_name.c_str(), p_name.length(), value.ptr()) == SUCCESS;
}
static Variant get(const char *name, string p_name)
{
zend_class_entry *_tmp_ce = getClassEntry(name);
if (!_tmp_ce)
{
return nullptr;
}
return Variant(zend_read_static_property(_tmp_ce, p_name.c_str(), p_name.length(), 1));
}
static bool set(const char *name, string p_name, Variant value)
{
zend_class_entry *_tmp_ce = getClassEntry(name);
if (!_tmp_ce)
{
return false;
}
value.addRef();
return zend_update_static_property(_tmp_ce, p_name.c_str(), p_name.length(), value.ptr()) == SUCCESS;
}
protected:
bool activated;
string class_name;
string parent_class_name;
zend_class_entry *parent_ce;
zend_class_entry _ce;
zend_class_entry *ce;
unordered_map<string, zend_class_entry *> interfaces;
vector<Method> methods;
vector<Property> propertys;
vector<Constant> constants;
};
static unordered_map<string, Class*> classes;
void registerClass(Class *c)
{
/**
* 激活类
*/
c->activate();
classes[c->getName()] = c;
}
void destroy()
{
for (auto i = classes.begin(); i != classes.end(); i++)
{
Class *c = i->second;
c->deactivate();
//delete c;
}
for (auto i = function_map.begin(); i != function_map.end(); i++)
{
string name = i->first;
unregisterFunction(name);
}
}
template<typename T>
Variant newResource(const char *name, T *v)
{
Resource *_c = resource_map[name];
if (!_c)
{
return nullptr;
}
zend_resource *res = zend_register_resource(static_cast<void*>(v), _c->type);
return Variant(res);
}
/*generator*/
Object newObject(const char *name, Variant v1)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
v15.addRef();
args.append(v15.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
v15.addRef();
args.append(v15.ptr());
v16.addRef();
args.append(v16.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
v15.addRef();
args.append(v15.ptr());
v16.addRef();
args.append(v16.ptr());
v17.addRef();
args.append(v17.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
v15.addRef();
args.append(v15.ptr());
v16.addRef();
args.append(v16.ptr());
v17.addRef();
args.append(v17.ptr());
v18.addRef();
args.append(v18.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18, Variant v19)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
v15.addRef();
args.append(v15.ptr());
v16.addRef();
args.append(v16.ptr());
v17.addRef();
args.append(v17.ptr());
v18.addRef();
args.append(v18.ptr());
v19.addRef();
args.append(v19.ptr());
object.call("__construct", args);
return object;
}
Object newObject(const char *name, Variant v1, Variant v2, Variant v3, Variant v4, Variant v5, Variant v6, Variant v7, Variant v8, Variant v9, Variant v10, Variant v11, Variant v12, Variant v13, Variant v14, Variant v15, Variant v16, Variant v17, Variant v18, Variant v19, Variant v20)
{
Object object;
zend_class_entry *ce = getClassEntry(name);
if (ce == NULL)
{
php_error_docref(NULL, E_WARNING, "class '%s' is undefined.", name);
return object;
}
zval zobject;
if (object_init_ex(&zobject, ce) == FAILURE)
{
return object;
}
object = Object(&zobject);
Array args;
v1.addRef();
args.append(v1.ptr());
v2.addRef();
args.append(v2.ptr());
v3.addRef();
args.append(v3.ptr());
v4.addRef();
args.append(v4.ptr());
v5.addRef();
args.append(v5.ptr());
v6.addRef();
args.append(v6.ptr());
v7.addRef();
args.append(v7.ptr());
v8.addRef();
args.append(v8.ptr());
v9.addRef();
args.append(v9.ptr());
v10.addRef();
args.append(v10.ptr());
v11.addRef();
args.append(v11.ptr());
v12.addRef();
args.append(v12.ptr());
v13.addRef();
args.append(v13.ptr());
v14.addRef();
args.append(v14.ptr());
v15.addRef();
args.append(v15.ptr());
v16.addRef();
args.append(v16.ptr());
v17.addRef();
args.append(v17.ptr());
v18.addRef();
args.append(v18.ptr());
v19.addRef();
args.append(v19.ptr());
v20.addRef();
args.append(v20.ptr());
object.call("__construct", args);
return object;
}
/*generator*/
//namespace end
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zhangcunli/swoole.git
git@gitee.com:zhangcunli/swoole.git
zhangcunli
swoole
swoole-src
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385