PageRenderTime 27ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/phalcon/datamapper/pdo/profiler/memorylogger.zep.c

http://github.com/phalcon/cphalcon
C | 497 lines | 361 code | 71 blank | 65 comment | 28 complexity | ede84f9826e4bba8f05187a269d84fd7 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/object.h"
  12. #include "kernel/fcall.h"
  13. #include "kernel/memory.h"
  14. #include "kernel/operators.h"
  15. #include "kernel/concat.h"
  16. #include "kernel/array.h"
  17. /**
  18. * This file is part of the Phalcon Framework.
  19. *
  20. * (c) Phalcon Team <team@phalcon.io>
  21. *
  22. * For the full copyright and license information, please view the LICENSE.txt
  23. * file that was distributed with this source code.
  24. *
  25. * Implementation of this file has been influenced by AtlasPHP
  26. *
  27. * @link https://github.com/atlasphp/Atlas.Pdo
  28. * @license https://github.com/atlasphp/Atlas.Pdo/blob/1.x/LICENSE.md
  29. */
  30. /**
  31. * A naive memory-based logger.
  32. *
  33. * @property array $messages
  34. */
  35. ZEPHIR_INIT_CLASS(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger)
  36. {
  37. ZEPHIR_REGISTER_CLASS_EX(Phalcon\\DataMapper\\Pdo\\Profiler, MemoryLogger, phalcon, datamapper_pdo_profiler_memorylogger, zephir_get_internal_ce(SL("psr\\log\\abstractlogger")), phalcon_datamapper_pdo_profiler_memorylogger_method_entry, 0);
  38. /**
  39. * @var array
  40. */
  41. zend_declare_property_null(phalcon_datamapper_pdo_profiler_memorylogger_ce, SL("messages"), ZEND_ACC_PROTECTED);
  42. phalcon_datamapper_pdo_profiler_memorylogger_ce->create_object = zephir_init_properties_Phalcon_DataMapper_Pdo_Profiler_MemoryLogger;
  43. return SUCCESS;
  44. }
  45. /**
  46. * Returns the logged messages.
  47. *
  48. * @return array
  49. */
  50. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, getMessages)
  51. {
  52. zval *this_ptr = getThis();
  53. RETURN_MEMBER(getThis(), "messages");
  54. }
  55. /**
  56. * @param string message
  57. * @param mixed[] context
  58. */
  59. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, emergency)
  60. {
  61. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  62. zend_long ZEPHIR_LAST_CALL_STATUS;
  63. zval context;
  64. zval *message, message_sub, *context_param = NULL;
  65. zval *this_ptr = getThis();
  66. ZVAL_UNDEF(&message_sub);
  67. ZVAL_UNDEF(&context);
  68. #if PHP_VERSION_ID >= 80000
  69. bool is_null_true = 1;
  70. ZEND_PARSE_PARAMETERS_START(1, 2)
  71. Z_PARAM_ZVAL(message)
  72. Z_PARAM_OPTIONAL
  73. Z_PARAM_ARRAY(context)
  74. ZEND_PARSE_PARAMETERS_END();
  75. #endif
  76. ZEPHIR_MM_GROW();
  77. zephir_fetch_params(1, 1, 1, &message, &context_param);
  78. if (!context_param) {
  79. ZEPHIR_INIT_VAR(&context);
  80. array_init(&context);
  81. } else {
  82. zephir_get_arrval(&context, context_param);
  83. }
  84. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "emergency", NULL, 0, message, &context);
  85. zephir_check_call_status();
  86. ZEPHIR_MM_RESTORE();
  87. }
  88. /**
  89. * @param string message
  90. * @param mixed[] context
  91. */
  92. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, alert)
  93. {
  94. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  95. zend_long ZEPHIR_LAST_CALL_STATUS;
  96. zval context;
  97. zval *message, message_sub, *context_param = NULL;
  98. zval *this_ptr = getThis();
  99. ZVAL_UNDEF(&message_sub);
  100. ZVAL_UNDEF(&context);
  101. #if PHP_VERSION_ID >= 80000
  102. bool is_null_true = 1;
  103. ZEND_PARSE_PARAMETERS_START(1, 2)
  104. Z_PARAM_ZVAL(message)
  105. Z_PARAM_OPTIONAL
  106. Z_PARAM_ARRAY(context)
  107. ZEND_PARSE_PARAMETERS_END();
  108. #endif
  109. ZEPHIR_MM_GROW();
  110. zephir_fetch_params(1, 1, 1, &message, &context_param);
  111. if (!context_param) {
  112. ZEPHIR_INIT_VAR(&context);
  113. array_init(&context);
  114. } else {
  115. zephir_get_arrval(&context, context_param);
  116. }
  117. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "alert", NULL, 0, message, &context);
  118. zephir_check_call_status();
  119. ZEPHIR_MM_RESTORE();
  120. }
  121. /**
  122. * @param string message
  123. * @param mixed[] context
  124. */
  125. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, critical)
  126. {
  127. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  128. zend_long ZEPHIR_LAST_CALL_STATUS;
  129. zval context;
  130. zval *message, message_sub, *context_param = NULL;
  131. zval *this_ptr = getThis();
  132. ZVAL_UNDEF(&message_sub);
  133. ZVAL_UNDEF(&context);
  134. #if PHP_VERSION_ID >= 80000
  135. bool is_null_true = 1;
  136. ZEND_PARSE_PARAMETERS_START(1, 2)
  137. Z_PARAM_ZVAL(message)
  138. Z_PARAM_OPTIONAL
  139. Z_PARAM_ARRAY(context)
  140. ZEND_PARSE_PARAMETERS_END();
  141. #endif
  142. ZEPHIR_MM_GROW();
  143. zephir_fetch_params(1, 1, 1, &message, &context_param);
  144. if (!context_param) {
  145. ZEPHIR_INIT_VAR(&context);
  146. array_init(&context);
  147. } else {
  148. zephir_get_arrval(&context, context_param);
  149. }
  150. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "critical", NULL, 0, message, &context);
  151. zephir_check_call_status();
  152. ZEPHIR_MM_RESTORE();
  153. }
  154. /**
  155. * @param string message
  156. * @param mixed[] context
  157. */
  158. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, error)
  159. {
  160. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  161. zend_long ZEPHIR_LAST_CALL_STATUS;
  162. zval context;
  163. zval *message, message_sub, *context_param = NULL;
  164. zval *this_ptr = getThis();
  165. ZVAL_UNDEF(&message_sub);
  166. ZVAL_UNDEF(&context);
  167. #if PHP_VERSION_ID >= 80000
  168. bool is_null_true = 1;
  169. ZEND_PARSE_PARAMETERS_START(1, 2)
  170. Z_PARAM_ZVAL(message)
  171. Z_PARAM_OPTIONAL
  172. Z_PARAM_ARRAY(context)
  173. ZEND_PARSE_PARAMETERS_END();
  174. #endif
  175. ZEPHIR_MM_GROW();
  176. zephir_fetch_params(1, 1, 1, &message, &context_param);
  177. if (!context_param) {
  178. ZEPHIR_INIT_VAR(&context);
  179. array_init(&context);
  180. } else {
  181. zephir_get_arrval(&context, context_param);
  182. }
  183. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "error", NULL, 0, message, &context);
  184. zephir_check_call_status();
  185. ZEPHIR_MM_RESTORE();
  186. }
  187. /**
  188. * @param string message
  189. * @param mixed[] context
  190. */
  191. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, warning)
  192. {
  193. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  194. zend_long ZEPHIR_LAST_CALL_STATUS;
  195. zval context;
  196. zval *message, message_sub, *context_param = NULL;
  197. zval *this_ptr = getThis();
  198. ZVAL_UNDEF(&message_sub);
  199. ZVAL_UNDEF(&context);
  200. #if PHP_VERSION_ID >= 80000
  201. bool is_null_true = 1;
  202. ZEND_PARSE_PARAMETERS_START(1, 2)
  203. Z_PARAM_ZVAL(message)
  204. Z_PARAM_OPTIONAL
  205. Z_PARAM_ARRAY(context)
  206. ZEND_PARSE_PARAMETERS_END();
  207. #endif
  208. ZEPHIR_MM_GROW();
  209. zephir_fetch_params(1, 1, 1, &message, &context_param);
  210. if (!context_param) {
  211. ZEPHIR_INIT_VAR(&context);
  212. array_init(&context);
  213. } else {
  214. zephir_get_arrval(&context, context_param);
  215. }
  216. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "warning", NULL, 0, message, &context);
  217. zephir_check_call_status();
  218. ZEPHIR_MM_RESTORE();
  219. }
  220. /**
  221. * @param string message
  222. * @param mixed[] context
  223. */
  224. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, notice)
  225. {
  226. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  227. zend_long ZEPHIR_LAST_CALL_STATUS;
  228. zval context;
  229. zval *message, message_sub, *context_param = NULL;
  230. zval *this_ptr = getThis();
  231. ZVAL_UNDEF(&message_sub);
  232. ZVAL_UNDEF(&context);
  233. #if PHP_VERSION_ID >= 80000
  234. bool is_null_true = 1;
  235. ZEND_PARSE_PARAMETERS_START(1, 2)
  236. Z_PARAM_ZVAL(message)
  237. Z_PARAM_OPTIONAL
  238. Z_PARAM_ARRAY(context)
  239. ZEND_PARSE_PARAMETERS_END();
  240. #endif
  241. ZEPHIR_MM_GROW();
  242. zephir_fetch_params(1, 1, 1, &message, &context_param);
  243. if (!context_param) {
  244. ZEPHIR_INIT_VAR(&context);
  245. array_init(&context);
  246. } else {
  247. zephir_get_arrval(&context, context_param);
  248. }
  249. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "notice", NULL, 0, message, &context);
  250. zephir_check_call_status();
  251. ZEPHIR_MM_RESTORE();
  252. }
  253. /**
  254. * @param string message
  255. * @param mixed[] context
  256. */
  257. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, info)
  258. {
  259. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  260. zend_long ZEPHIR_LAST_CALL_STATUS;
  261. zval context;
  262. zval *message, message_sub, *context_param = NULL;
  263. zval *this_ptr = getThis();
  264. ZVAL_UNDEF(&message_sub);
  265. ZVAL_UNDEF(&context);
  266. #if PHP_VERSION_ID >= 80000
  267. bool is_null_true = 1;
  268. ZEND_PARSE_PARAMETERS_START(1, 2)
  269. Z_PARAM_ZVAL(message)
  270. Z_PARAM_OPTIONAL
  271. Z_PARAM_ARRAY(context)
  272. ZEND_PARSE_PARAMETERS_END();
  273. #endif
  274. ZEPHIR_MM_GROW();
  275. zephir_fetch_params(1, 1, 1, &message, &context_param);
  276. if (!context_param) {
  277. ZEPHIR_INIT_VAR(&context);
  278. array_init(&context);
  279. } else {
  280. zephir_get_arrval(&context, context_param);
  281. }
  282. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "info", NULL, 0, message, &context);
  283. zephir_check_call_status();
  284. ZEPHIR_MM_RESTORE();
  285. }
  286. /**
  287. * @param string message
  288. * @param mixed[] context
  289. */
  290. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, debug)
  291. {
  292. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  293. zend_long ZEPHIR_LAST_CALL_STATUS;
  294. zval context;
  295. zval *message, message_sub, *context_param = NULL;
  296. zval *this_ptr = getThis();
  297. ZVAL_UNDEF(&message_sub);
  298. ZVAL_UNDEF(&context);
  299. #if PHP_VERSION_ID >= 80000
  300. bool is_null_true = 1;
  301. ZEND_PARSE_PARAMETERS_START(1, 2)
  302. Z_PARAM_ZVAL(message)
  303. Z_PARAM_OPTIONAL
  304. Z_PARAM_ARRAY(context)
  305. ZEND_PARSE_PARAMETERS_END();
  306. #endif
  307. ZEPHIR_MM_GROW();
  308. zephir_fetch_params(1, 1, 1, &message, &context_param);
  309. if (!context_param) {
  310. ZEPHIR_INIT_VAR(&context);
  311. array_init(&context);
  312. } else {
  313. zephir_get_arrval(&context, context_param);
  314. }
  315. ZEPHIR_CALL_PARENT(NULL, phalcon_datamapper_pdo_profiler_memorylogger_ce, getThis(), "debug", NULL, 0, message, &context);
  316. zephir_check_call_status();
  317. ZEPHIR_MM_RESTORE();
  318. }
  319. /**
  320. * Logs a message.
  321. *
  322. * @param mixed $level
  323. * @param string $message
  324. * @param array $context
  325. */
  326. PHP_METHOD(Phalcon_DataMapper_Pdo_Profiler_MemoryLogger, log)
  327. {
  328. zend_string *_3;
  329. zend_ulong _2;
  330. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  331. zend_long ZEPHIR_LAST_CALL_STATUS;
  332. zval context, replace;
  333. zval *level, level_sub, *message, message_sub, *context_param = NULL, key, value, *_0, _1, _6, _4$$3, _5$$4;
  334. zval *this_ptr = getThis();
  335. ZVAL_UNDEF(&level_sub);
  336. ZVAL_UNDEF(&message_sub);
  337. ZVAL_UNDEF(&key);
  338. ZVAL_UNDEF(&value);
  339. ZVAL_UNDEF(&_1);
  340. ZVAL_UNDEF(&_6);
  341. ZVAL_UNDEF(&_4$$3);
  342. ZVAL_UNDEF(&_5$$4);
  343. ZVAL_UNDEF(&context);
  344. ZVAL_UNDEF(&replace);
  345. #if PHP_VERSION_ID >= 80000
  346. bool is_null_true = 1;
  347. ZEND_PARSE_PARAMETERS_START(2, 3)
  348. Z_PARAM_ZVAL(level)
  349. Z_PARAM_ZVAL(message)
  350. Z_PARAM_OPTIONAL
  351. Z_PARAM_ARRAY(context)
  352. ZEND_PARSE_PARAMETERS_END();
  353. #endif
  354. ZEPHIR_MM_GROW();
  355. zephir_fetch_params(1, 2, 1, &level, &message, &context_param);
  356. if (!context_param) {
  357. ZEPHIR_INIT_VAR(&context);
  358. array_init(&context);
  359. } else {
  360. zephir_get_arrval(&context, context_param);
  361. }
  362. ZEPHIR_INIT_VAR(&replace);
  363. array_init(&replace);
  364. zephir_is_iterable(&context, 0, "phalcon/DataMapper/Pdo/Profiler/MemoryLogger.zep", 130);
  365. if (Z_TYPE_P(&context) == IS_ARRAY) {
  366. ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&context), _2, _3, _0)
  367. {
  368. ZEPHIR_INIT_NVAR(&key);
  369. if (_3 != NULL) {
  370. ZVAL_STR_COPY(&key, _3);
  371. } else {
  372. ZVAL_LONG(&key, _2);
  373. }
  374. ZEPHIR_INIT_NVAR(&value);
  375. ZVAL_COPY(&value, _0);
  376. ZEPHIR_INIT_NVAR(&_4$$3);
  377. ZEPHIR_CONCAT_SVS(&_4$$3, "{", &key, "}");
  378. zephir_array_update_zval(&replace, &_4$$3, &value, PH_COPY | PH_SEPARATE);
  379. } ZEND_HASH_FOREACH_END();
  380. } else {
  381. ZEPHIR_CALL_METHOD(NULL, &context, "rewind", NULL, 0);
  382. zephir_check_call_status();
  383. while (1) {
  384. ZEPHIR_CALL_METHOD(&_1, &context, "valid", NULL, 0);
  385. zephir_check_call_status();
  386. if (!zend_is_true(&_1)) {
  387. break;
  388. }
  389. ZEPHIR_CALL_METHOD(&key, &context, "key", NULL, 0);
  390. zephir_check_call_status();
  391. ZEPHIR_CALL_METHOD(&value, &context, "current", NULL, 0);
  392. zephir_check_call_status();
  393. ZEPHIR_INIT_NVAR(&_5$$4);
  394. ZEPHIR_CONCAT_SVS(&_5$$4, "{", &key, "}");
  395. zephir_array_update_zval(&replace, &_5$$4, &value, PH_COPY | PH_SEPARATE);
  396. ZEPHIR_CALL_METHOD(NULL, &context, "next", NULL, 0);
  397. zephir_check_call_status();
  398. }
  399. }
  400. ZEPHIR_INIT_NVAR(&value);
  401. ZEPHIR_INIT_NVAR(&key);
  402. ZEPHIR_CALL_FUNCTION(&_6, "strtr", NULL, 5, message, &replace);
  403. zephir_check_call_status();
  404. zephir_update_property_array_append(this_ptr, SL("messages"), &_6);
  405. ZEPHIR_MM_RESTORE();
  406. }
  407. zend_object *zephir_init_properties_Phalcon_DataMapper_Pdo_Profiler_MemoryLogger(zend_class_entry *class_type)
  408. {
  409. zval _0, _1$$3;
  410. zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
  411. ZVAL_UNDEF(&_0);
  412. ZVAL_UNDEF(&_1$$3);
  413. ZEPHIR_MM_GROW();
  414. {
  415. zval local_this_ptr, *this_ptr = &local_this_ptr;
  416. ZEPHIR_CREATE_OBJECT(this_ptr, class_type);
  417. zephir_read_property_ex(&_0, this_ptr, ZEND_STRL("messages"), PH_NOISY_CC | PH_READONLY);
  418. if (Z_TYPE_P(&_0) == IS_NULL) {
  419. ZEPHIR_INIT_VAR(&_1$$3);
  420. array_init(&_1$$3);
  421. zephir_update_property_zval_ex(this_ptr, ZEND_STRL("messages"), &_1$$3);
  422. }
  423. ZEPHIR_MM_RESTORE();
  424. return Z_OBJ_P(this_ptr);
  425. }
  426. }