/** * Writes the meta-data to files * * @param string $key * @param array $data */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ zval **key, **data, *meta_data_dir, *virtual_key; zval *path, *php_export, *status; smart_str exp = { NULL, 0, 0 }; phalcon_fetch_params_ex(2, 0, &key, &data); PHALCON_MM_GROW(); meta_data_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_metaDataDir"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path_ex(virtual_key, Z_STRVAL_PP(key), Z_STRLEN_PP(key), '_' TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); smart_str_appends(&exp, "<?php return "); php_var_export_ex(data, 0, &exp TSRMLS_CC); smart_str_appendc(&exp, ';'); smart_str_0(&exp); PHALCON_INIT_VAR(php_export); ZVAL_STRINGL(php_export, exp.c, exp.len, 0); PHALCON_INIT_VAR(status); phalcon_file_put_contents(status, path, php_export TSRMLS_CC); if (PHALCON_IS_FALSE(status)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Meta-Data directory cannot be written"); return; } PHALCON_MM_RESTORE(); }
/** * Writes parsed annotations to files * * @param string $key * @param Phalcon\Annotations\Reflection $data */ PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){ zval *key, *data, annotations_dir = {}, virtual_key = {}, path = {}, php_export = {}, status = {}; smart_str exp = { 0 }; phalcon_fetch_params(0, 2, 0, &key, &data); PHALCON_ENSURE_IS_STRING(key); phalcon_return_property(&annotations_dir, getThis(), SL("_annotationsDir")); /** * Paths must be normalized before be used as keys */ phalcon_prepare_virtual_path_ex(&virtual_key, Z_STRVAL_P(key), Z_STRLEN_P(key), '_'); PHALCON_CONCAT_VVS(&path, &annotations_dir, &virtual_key, ".php"); smart_str_appends(&exp, "<?php return "); php_var_export_ex(data, 0, &exp); smart_str_appendc(&exp, ';'); smart_str_0(&exp); ZVAL_STR(&php_export, exp.s); phalcon_file_put_contents(&status, &path, &php_export); if (PHALCON_IS_FALSE(&status)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Annotations directory cannot be written"); return; } }
/** * Reads meta-data from files * * @param string $key * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ zval **key, *meta_data_dir, *virtual_key; zval *path, *data = NULL; phalcon_fetch_params_ex(1, 0, &key); PHALCON_ENSURE_IS_STRING(key); PHALCON_MM_GROW(); meta_data_dir = phalcon_fetch_nproperty_this(this_ptr, SL("_metaDataDir"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path_ex(virtual_key, Z_STRVAL_PP(key), Z_STRLEN_PP(key), '_' TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { RETURN_MM_ON_FAILURE(phalcon_require_ret(&data, Z_STRVAL_P(path) TSRMLS_CC)); RETVAL_ZVAL(data, 1, 1); } PHALCON_MM_RESTORE(); }
/** * Reads parsed annotations from files * * @param string $key * @return Phalcon\Annotations\Reflection */ PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){ zval *key, annotations_dir = {}, virtual_key = {}, path = {}; phalcon_fetch_params(0, 1, 0, &key); PHALCON_ENSURE_IS_STRING(key); phalcon_return_property(&annotations_dir, getThis(), SL("_annotationsDir")); /** * Paths must be normalized before be used as keys */ phalcon_prepare_virtual_path_ex(&virtual_key, Z_STRVAL_P(key), Z_STRLEN_P(key), '_'); PHALCON_CONCAT_VVS(&path, &annotations_dir, &virtual_key, ".php"); if (phalcon_file_exists(&path) == SUCCESS) { RETURN_ON_FAILURE(phalcon_require_ret(return_value, Z_STRVAL(path))); return; } }