forked from swoole/swoole-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swoole_module.c
66 lines (58 loc) · 2.38 KB
/
swoole_module.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
+----------------------------------------------------------------------+
| Swoole |
+----------------------------------------------------------------------+
| Copyright (c) 2012-2015 The Swoole Group |
+----------------------------------------------------------------------+
| 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> |
+----------------------------------------------------------------------+
*/
#include "php_swoole.h"
#include "module.h"
static zend_class_entry swoole_module_ce;
static zend_class_entry *swoole_module_class_entry_ptr;
void swoole_module_init(int module_number TSRMLS_DC)
{
SWOOLE_INIT_CLASS_ENTRY(swoole_module_ce, "swoole_module", "Swoole\\Module", NULL);
swoole_module_class_entry_ptr = zend_register_internal_class(&swoole_module_ce TSRMLS_CC);
SWOOLE_CLASS_ALIAS(swoole_module, "Swoole\\Module");
}
static zval *loaded_modules = NULL;
PHP_FUNCTION(swoole_load_module)
{
char *name;
zend_size_t len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE)
{
return;
}
if (loaded_modules == NULL)
{
SW_ALLOC_INIT_ZVAL(loaded_modules);
array_init(loaded_modules);
}
else
{
zval *value;
if (sw_zend_hash_find(Z_ARRVAL_P(loaded_modules), name, len + 1, (void **) &value) == SUCCESS)
{
RETURN_ZVAL(value, 1, 0);
}
}
swModule *module = swModule_load(name);
if (module == NULL)
{
RETURN_FALSE;
}
object_init_ex(return_value, swoole_module_class_entry_ptr);
swoole_set_object(return_value, module);
sw_zend_hash_update(Z_ARRVAL_P(loaded_modules), name, len + 1, return_value, sizeof(return_value), NULL);
}