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/object.h"
16 #include "kernel/memory.h"
17 #include "kernel/fcall.h"
18
19
20 /**
21 * This file is part of the Phalcon Framework.
22 *
23 * (c) Phalcon Team <team@phalcon.io>
24 *
25 * For the full copyright and license information, please view the LICENSE.txt
26 * file that was distributed with this source code.
27 */
28 /**
29 * Class Phalcon\Http\Link\EvolvableLink
30 *
31 * @property array attributes
32 * @property string href
33 * @property array rels
34 * @property bool templated
35 */
ZEPHIR_INIT_CLASS(Phalcon_Html_Link_EvolvableLink)36 ZEPHIR_INIT_CLASS(Phalcon_Html_Link_EvolvableLink) {
37
38 ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Html\\Link, EvolvableLink, phalcon, html_link_evolvablelink, phalcon_html_link_link_ce, phalcon_html_link_evolvablelink_method_entry, 0);
39
40 zend_class_implements(phalcon_html_link_evolvablelink_ce, 1, zephir_get_internal_ce(SL("psr\\link\\evolvablelinkinterface")));
41 return SUCCESS;
42
43 }
44
45 /**
46 * Returns an instance with the specified attribute added.
47 *
48 * If the specified attribute is already present, it will be overwritten
49 * with the new value.
50 *
51 * @param string attribute The attribute to include.
52 * @param string value The value of the attribute to set.
53 *
54 * @return static
55 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLink,withAttribute)56 PHP_METHOD(Phalcon_Html_Link_EvolvableLink, withAttribute) {
57
58 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
59 zend_long ZEPHIR_LAST_CALL_STATUS;
60 zval *attribute, attribute_sub, *value, value_sub, newInstance, _0;
61 zval *this_ptr = getThis();
62
63 ZVAL_UNDEF(&attribute_sub);
64 ZVAL_UNDEF(&value_sub);
65 ZVAL_UNDEF(&newInstance);
66 ZVAL_UNDEF(&_0);
67
68 ZEPHIR_MM_GROW();
69 zephir_fetch_params(1, 2, 0, &attribute, &value);
70
71
72
73 ZEPHIR_INIT_VAR(&newInstance);
74 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
75 RETURN_MM();
76 }
77 zephir_read_property(&_0, &newInstance, ZEND_STRL("attributes"), PH_NOISY_CC | PH_READONLY);
78 ZEPHIR_CALL_METHOD(NULL, &_0, "set", NULL, 0, attribute, value);
79 zephir_check_call_status();
80 RETURN_CCTOR(&newInstance);
81
82 }
83
84 /**
85 * Returns an instance with the specified href.
86 *
87 * @param string href
88 * The href value to include. It must be one of:
89 * - An absolute URI, as defined by RFC 5988.
90 * - A relative URI, as defined by RFC 5988. The base of the relative
91 * link is assumed to be known based on context by the client.
92 * - A URI template as defined by RFC 6570.
93 * - An object implementing __toString() that produces one of the
94 * above values.
95 *
96 * An implementing library SHOULD evaluate a passed object to a string
97 * immediately rather than waiting for it to be returned later.
98 *
99 * @return static
100 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLink,withHref)101 PHP_METHOD(Phalcon_Html_Link_EvolvableLink, withHref) {
102
103 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
104 zend_long ZEPHIR_LAST_CALL_STATUS;
105 zval *href, href_sub, newInstance, _0;
106 zval *this_ptr = getThis();
107
108 ZVAL_UNDEF(&href_sub);
109 ZVAL_UNDEF(&newInstance);
110 ZVAL_UNDEF(&_0);
111
112 ZEPHIR_MM_GROW();
113 zephir_fetch_params(1, 1, 0, &href);
114
115
116
117 ZEPHIR_INIT_VAR(&newInstance);
118 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
119 RETURN_MM();
120 }
121 zephir_update_property_zval(&newInstance, ZEND_STRL("href"), href);
122 ZEPHIR_CALL_METHOD(&_0, this_ptr, "hrefistemplated", NULL, 0, href);
123 zephir_check_call_status();
124 zephir_update_property_zval(&newInstance, ZEND_STRL("templated"), &_0);
125 RETURN_CCTOR(&newInstance);
126
127 }
128
129 /**
130 * Returns an instance with the specified relationship included.
131 *
132 * If the specified rel is already present, this method MUST return
133 * normally without errors, but without adding the rel a second time.
134 *
135 * @param string rel
136 * The relationship value to add.
137 *
138 * @return static
139 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLink,withRel)140 PHP_METHOD(Phalcon_Html_Link_EvolvableLink, withRel) {
141
142 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
143 zend_long ZEPHIR_LAST_CALL_STATUS;
144 zval *rel, rel_sub, newInstance, _0, _1;
145 zval *this_ptr = getThis();
146
147 ZVAL_UNDEF(&rel_sub);
148 ZVAL_UNDEF(&newInstance);
149 ZVAL_UNDEF(&_0);
150 ZVAL_UNDEF(&_1);
151
152 ZEPHIR_MM_GROW();
153 zephir_fetch_params(1, 1, 0, &rel);
154
155
156
157 ZEPHIR_INIT_VAR(&newInstance);
158 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
159 RETURN_MM();
160 }
161 zephir_read_property(&_0, &newInstance, ZEND_STRL("rels"), PH_NOISY_CC | PH_READONLY);
162 ZVAL_BOOL(&_1, 1);
163 ZEPHIR_CALL_METHOD(NULL, &_0, "set", NULL, 0, rel, &_1);
164 zephir_check_call_status();
165 RETURN_CCTOR(&newInstance);
166
167 }
168
169 /**
170 * Returns an instance with the specified attribute excluded.
171 *
172 * If the specified attribute is not present, this method MUST return
173 * normally without errors.
174 *
175 * @param string attribute
176 * The attribute to remove.
177 *
178 * @return static
179 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLink,withoutAttribute)180 PHP_METHOD(Phalcon_Html_Link_EvolvableLink, withoutAttribute) {
181
182 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
183 zend_long ZEPHIR_LAST_CALL_STATUS;
184 zval *attribute, attribute_sub, newInstance, _0;
185 zval *this_ptr = getThis();
186
187 ZVAL_UNDEF(&attribute_sub);
188 ZVAL_UNDEF(&newInstance);
189 ZVAL_UNDEF(&_0);
190
191 ZEPHIR_MM_GROW();
192 zephir_fetch_params(1, 1, 0, &attribute);
193
194
195
196 ZEPHIR_INIT_VAR(&newInstance);
197 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
198 RETURN_MM();
199 }
200 zephir_read_property(&_0, &newInstance, ZEND_STRL("attributes"), PH_NOISY_CC | PH_READONLY);
201 ZEPHIR_CALL_METHOD(NULL, &_0, "remove", NULL, 0, attribute);
202 zephir_check_call_status();
203 RETURN_CCTOR(&newInstance);
204
205 }
206
207 /**
208 * Returns an instance with the specified relationship excluded.
209 *
210 * If the specified rel is already not present, this method MUST return
211 * normally without errors.
212 *
213 * @param string rel
214 * The relationship value to exclude.
215 *
216 * @return static
217 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLink,withoutRel)218 PHP_METHOD(Phalcon_Html_Link_EvolvableLink, withoutRel) {
219
220 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
221 zend_long ZEPHIR_LAST_CALL_STATUS;
222 zval *rel, rel_sub, newInstance, _0;
223 zval *this_ptr = getThis();
224
225 ZVAL_UNDEF(&rel_sub);
226 ZVAL_UNDEF(&newInstance);
227 ZVAL_UNDEF(&_0);
228
229 ZEPHIR_MM_GROW();
230 zephir_fetch_params(1, 1, 0, &rel);
231
232
233
234 ZEPHIR_INIT_VAR(&newInstance);
235 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
236 RETURN_MM();
237 }
238 zephir_read_property(&_0, &newInstance, ZEND_STRL("rels"), PH_NOISY_CC | PH_READONLY);
239 ZEPHIR_CALL_METHOD(NULL, &_0, "remove", NULL, 0, rel);
240 zephir_check_call_status();
241 RETURN_CCTOR(&newInstance);
242
243 }
244
245