1
2 #ifdef HAVE_CONFIG_H
3 #include "../../../ext_config.h"
4 #endif
5
6 #include <php.h>
7 #include "../../../php_ext.h"
8 #include "../../../ext.h"
9
10 #include <Zend/zend_operators.h>
11 #include <Zend/zend_exceptions.h>
12 #include <Zend/zend_interfaces.h>
13
14 #include "kernel/main.h"
15 #include "kernel/array.h"
16 #include "kernel/object.h"
17 #include "kernel/memory.h"
18 #include "kernel/string.h"
19 #include "ext/spl/spl_exceptions.h"
20 #include "kernel/exception.h"
21 #include "kernel/operators.h"
22
23
24 /**
25 * Phalcon\Annotations\Adapter\Memory
26 *
27 * Stores the parsed annotations in memory. This adapter is the suitable development/testing
28 */
ZEPHIR_INIT_CLASS(Phalcon_Annotations_Adapter_Memory)29 ZEPHIR_INIT_CLASS(Phalcon_Annotations_Adapter_Memory) {
30
31 ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Memory, phalcon, annotations_adapter_memory, phalcon_annotations_adapter_ce, phalcon_annotations_adapter_memory_method_entry, 0);
32
33 /**
34 * Data
35 * @var mixed
36 */
37 zend_declare_property_null(phalcon_annotations_adapter_memory_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC);
38
39 return SUCCESS;
40
41 }
42
43 /**
44 * Reads parsed annotations from memory
45 */
PHP_METHOD(Phalcon_Annotations_Adapter_Memory,read)46 PHP_METHOD(Phalcon_Annotations_Adapter_Memory, read) {
47
48 zval *key_param = NULL, *data = NULL, *_0, *_1;
49 zval *key = NULL;
50
51 ZEPHIR_MM_GROW();
52 zephir_fetch_params(1, 1, 0, &key_param);
53
54 if (UNEXPECTED(Z_TYPE_P(key_param) != IS_STRING && Z_TYPE_P(key_param) != IS_NULL)) {
55 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'key' must be a string") TSRMLS_CC);
56 RETURN_MM_NULL();
57 }
58 if (EXPECTED(Z_TYPE_P(key_param) == IS_STRING)) {
59 zephir_get_strval(key, key_param);
60 } else {
61 ZEPHIR_INIT_VAR(key);
62 ZVAL_EMPTY_STRING(key);
63 }
64
65
66 _0 = zephir_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY_CC);
67 ZEPHIR_INIT_VAR(_1);
68 zephir_fast_strtolower(_1, key);
69 if (zephir_array_isset_fetch(&data, _0, _1, 1 TSRMLS_CC)) {
70 RETURN_CTOR(data);
71 }
72 RETURN_MM_BOOL(0);
73
74 }
75
76 /**
77 * Writes parsed annotations to memory
78 */
PHP_METHOD(Phalcon_Annotations_Adapter_Memory,write)79 PHP_METHOD(Phalcon_Annotations_Adapter_Memory, write) {
80
81 zval *key_param = NULL, *data, *lowercasedKey = NULL;
82 zval *key = NULL;
83
84 ZEPHIR_MM_GROW();
85 zephir_fetch_params(1, 2, 0, &key_param, &data);
86
87 if (UNEXPECTED(Z_TYPE_P(key_param) != IS_STRING && Z_TYPE_P(key_param) != IS_NULL)) {
88 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'key' must be a string") TSRMLS_CC);
89 RETURN_MM_NULL();
90 }
91 if (EXPECTED(Z_TYPE_P(key_param) == IS_STRING)) {
92 zephir_get_strval(key, key_param);
93 } else {
94 ZEPHIR_INIT_VAR(key);
95 ZVAL_EMPTY_STRING(key);
96 }
97
98
99 ZEPHIR_INIT_VAR(lowercasedKey);
100 zephir_fast_strtolower(lowercasedKey, key);
101 zephir_update_property_array(this_ptr, SL("_data"), lowercasedKey, data TSRMLS_CC);
102 ZEPHIR_MM_RESTORE();
103
104 }
105
106