/** * Reads parsed annotations from files * * @param string $key * @return array */ PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){ zval *key, *annotations_dir, *separator, *virtual_key; zval *path, *data; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &key) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(annotations_dir); phalcon_read_property_this(&annotations_dir, this_ptr, SL("_annotationsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(separator); ZVAL_STRING(separator, "_", 1); PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(data); if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { return; } RETURN_CCTOR(data); } RETURN_MM_NULL(); }
/** * Reads parsed annotations from files * * @param string $key * @return Phalcon\Annotations\Reflection */ PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){ zval *key, *annotations_dir, *separator, *virtual_key; zval *path, *data; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &key); PHALCON_OBS_VAR(annotations_dir); phalcon_read_property_this(&annotations_dir, this_ptr, SL("_annotationsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(separator); ZVAL_STRING(separator, "_", 1); /** * Paths must be normalized before be used as keys */ PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(data); if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { return; } RETURN_CCTOR(data); } RETURN_MM_NULL(); }
/** * 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, *separator; zval *virtual_key, *path, *to_string, *export, *php_export; zval *status; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &key, &data); PHALCON_OBS_VAR(annotations_dir); phalcon_read_property_this(&annotations_dir, this_ptr, SL("_annotationsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(separator); ZVAL_STRING(separator, "_", 1); /** * Paths must be normalized before be used as keys */ PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); PHALCON_INIT_VAR(to_string); ZVAL_BOOL(to_string, 1); PHALCON_INIT_VAR(export); phalcon_call_func_p2(export, "var_export", data, to_string); PHALCON_INIT_VAR(php_export); PHALCON_CONCAT_SVS(php_export, "<?php return ", export, "; "); PHALCON_INIT_VAR(status); phalcon_file_put_contents(status, path, php_export TSRMLS_CC); if (PHALCON_IS_FALSE(status)) { PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Annotations directory cannot be written"); return; } PHALCON_MM_RESTORE(); }
/** * Writes parsed annotations to files * * @param string $key * @param array $data */ PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){ zval *key, *data, *annotations_dir, *separator; zval *virtual_key, *path, *to_string, *export, *php_export; zval *status; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &key, &data) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(annotations_dir); phalcon_read_property_this(&annotations_dir, this_ptr, SL("_annotationsDir"), PH_NOISY_CC); PHALCON_INIT_VAR(separator); ZVAL_STRING(separator, "_", 1); PHALCON_INIT_VAR(virtual_key); phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); PHALCON_INIT_VAR(path); PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); PHALCON_INIT_VAR(to_string); ZVAL_BOOL(to_string, 1); PHALCON_INIT_VAR(export); PHALCON_CALL_FUNC_PARAMS_2(export, "var_export", data, to_string); PHALCON_INIT_VAR(php_export); PHALCON_CONCAT_SVS(php_export, "<?php return ", export, "; "); PHALCON_INIT_VAR(status); PHALCON_CALL_FUNC_PARAMS_2(status, "file_put_contents", path, php_export); if (PHALCON_IS_FALSE(status)) { PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Annotations directory cannot be written"); return; } PHALCON_MM_RESTORE(); }