/** * Writes parsed annotations to files */ PHP_METHOD(Phalcon_Annotations_Adapter_Files, write) { zval *key_param = NULL, *data, *path = NULL, *_0, *_1, _2, *_3, *_4 = NULL, *_5; zval *key = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 2, 0, &key_param, &data); if (unlikely(Z_TYPE_P(key_param) != IS_STRING && Z_TYPE_P(key_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'key' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(key_param) == IS_STRING)) { zephir_get_strval(key, key_param); } else { ZEPHIR_INIT_VAR(key); ZVAL_EMPTY_STRING(key); } _0 = zephir_fetch_nproperty_this(this_ptr, SL("_annotationsDir"), PH_NOISY_CC); ZEPHIR_INIT_VAR(_1); ZEPHIR_SINIT_VAR(_2); ZVAL_STRING(&_2, "_", 0); zephir_prepare_virtual_path(_1, key, &_2 TSRMLS_CC); ZEPHIR_INIT_VAR(path); ZEPHIR_CONCAT_VVS(path, _0, _1, ".php"); ZEPHIR_INIT_VAR(_3); ZEPHIR_INIT_VAR(_4); ZEPHIR_INIT_NVAR(_4); zephir_var_export_ex(_4, &data TSRMLS_CC); ZEPHIR_INIT_VAR(_5); ZEPHIR_CONCAT_SVS(_5, "<?php return ", _4, "; "); zephir_file_put_contents(_3, path, _5 TSRMLS_CC); if (ZEPHIR_IS_FALSE_IDENTICAL(_3)) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_annotations_exception_ce, "Annotations directory cannot be written", "phalcon/annotations/adapter/files.zep", 91); return; } ZEPHIR_MM_RESTORE(); }
/** * Stores cached content into the file backend and stops the frontend * * @param int|string keyName * @param string content * @param int lifetime * @param boolean stopBuffer */ PHP_METHOD(Phalcon_Cache_Backend_File, save) { zephir_nts_static zephir_fcall_cache_entry *_4 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *keyName = NULL, *content = NULL, *lifetime = NULL, *stopBuffer = NULL, *lastKey = NULL, *frontend, *cacheDir, *isBuffering = NULL, *cacheFile, *cachedContent = NULL, *preparedContent = NULL, *status = NULL, *_0, *_1 = NULL, *_2, *_3; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 0, 4, &keyName, &content, &lifetime, &stopBuffer); if (!keyName) { keyName = ZEPHIR_GLOBAL(global_null); } if (!content) { content = ZEPHIR_GLOBAL(global_null); } if (!lifetime) { lifetime = ZEPHIR_GLOBAL(global_null); } if (!stopBuffer) { stopBuffer = ZEPHIR_GLOBAL(global_true); } if (!(zephir_is_true(keyName))) { ZEPHIR_OBS_VAR(lastKey); zephir_read_property_this(&lastKey, this_ptr, SL("_lastKey"), PH_NOISY_CC); } else { _0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC); ZEPHIR_CALL_METHOD(&_1, this_ptr, "getkey", NULL, keyName); zephir_check_call_status(); ZEPHIR_INIT_NVAR(lastKey); ZEPHIR_CONCAT_VV(lastKey, _0, _1); } if (!(zephir_is_true(lastKey))) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Cache must be started first", "phalcon/cache/backend/file.zep", 186); return; } ZEPHIR_OBS_VAR(frontend); zephir_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC); ZEPHIR_OBS_VAR(cacheDir); _0 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC); if (!(zephir_array_isset_string_fetch(&cacheDir, _0, SS("cacheDir"), 0 TSRMLS_CC))) { ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 192); return; } ZEPHIR_INIT_VAR(cacheFile); ZEPHIR_CONCAT_VV(cacheFile, cacheDir, lastKey); if (!(zephir_is_true(content))) { ZEPHIR_CALL_METHOD(&cachedContent, frontend, "getcontent", NULL); zephir_check_call_status(); } else { ZEPHIR_CPY_WRT(cachedContent, content); } ZEPHIR_CALL_METHOD(&preparedContent, frontend, "beforestore", NULL, cachedContent); zephir_check_call_status(); if (!(zephir_is_numeric(cachedContent))) { ZEPHIR_INIT_VAR(status); zephir_file_put_contents(status, cacheFile, preparedContent TSRMLS_CC); } else { ZEPHIR_INIT_NVAR(status); zephir_file_put_contents(status, cacheFile, cachedContent TSRMLS_CC); } if (ZEPHIR_IS_FALSE_IDENTICAL(status)) { ZEPHIR_INIT_VAR(_2); object_init_ex(_2, phalcon_cache_exception_ce); ZEPHIR_INIT_VAR(_3); ZEPHIR_CONCAT_SVS(_3, "Cache file ", cacheFile, " could not be written"); ZEPHIR_CALL_METHOD(NULL, _2, "__construct", &_4, _3); zephir_check_call_status(); zephir_throw_exception_debug(_2, "phalcon/cache/backend/file.zep", 215 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_CALL_METHOD(&isBuffering, frontend, "isbuffering", NULL); zephir_check_call_status(); if (ZEPHIR_IS_TRUE_IDENTICAL(stopBuffer)) { ZEPHIR_CALL_METHOD(NULL, frontend, "stop", NULL); zephir_check_call_status(); } if (ZEPHIR_IS_TRUE_IDENTICAL(isBuffering)) { zend_print_zval(cachedContent, 0); } zephir_update_property_this(this_ptr, SL("_started"), (0) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC); ZEPHIR_MM_RESTORE(); }