PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/phalcon/annotations/annotation.zep.c

http://github.com/phalcon/cphalcon
C | 498 lines | 375 code | 67 blank | 56 comment | 49 complexity | 2a5e01e525c1e906269fbe95be6b47cd MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifdef HAVE_CONFIG_H
  2. #include "../../ext_config.h"
  3. #endif
  4. #include <php.h>
  5. #include "../../php_ext.h"
  6. #include "../../ext.h"
  7. #include <Zend/zend_operators.h>
  8. #include <Zend/zend_exceptions.h>
  9. #include <Zend/zend_interfaces.h>
  10. #include "kernel/main.h"
  11. #include "kernel/array.h"
  12. #include "kernel/memory.h"
  13. #include "kernel/object.h"
  14. #include "kernel/fcall.h"
  15. #include "ext/spl/spl_exceptions.h"
  16. #include "kernel/exception.h"
  17. #include "kernel/operators.h"
  18. #include "kernel/concat.h"
  19. /**
  20. * This file is part of the Phalcon Framework.
  21. *
  22. * (c) Phalcon Team <team@phalcon.io>
  23. *
  24. * For the full copyright and license information, please view the
  25. * LICENSE.txt file that was distributed with this source code.
  26. */
  27. /**
  28. * Represents a single annotation in an annotations collection
  29. */
  30. ZEPHIR_INIT_CLASS(Phalcon_Annotations_Annotation)
  31. {
  32. ZEPHIR_REGISTER_CLASS(Phalcon\\Annotations, Annotation, phalcon, annotations_annotation, phalcon_annotations_annotation_method_entry, 0);
  33. /**
  34. * Annotation Arguments
  35. *
  36. * @var array
  37. */
  38. zend_declare_property_null(phalcon_annotations_annotation_ce, SL("arguments"), ZEND_ACC_PROTECTED);
  39. /**
  40. * Annotation ExprArguments
  41. *
  42. * @var array
  43. */
  44. zend_declare_property_null(phalcon_annotations_annotation_ce, SL("exprArguments"), ZEND_ACC_PROTECTED);
  45. /**
  46. * Annotation Name
  47. *
  48. * @var string|null
  49. */
  50. zend_declare_property_null(phalcon_annotations_annotation_ce, SL("name"), ZEND_ACC_PROTECTED);
  51. phalcon_annotations_annotation_ce->create_object = zephir_init_properties_Phalcon_Annotations_Annotation;
  52. return SUCCESS;
  53. }
  54. /**
  55. * Phalcon\Annotations\Annotation constructor
  56. */
  57. PHP_METHOD(Phalcon_Annotations_Annotation, __construct)
  58. {
  59. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  60. zephir_fcall_cache_entry *_4 = NULL;
  61. zend_long ZEPHIR_LAST_CALL_STATUS;
  62. zval *reflectionData_param = NULL, name, exprArguments, argument, resolvedArgument, _0$$3, *_1$$4, _2$$4, _3$$5, _5$$8;
  63. zval reflectionData, arguments;
  64. zval *this_ptr = getThis();
  65. ZVAL_UNDEF(&reflectionData);
  66. ZVAL_UNDEF(&arguments);
  67. ZVAL_UNDEF(&name);
  68. ZVAL_UNDEF(&exprArguments);
  69. ZVAL_UNDEF(&argument);
  70. ZVAL_UNDEF(&resolvedArgument);
  71. ZVAL_UNDEF(&_0$$3);
  72. ZVAL_UNDEF(&_2$$4);
  73. ZVAL_UNDEF(&_3$$5);
  74. ZVAL_UNDEF(&_5$$8);
  75. #if PHP_VERSION_ID >= 80000
  76. bool is_null_true = 1;
  77. ZEND_PARSE_PARAMETERS_START(1, 1)
  78. Z_PARAM_ARRAY(reflectionData)
  79. ZEND_PARSE_PARAMETERS_END();
  80. #endif
  81. ZEPHIR_MM_GROW();
  82. zephir_fetch_params(1, 1, 0, &reflectionData_param);
  83. ZEPHIR_OBS_COPY_OR_DUP(&reflectionData, reflectionData_param);
  84. ZEPHIR_OBS_VAR(&name);
  85. if (zephir_array_isset_string_fetch(&name, &reflectionData, SL("name"), 0)) {
  86. zephir_array_fetch_string(&_0$$3, &reflectionData, SL("name"), PH_NOISY | PH_READONLY, "phalcon/Annotations/Annotation.zep", 48);
  87. zephir_update_property_zval(this_ptr, ZEND_STRL("name"), &_0$$3);
  88. }
  89. ZEPHIR_OBS_VAR(&exprArguments);
  90. if (zephir_array_isset_string_fetch(&exprArguments, &reflectionData, SL("arguments"), 0)) {
  91. ZEPHIR_INIT_VAR(&arguments);
  92. array_init(&arguments);
  93. zephir_is_iterable(&exprArguments, 0, "phalcon/Annotations/Annotation.zep", 69);
  94. if (Z_TYPE_P(&exprArguments) == IS_ARRAY) {
  95. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&exprArguments), _1$$4)
  96. {
  97. ZEPHIR_INIT_NVAR(&argument);
  98. ZVAL_COPY(&argument, _1$$4);
  99. zephir_array_fetch_string(&_3$$5, &argument, SL("expr"), PH_NOISY | PH_READONLY, "phalcon/Annotations/Annotation.zep", 60);
  100. ZEPHIR_CALL_METHOD(&resolvedArgument, this_ptr, "getexpression", &_4, 0, &_3$$5);
  101. zephir_check_call_status();
  102. ZEPHIR_OBS_NVAR(&name);
  103. if (zephir_array_isset_string_fetch(&name, &argument, SL("name"), 0)) {
  104. zephir_array_update_zval(&arguments, &name, &resolvedArgument, PH_COPY | PH_SEPARATE);
  105. } else {
  106. zephir_array_append(&arguments, &resolvedArgument, PH_SEPARATE, "phalcon/Annotations/Annotation.zep", 65);
  107. }
  108. } ZEND_HASH_FOREACH_END();
  109. } else {
  110. ZEPHIR_CALL_METHOD(NULL, &exprArguments, "rewind", NULL, 0);
  111. zephir_check_call_status();
  112. while (1) {
  113. ZEPHIR_CALL_METHOD(&_2$$4, &exprArguments, "valid", NULL, 0);
  114. zephir_check_call_status();
  115. if (!zend_is_true(&_2$$4)) {
  116. break;
  117. }
  118. ZEPHIR_CALL_METHOD(&argument, &exprArguments, "current", NULL, 0);
  119. zephir_check_call_status();
  120. zephir_array_fetch_string(&_5$$8, &argument, SL("expr"), PH_NOISY | PH_READONLY, "phalcon/Annotations/Annotation.zep", 60);
  121. ZEPHIR_CALL_METHOD(&resolvedArgument, this_ptr, "getexpression", &_4, 0, &_5$$8);
  122. zephir_check_call_status();
  123. ZEPHIR_OBS_NVAR(&name);
  124. if (zephir_array_isset_string_fetch(&name, &argument, SL("name"), 0)) {
  125. zephir_array_update_zval(&arguments, &name, &resolvedArgument, PH_COPY | PH_SEPARATE);
  126. } else {
  127. zephir_array_append(&arguments, &resolvedArgument, PH_SEPARATE, "phalcon/Annotations/Annotation.zep", 65);
  128. }
  129. ZEPHIR_CALL_METHOD(NULL, &exprArguments, "next", NULL, 0);
  130. zephir_check_call_status();
  131. }
  132. }
  133. ZEPHIR_INIT_NVAR(&argument);
  134. zephir_update_property_zval(this_ptr, ZEND_STRL("arguments"), &arguments);
  135. zephir_update_property_zval(this_ptr, ZEND_STRL("exprArguments"), &exprArguments);
  136. }
  137. ZEPHIR_MM_RESTORE();
  138. }
  139. /**
  140. * Returns an argument in a specific position
  141. */
  142. PHP_METHOD(Phalcon_Annotations_Annotation, getArgument)
  143. {
  144. zval *position, position_sub, argument, _0;
  145. zval *this_ptr = getThis();
  146. ZVAL_UNDEF(&position_sub);
  147. ZVAL_UNDEF(&argument);
  148. ZVAL_UNDEF(&_0);
  149. #if PHP_VERSION_ID >= 80000
  150. bool is_null_true = 1;
  151. ZEND_PARSE_PARAMETERS_START(1, 1)
  152. Z_PARAM_ZVAL(position)
  153. ZEND_PARSE_PARAMETERS_END();
  154. #endif
  155. zephir_fetch_params_without_memory_grow(1, 0, &position);
  156. zephir_read_property(&_0, this_ptr, ZEND_STRL("arguments"), PH_NOISY_CC | PH_READONLY);
  157. if (zephir_array_isset_fetch(&argument, &_0, position, 1)) {
  158. RETURN_CTORW(&argument);
  159. }
  160. RETURN_NULL();
  161. }
  162. /**
  163. * Returns the expression arguments
  164. */
  165. PHP_METHOD(Phalcon_Annotations_Annotation, getArguments)
  166. {
  167. zval *this_ptr = getThis();
  168. RETURN_MEMBER(getThis(), "arguments");
  169. }
  170. /**
  171. * Returns the expression arguments without resolving
  172. */
  173. PHP_METHOD(Phalcon_Annotations_Annotation, getExprArguments)
  174. {
  175. zval *this_ptr = getThis();
  176. RETURN_MEMBER(getThis(), "exprArguments");
  177. }
  178. /**
  179. * Resolves an annotation expression
  180. */
  181. PHP_METHOD(Phalcon_Annotations_Annotation, getExpression)
  182. {
  183. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  184. zephir_fcall_cache_entry *_4 = NULL;
  185. zend_long ZEPHIR_LAST_CALL_STATUS;
  186. zval *expr_param = NULL, value, item, resolvedItem, arrayValue, name, type, _0$$7, *_1$$7, _2$$7, _3$$8, _5$$11, _6$$15, _7$$15;
  187. zval expr;
  188. zval *this_ptr = getThis();
  189. ZVAL_UNDEF(&expr);
  190. ZVAL_UNDEF(&value);
  191. ZVAL_UNDEF(&item);
  192. ZVAL_UNDEF(&resolvedItem);
  193. ZVAL_UNDEF(&arrayValue);
  194. ZVAL_UNDEF(&name);
  195. ZVAL_UNDEF(&type);
  196. ZVAL_UNDEF(&_0$$7);
  197. ZVAL_UNDEF(&_2$$7);
  198. ZVAL_UNDEF(&_3$$8);
  199. ZVAL_UNDEF(&_5$$11);
  200. ZVAL_UNDEF(&_6$$15);
  201. ZVAL_UNDEF(&_7$$15);
  202. #if PHP_VERSION_ID >= 80000
  203. bool is_null_true = 1;
  204. ZEND_PARSE_PARAMETERS_START(1, 1)
  205. Z_PARAM_ARRAY(expr)
  206. ZEND_PARSE_PARAMETERS_END();
  207. #endif
  208. ZEPHIR_MM_GROW();
  209. zephir_fetch_params(1, 1, 0, &expr_param);
  210. ZEPHIR_OBS_COPY_OR_DUP(&expr, expr_param);
  211. ZEPHIR_OBS_VAR(&type);
  212. zephir_array_fetch_string(&type, &expr, SL("type"), PH_NOISY, "phalcon/Annotations/Annotation.zep", 111);
  213. do {
  214. if (ZEPHIR_IS_LONG(&type, 301) || ZEPHIR_IS_LONG(&type, 302) || ZEPHIR_IS_LONG(&type, 303) || ZEPHIR_IS_LONG(&type, 307)) {
  215. ZEPHIR_OBS_VAR(&value);
  216. zephir_array_fetch_string(&value, &expr, SL("value"), PH_NOISY, "phalcon/Annotations/Annotation.zep", 118);
  217. break;
  218. }
  219. if (ZEPHIR_IS_LONG(&type, 304)) {
  220. ZEPHIR_INIT_NVAR(&value);
  221. ZVAL_NULL(&value);
  222. break;
  223. }
  224. if (ZEPHIR_IS_LONG(&type, 305)) {
  225. ZEPHIR_INIT_NVAR(&value);
  226. ZVAL_BOOL(&value, 0);
  227. break;
  228. }
  229. if (ZEPHIR_IS_LONG(&type, 306)) {
  230. ZEPHIR_INIT_NVAR(&value);
  231. ZVAL_BOOL(&value, 1);
  232. break;
  233. }
  234. if (ZEPHIR_IS_LONG(&type, 308)) {
  235. ZEPHIR_INIT_VAR(&arrayValue);
  236. array_init(&arrayValue);
  237. zephir_array_fetch_string(&_0$$7, &expr, SL("items"), PH_NOISY | PH_READONLY, "phalcon/Annotations/Annotation.zep", 136);
  238. zephir_is_iterable(&_0$$7, 0, "phalcon/Annotations/Annotation.zep", 148);
  239. if (Z_TYPE_P(&_0$$7) == IS_ARRAY) {
  240. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&_0$$7), _1$$7)
  241. {
  242. ZEPHIR_INIT_NVAR(&item);
  243. ZVAL_COPY(&item, _1$$7);
  244. zephir_array_fetch_string(&_3$$8, &item, SL("expr"), PH_NOISY | PH_READONLY, "phalcon/Annotations/Annotation.zep", 139);
  245. ZEPHIR_CALL_METHOD(&resolvedItem, this_ptr, "getexpression", &_4, 154, &_3$$8);
  246. zephir_check_call_status();
  247. ZEPHIR_OBS_NVAR(&name);
  248. if (zephir_array_isset_string_fetch(&name, &item, SL("name"), 0)) {
  249. zephir_array_update_zval(&arrayValue, &name, &resolvedItem, PH_COPY | PH_SEPARATE);
  250. } else {
  251. zephir_array_append(&arrayValue, &resolvedItem, PH_SEPARATE, "phalcon/Annotations/Annotation.zep", 144);
  252. }
  253. } ZEND_HASH_FOREACH_END();
  254. } else {
  255. ZEPHIR_CALL_METHOD(NULL, &_0$$7, "rewind", NULL, 0);
  256. zephir_check_call_status();
  257. while (1) {
  258. ZEPHIR_CALL_METHOD(&_2$$7, &_0$$7, "valid", NULL, 0);
  259. zephir_check_call_status();
  260. if (!zend_is_true(&_2$$7)) {
  261. break;
  262. }
  263. ZEPHIR_CALL_METHOD(&item, &_0$$7, "current", NULL, 0);
  264. zephir_check_call_status();
  265. zephir_array_fetch_string(&_5$$11, &item, SL("expr"), PH_NOISY | PH_READONLY, "phalcon/Annotations/Annotation.zep", 139);
  266. ZEPHIR_CALL_METHOD(&resolvedItem, this_ptr, "getexpression", &_4, 154, &_5$$11);
  267. zephir_check_call_status();
  268. ZEPHIR_OBS_NVAR(&name);
  269. if (zephir_array_isset_string_fetch(&name, &item, SL("name"), 0)) {
  270. zephir_array_update_zval(&arrayValue, &name, &resolvedItem, PH_COPY | PH_SEPARATE);
  271. } else {
  272. zephir_array_append(&arrayValue, &resolvedItem, PH_SEPARATE, "phalcon/Annotations/Annotation.zep", 144);
  273. }
  274. ZEPHIR_CALL_METHOD(NULL, &_0$$7, "next", NULL, 0);
  275. zephir_check_call_status();
  276. }
  277. }
  278. ZEPHIR_INIT_NVAR(&item);
  279. RETURN_CCTOR(&arrayValue);
  280. }
  281. if (ZEPHIR_IS_LONG(&type, 300)) {
  282. object_init_ex(return_value, phalcon_annotations_annotation_ce);
  283. ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 155, &expr);
  284. zephir_check_call_status();
  285. RETURN_MM();
  286. }
  287. ZEPHIR_INIT_VAR(&_6$$15);
  288. object_init_ex(&_6$$15, phalcon_annotations_exception_ce);
  289. ZEPHIR_INIT_VAR(&_7$$15);
  290. ZEPHIR_CONCAT_SVS(&_7$$15, "The expression ", &type, " is unknown");
  291. ZEPHIR_CALL_METHOD(NULL, &_6$$15, "__construct", NULL, 8, &_7$$15);
  292. zephir_check_call_status();
  293. zephir_throw_exception_debug(&_6$$15, "phalcon/Annotations/Annotation.zep", 154);
  294. ZEPHIR_MM_RESTORE();
  295. return;
  296. } while(0);
  297. RETURN_CCTOR(&value);
  298. }
  299. /**
  300. * Returns the annotation's name
  301. */
  302. PHP_METHOD(Phalcon_Annotations_Annotation, getName)
  303. {
  304. zval *this_ptr = getThis();
  305. RETURN_MEMBER(getThis(), "name");
  306. }
  307. /**
  308. * Returns a named argument
  309. */
  310. PHP_METHOD(Phalcon_Annotations_Annotation, getNamedArgument)
  311. {
  312. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  313. zval *name_param = NULL, argument, _0;
  314. zval name;
  315. zval *this_ptr = getThis();
  316. ZVAL_UNDEF(&name);
  317. ZVAL_UNDEF(&argument);
  318. ZVAL_UNDEF(&_0);
  319. #if PHP_VERSION_ID >= 80000
  320. bool is_null_true = 1;
  321. ZEND_PARSE_PARAMETERS_START(1, 1)
  322. Z_PARAM_STR(name)
  323. ZEND_PARSE_PARAMETERS_END();
  324. #endif
  325. ZEPHIR_MM_GROW();
  326. zephir_fetch_params(1, 1, 0, &name_param);
  327. if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
  328. zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
  329. RETURN_MM_NULL();
  330. }
  331. if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
  332. zephir_get_strval(&name, name_param);
  333. } else {
  334. ZEPHIR_INIT_VAR(&name);
  335. }
  336. zephir_read_property(&_0, this_ptr, ZEND_STRL("arguments"), PH_NOISY_CC | PH_READONLY);
  337. if (zephir_array_isset_fetch(&argument, &_0, &name, 1)) {
  338. RETURN_CTOR(&argument);
  339. }
  340. RETURN_MM_NULL();
  341. }
  342. /**
  343. * Returns a named parameter
  344. */
  345. PHP_METHOD(Phalcon_Annotations_Annotation, getNamedParameter)
  346. {
  347. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  348. zend_long ZEPHIR_LAST_CALL_STATUS;
  349. zval *name_param = NULL;
  350. zval name;
  351. zval *this_ptr = getThis();
  352. ZVAL_UNDEF(&name);
  353. #if PHP_VERSION_ID >= 80000
  354. bool is_null_true = 1;
  355. ZEND_PARSE_PARAMETERS_START(1, 1)
  356. Z_PARAM_STR(name)
  357. ZEND_PARSE_PARAMETERS_END();
  358. #endif
  359. ZEPHIR_MM_GROW();
  360. zephir_fetch_params(1, 1, 0, &name_param);
  361. if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
  362. zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
  363. RETURN_MM_NULL();
  364. }
  365. if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
  366. zephir_get_strval(&name, name_param);
  367. } else {
  368. ZEPHIR_INIT_VAR(&name);
  369. }
  370. ZEPHIR_RETURN_CALL_METHOD(this_ptr, "getnamedargument", NULL, 0, &name);
  371. zephir_check_call_status();
  372. RETURN_MM();
  373. }
  374. /**
  375. * Returns an argument in a specific position
  376. */
  377. PHP_METHOD(Phalcon_Annotations_Annotation, hasArgument)
  378. {
  379. zval *position, position_sub, _0;
  380. zval *this_ptr = getThis();
  381. ZVAL_UNDEF(&position_sub);
  382. ZVAL_UNDEF(&_0);
  383. #if PHP_VERSION_ID >= 80000
  384. bool is_null_true = 1;
  385. ZEND_PARSE_PARAMETERS_START(1, 1)
  386. Z_PARAM_ZVAL(position)
  387. ZEND_PARSE_PARAMETERS_END();
  388. #endif
  389. zephir_fetch_params_without_memory_grow(1, 0, &position);
  390. zephir_read_property(&_0, this_ptr, ZEND_STRL("arguments"), PH_NOISY_CC | PH_READONLY);
  391. RETURN_BOOL(zephir_array_isset(&_0, position));
  392. }
  393. /**
  394. * Returns the number of arguments that the annotation has
  395. */
  396. PHP_METHOD(Phalcon_Annotations_Annotation, numberArguments)
  397. {
  398. zval _0;
  399. zval *this_ptr = getThis();
  400. ZVAL_UNDEF(&_0);
  401. zephir_read_property(&_0, this_ptr, ZEND_STRL("arguments"), PH_NOISY_CC | PH_READONLY);
  402. RETURN_LONG(zephir_fast_count_int(&_0));
  403. }
  404. zend_object *zephir_init_properties_Phalcon_Annotations_Annotation(zend_class_entry *class_type)
  405. {
  406. zval _0, _2, _1$$3, _3$$4;
  407. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  408. ZVAL_UNDEF(&_0);
  409. ZVAL_UNDEF(&_2);
  410. ZVAL_UNDEF(&_1$$3);
  411. ZVAL_UNDEF(&_3$$4);
  412. ZEPHIR_MM_GROW();
  413. {
  414. zval local_this_ptr, *this_ptr = &local_this_ptr;
  415. ZEPHIR_CREATE_OBJECT(this_ptr, class_type);
  416. zephir_read_property_ex(&_0, this_ptr, ZEND_STRL("exprArguments"), PH_NOISY_CC | PH_READONLY);
  417. if (Z_TYPE_P(&_0) == IS_NULL) {
  418. ZEPHIR_INIT_VAR(&_1$$3);
  419. array_init(&_1$$3);
  420. zephir_update_property_zval_ex(this_ptr, ZEND_STRL("exprArguments"), &_1$$3);
  421. }
  422. zephir_read_property_ex(&_2, this_ptr, ZEND_STRL("arguments"), PH_NOISY_CC | PH_READONLY);
  423. if (Z_TYPE_P(&_2) == IS_NULL) {
  424. ZEPHIR_INIT_VAR(&_3$$4);
  425. array_init(&_3$$4);
  426. zephir_update_property_zval_ex(this_ptr, ZEND_STRL("arguments"), &_3$$4);
  427. }
  428. ZEPHIR_MM_RESTORE();
  429. return Z_OBJ_P(this_ptr);
  430. }
  431. }