Skip to content

Commit 059693f

Browse files
committed
separate
1 parent 9c88d88 commit 059693f

File tree

3 files changed

+290
-220
lines changed

3 files changed

+290
-220
lines changed

include/phpx.h

Lines changed: 13 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ Variant newResource(const char *name, T *v)
393393
return Variant(res);
394394
}
395395

396-
void var_dump(Variant &v)
396+
static inline void var_dump(Variant &v)
397397
{
398398
php_var_dump(v.ptr(), PHPX_VAR_DUMP_LEVEL);
399399
}
@@ -618,36 +618,7 @@ class ArrayIterator
618618
zend_ulong _index;
619619
};
620620

621-
static int array_data_compare(const void *a, const void *b)
622-
{
623-
Bucket *f;
624-
Bucket *s;
625-
zval result;
626-
zval *first;
627-
zval *second;
628-
629-
f = (Bucket *) a;
630-
s = (Bucket *) b;
631-
632-
first = &f->val;
633-
second = &s->val;
634-
635-
if (UNEXPECTED(Z_TYPE_P(first) == IS_INDIRECT))
636-
{
637-
first = Z_INDIRECT_P(first);
638-
}
639-
if (UNEXPECTED(Z_TYPE_P(second) == IS_INDIRECT))
640-
{
641-
second = Z_INDIRECT_P(second);
642-
}
643-
if (compare_function(&result, first, second) == FAILURE)
644-
{
645-
return 0;
646-
}
647-
648-
ZEND_ASSERT(Z_TYPE(result) == IS_LONG);
649-
return Z_LVAL(result);
650-
}
621+
extern int array_data_compare(const void *a, const void *b);
651622

652623
class Array: public Variant
653624
{
@@ -1648,195 +1619,17 @@ class Class
16481619
};
16491620

