Skip to content

Commit

Permalink
separate
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jun 9, 2017
1 parent 8f01d0f commit 56c0f95
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 128 deletions.
141 changes: 13 additions & 128 deletions include/phpx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ class Interface
methods.push_back(m);
return false;
}
string getName()
inline string getName()
{
return name;
}
Expand Down Expand Up @@ -1634,7 +1634,7 @@ class Extension

Extension(const char*name, const char *version);

void checkStartupStatus(enum StartupStatus status, const char *func)
void inline checkStartupStatus(enum StartupStatus status, const char *func)
{
if (status == AFTER_START && !this->started)
{
Expand All @@ -1646,133 +1646,18 @@ class Extension
}
}

bool registerClass(Class *c)
{
this->checkStartupStatus(AFTER_START, __func__);
c->activate();
class_map[c->getName()] = c;
return true;
}

bool registerInterface(Interface *i)
{
this->checkStartupStatus(AFTER_START, __func__);
i->activate();
interface_map[i->getName()] = i;
return true;
}

bool registerClass(Class *c);
bool registerInterface(Interface *i);
bool registerFunction(const char *name, function_t func, ArgInfo *info = nullptr);

bool registerResource(const char *name, resource_dtor dtor)
{
this->checkStartupStatus(AFTER_START, __func__);
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;
}

bool registerConstant(const char *name, long v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_LONG(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, int v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_LONG(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, bool v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
if (v)
{
ZVAL_TRUE(&c.value);
}
else
{
ZVAL_FALSE(&c.value);
}
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, double v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_DOUBLE(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, float v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_DOUBLE(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, const char *v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_STRING(&c.value, (char* )v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, string &v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_STRINGL(&c.value, (char * )v.c_str(), v.length());
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool registerConstant(const char *name, Variant &v)
{
this->checkStartupStatus(AFTER_START, __func__);
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 = module.module_number;
return zend_register_constant(&c);
}
bool registerResource(const char *name, resource_dtor dtor);
bool registerConstant(const char *name, long v);
bool registerConstant(const char *name, int v);
bool registerConstant(const char *name, bool v);
bool registerConstant(const char *name, double v);
bool registerConstant(const char *name, float v);
bool registerConstant(const char *name, const char *v);
bool registerConstant(const char *name, string &v);
bool registerConstant(const char *name, Variant &v);

bool require(const char *name, const char *version = nullptr);

Expand Down
126 changes: 126 additions & 0 deletions src/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,132 @@ bool Extension::require(const char *name, const char *version)
return true;
}

bool Extension::registerClass(Class *c)
{
this->checkStartupStatus(AFTER_START, __func__);
c->activate();
class_map[c->getName()] = c;
return true;
}

bool Extension::registerInterface(Interface *i)
{
this->checkStartupStatus(AFTER_START, __func__);
i->activate();
interface_map[i->getName()] = i;
return true;
}

bool Extension::registerResource(const char *name, resource_dtor dtor)
{
this->checkStartupStatus(AFTER_START, __func__);
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;
}

bool Extension::registerConstant(const char *name, long v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_LONG(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, int v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_LONG(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, bool v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
if (v)
{
ZVAL_TRUE(&c.value);
}
else
{
ZVAL_FALSE(&c.value);
}
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, double v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_DOUBLE(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, float v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_DOUBLE(&c.value, v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, const char *v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_STRING(&c.value, (char* )v);
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, string &v)
{
this->checkStartupStatus(AFTER_START, __func__);
zend_constant c;
ZVAL_STRINGL(&c.value, (char * )v.c_str(), v.length());
c.flags = CONST_CS | CONST_PERSISTENT;
c.name = zend_string_init(name, strlen(name), c.flags);
c.module_number = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerConstant(const char *name, Variant &v)
{
this->checkStartupStatus(AFTER_START, __func__);
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 = module.module_number;
return zend_register_constant(&c);
}

bool Extension::registerFunction(const char *name, function_t func, ArgInfo *info)
{
this->checkStartupStatus(BEFORE_START, __func__);
Expand Down

0 comments on commit 56c0f95

Please sign in to comment.