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/fcall.h"
16 #include "kernel/object.h"
17 #include "kernel/memory.h"
18 #include "kernel/array.h"
19
20
21 /**
22 * This file is part of the Phalcon Framework.
23 *
24 * (c) Phalcon Team <team@phalcon.io>
25 *
26 * For the full copyright and license information, please view the LICENSE.txt
27 * file that was distributed with this source code.
28 */
29 /**
30 * Class Phalcon\Http\Link\LinkProvider
31 *
32 * @property LinkInterface[] links
33 */
ZEPHIR_INIT_CLASS(Phalcon_Html_Link_EvolvableLinkProvider)34 ZEPHIR_INIT_CLASS(Phalcon_Html_Link_EvolvableLinkProvider) {
35
36 ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Html\\Link, EvolvableLinkProvider, phalcon, html_link_evolvablelinkprovider, phalcon_html_link_linkprovider_ce, phalcon_html_link_evolvablelinkprovider_method_entry, 0);
37
38 zend_class_implements(phalcon_html_link_evolvablelinkprovider_ce, 1, zephir_get_internal_ce(SL("psr\\link\\evolvablelinkproviderinterface")));
39 return SUCCESS;
40
41 }
42
43 /**
44 * Returns an instance with the specified link included.
45 *
46 * If the specified link is already present, this method MUST return
47 * normally without errors. The link is present if link is === identical
48 * to a link object already in the collection.
49 *
50 * @param LinkInterface link
51 * A link object that should be included in this collection.
52 *
53 * @return static
54 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLinkProvider,withLink)55 PHP_METHOD(Phalcon_Html_Link_EvolvableLinkProvider, withLink) {
56
57 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
58 zend_long ZEPHIR_LAST_CALL_STATUS;
59 zval *link, link_sub, key, newInstance;
60 zval *this_ptr = getThis();
61
62 ZVAL_UNDEF(&link_sub);
63 ZVAL_UNDEF(&key);
64 ZVAL_UNDEF(&newInstance);
65
66 ZEPHIR_MM_GROW();
67 zephir_fetch_params(1, 1, 0, &link);
68
69
70
71 ZEPHIR_CALL_METHOD(&key, this_ptr, "getkey", NULL, 0, link);
72 zephir_check_call_status();
73 ZEPHIR_INIT_VAR(&newInstance);
74 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
75 RETURN_MM();
76 }
77 zephir_update_property_array(&newInstance, SL("links"), &key, link);
78 RETURN_CCTOR(&newInstance);
79
80 }
81
82 /**
83 * Returns an instance with the specified link removed.
84 *
85 * If the specified link is not present, this method MUST return normally
86 * without errors. The link is present if link is === identical to a link
87 * object already in the collection.
88 *
89 * @param LinkInterface link
90 * The link to remove.
91 *
92 * @return static
93 */
PHP_METHOD(Phalcon_Html_Link_EvolvableLinkProvider,withoutLink)94 PHP_METHOD(Phalcon_Html_Link_EvolvableLinkProvider, withoutLink) {
95
96 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
97 zend_long ZEPHIR_LAST_CALL_STATUS;
98 zval *link, link_sub, key, links, newInstance, _0;
99 zval *this_ptr = getThis();
100
101 ZVAL_UNDEF(&link_sub);
102 ZVAL_UNDEF(&key);
103 ZVAL_UNDEF(&links);
104 ZVAL_UNDEF(&newInstance);
105 ZVAL_UNDEF(&_0);
106
107 ZEPHIR_MM_GROW();
108 zephir_fetch_params(1, 1, 0, &link);
109
110
111
112 ZEPHIR_CALL_METHOD(&key, this_ptr, "getkey", NULL, 0, link);
113 zephir_check_call_status();
114 ZEPHIR_INIT_VAR(&newInstance);
115 if (zephir_clone(&newInstance, this_ptr) == FAILURE) {
116 RETURN_MM();
117 }
118 zephir_read_property(&_0, this_ptr, ZEND_STRL("links"), PH_NOISY_CC | PH_READONLY);
119 ZEPHIR_CPY_WRT(&links, &_0);
120 zephir_array_unset(&links, &key, PH_SEPARATE);
121 zephir_update_property_zval(&newInstance, ZEND_STRL("links"), &links);
122 RETURN_CCTOR(&newInstance);
123
124 }
125
126