16501621
public:
1651-
Class(const char *name)
1652-
{
1653-
class_name = name;
1654-
INIT_CLASS_ENTRY_EX(_ce, name, strlen(name), NULL);
1655-
parent_ce = NULL;
1656-
ce = NULL;
1657-
activated = false;
1658-
}
1659-
bool extends(const char *_parent_class)
1660-
{
1661-
if (activated)
1662-
{
1663-
return false;
1664-
}
1665-
parent_class_name = _parent_class;
1666-
parent_ce = getClassEntry(_parent_class);
1667-
return parent_ce != NULL;
1668-
}
1669-
bool extends(Class *parent)
1670-
{
1671-
if (activated)
1672-
{
1673-
return false;
1674-
}
1675-
parent_class_name = parent->getName();
1676-
parent_ce = parent->ptr();
1677-
return parent_ce != NULL;
1678-
}
1679-
bool implements(const char *name)
1680-
{
1681-
if (activated)
1682-
{
1683-
return false;
1684-
}
1685-
if (interfaces.find(name) != interfaces.end())
1686-
{
1687-
return false;
1688-
}
1689-
zend_class_entry *interface_ce = getClassEntry(name);
1690-
if (interface_ce == NULL)
1691-
{
1692-
return false;
1693-
}
1694-
interfaces[name] = interface_ce;
1695-
return true;
1696-
}
1697-
bool implements(zend_class_entry *interface_ce)
1698-
{
1699-
if (activated)
1700-
{
1701-
return false;
1702-
}
1703-
interfaces[interface_ce->name->val] = interface_ce;
1704-
return true;
1705-
}
1706-
bool addConstant(const char *name, Variant v)
1707-
{
1708-
if (activated)
1709-
{
1710-
return false;
1711-
}
1712-
Constant c;
1713-
c.name = name;
1714-
ZVAL_COPY(&c.value, v.ptr());
1715-
constants.push_back(c);
1716-
return true;
1717-
}
1718-
bool addProperty(const char *name, Variant v, int flags = PUBLIC)
1719-
{
1720-
if (activated)
1721-
{
1722-
return false;
1723-
}
1724-
Property p;
1725-
p.name = name;
1726-
ZVAL_COPY(&p.value, v.ptr());
1727-
p.flags = flags;
1728-
propertys.push_back(p);
1729-
return true;
1730-
}
1731-
bool addMethod(const char *name, method_t method, int flags = PUBLIC, ArgInfo *info = nullptr)
1732-
{
1733-
if (activated)
1734-
{
1735-
return false;
1736-
}
1737-
if ((flags & CONSTRUCT) || (flags & DESTRUCT) || !(flags & ZEND_ACC_PPP_MASK))
1738-
{
1739-
flags |= PUBLIC;
1740-
}
1741-
Method m;
1742-
m.flags = flags;
1743-
m.method = method;
1744-
m.name = name;
1745-
m.info = info;
1746-
methods.push_back(m);
1747-
return false;
1748-
}
1749-
bool activate()
1750-
{
1751-
if (activated)
1752-
{
1753-
return false;
1754-
}
1755-
/**
1756-
* register methods
1757-
*/
1758-
int n = methods.size();
1759-
zend_function_entry *_methods = (zend_function_entry *) ecalloc(n + 1, sizeof(zend_function_entry));
1760-
for (int i = 0; i < n; i++)
1761-
{
1762-
_methods[i].fname = methods[i].name.c_str();
1763-
_methods[i].handler = _exec_method;
1764-
if (methods[i].info)
1765-
{
1766-
_methods[i].arg_info = methods[i].info->get();
1767-
_methods[i].num_args = methods[i].info->count();
1768-
}
1769-
else
1770-
{
1771-
_methods[i].arg_info = nullptr;
1772-
_methods[i].num_args = 0;
1773-
}
1774-
_methods[i].flags = methods[i].flags;
1775-
method_map[class_name.c_str()][methods[i].name.c_str()] = methods[i].method;
1776-
}
1777-
memset(&_methods[n], 0, sizeof(zend_function_entry));
1778-
_ce.info.internal.builtin_functions = _methods;
1779-
if (parent_ce)
1780-
{
1781-
ce = zend_register_internal_class_ex(&_ce, parent_ce);
1782-
}
1783-
else
1784-
{
1785-
ce = zend_register_internal_class(&_ce TSRMLS_CC);
1786-
}
1787-
efree(_methods);
1788-
if (ce == NULL)
1789-
{
1790-
return false;
1791-
}
1792-
/**
1793-
* implements interface
1794-
*/
1795-
for (auto i = interfaces.begin(); i != interfaces.end(); i++)
1796-
{
1797-
zend_do_implement_interface(ce, interfaces[i->first]);
1798-
}
1799-
/**
1800-
* register property
1801-
*/
1802-
for (int i = 0; i != propertys.size(); i++)
1803-
{
1804-
Property p = propertys[i];
1805-
zval_add_ref(&p.value);
1806-
zend_declare_property(ce, p.name.c_str(), p.name.length(), &p.value, p.flags);
1807-
}
1808-
/**
1809-
* register constant
1810-
*/
1811-
for (int i = 0; i != constants.size(); i++)
1812-
{
1813-
if (Z_TYPE(constants[i].value) == IS_STRING)
1814-
{
1815-
zend_declare_class_constant_stringl(ce, constants[i].name.c_str(), constants[i].name.length(),
1816-
Z_STRVAL(constants[i].value), Z_STRLEN(constants[i].value));
1817-
}
1818-
else
1819-
{
1820-
zend_declare_class_constant(ce, constants[i].name.c_str(), constants[i].name.length(),
1821-
&constants[i].value);
1822-
}
1823-
}
1824-
activated = true;
1825-
return true;
1826-
}
1827-
bool alias(const char *alias_name)
1828-
{
1829-
if (!activated)
1830-
{
1831-
php_error_docref(NULL, E_WARNING, "Please execute alias method after activate.");
1832-
return false;
1833-
}
1834-
if (zend_register_class_alias_ex(alias_name, strlen(alias_name), ce) < 0)
1835-
{
1836-
return false;
1837-
}
1838-
return true;
1839-
}
1622+
Class(const char *name);
1623+
bool extends(const char *_parent_class);
1624+
bool extends(Class *parent);
1625+
bool implements(const char *name);
1626+
bool implements(zend_class_entry *interface_ce);
1627+
bool addConstant(const char *name, Variant v);
1628+
bool addProperty(const char *name, Variant v, int flags = PUBLIC);
1629+
bool addMethod(const char *name, method_t method, int flags = PUBLIC, ArgInfo *info = nullptr);
1630+
bool activate();
1631+
bool alias(const char *alias_name);
1632+
18401633
string getName()
18411634
{
18421635
return class_name;

src/array.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Swoole |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 2.0 of the Apache license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.apache.org/licenses/LICENSE-2.0.html |
9+
| If you did not receive a copy of the Apache2.0 license and are unable|
10+
| to obtain it through the world-wide-web, please send a note to |
11+
| license@swoole.com so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: Tianfeng Han <mikan.tenny@gmail.com> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#include "phpx.h"
18+
19+
using namespace std;
20+
21+
namespace php
22+
{
23+
24+
int array_data_compare(const void *a, const void *b)
25+
{
26+
Bucket *f;
27+
Bucket *s;
28+
zval result;
29+
zval *first;
30+
zval *second;
31+
32+
f = (Bucket *) a;
33+
s = (Bucket *) b;
34+
35+
first = &f->val;
36+
second = &s->val;
37+
38+
if (UNEXPECTED(Z_TYPE_P(first) == IS_INDIRECT))
39+
{
40+
first = Z_INDIRECT_P(first);
41+
}
42+
if (UNEXPECTED(Z_TYPE_P(second) == IS_INDIRECT))
43+
{
44+
second = Z_INDIRECT_P(second);
45+
}
46+
if (compare_function(&result, first, second) == FAILURE)
47+
{
48+
return 0;
49+
}
50+
51+
ZEND_ASSERT(Z_TYPE(result) == IS_LONG);
52+
return Z_LVAL(result);
53+
}
54+
55+
}

0 commit comments

Comments
 (0)