Beispiel #1
0
/**
 * Read the model's column map, this can't be inferred
 *
 * @param Phalcon\Mvc\ModelInterface $model
 * @param Phalcon\DiInterface $dependencyInjector
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getColumnMaps){

	zval *model, *dependency_injector, *service;
	zval *ordered_column_map, *reversed_column_map = NULL;
	zval *annotations = NULL, *class_name, *reflection = NULL;
	zval *exception_message = NULL, *properties_annotations = NULL;
	zval *column_annot_name, *column_map_name;
	zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL;
	zval *column_annotation = NULL, *real_property = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &model, &dependency_injector);

	if (!PHALCON_GLOBAL(orm).column_renaming) {
		RETURN_MM_NULL();
	}

	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid");
		return;
	}

	PHALCON_INIT_VAR(service);
	ZVAL_STRING(service, "annotations", 1);

	PHALCON_CALL_METHOD(&annotations, dependency_injector, "get", service);

	PHALCON_INIT_VAR(class_name);
	phalcon_get_class(class_name, model, 0 TSRMLS_CC);

	PHALCON_CALL_METHOD(&reflection, annotations, "get", class_name);
	if (Z_TYPE_P(reflection) != IS_OBJECT) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name);
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message);
		return;
	}

	/** 
	 * Get the properties defined in 
	 */
	PHALCON_CALL_METHOD(&properties_annotations, reflection, "getpropertiesannotations");
	if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) {
		PHALCON_INIT_NVAR(exception_message);
		PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name);
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message);
		return;
	}

	/** 
	 * Initialize meta-data
	 */
	PHALCON_INIT_VAR(ordered_column_map);
	array_init(ordered_column_map);

	PHALCON_INIT_VAR(reversed_column_map);
	array_init(reversed_column_map);

	PHALCON_INIT_VAR(column_annot_name);
	ZVAL_STRING(column_annot_name, "Column", 1);

	PHALCON_INIT_VAR(column_map_name);
	ZVAL_STRING(column_map_name, "column", 1);

	phalcon_is_iterable(properties_annotations, &ah0, &hp0, 0, 0);

	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

		PHALCON_GET_HKEY(property, ah0, hp0);
		PHALCON_GET_HVALUE(prop_annotations);

		/** 
		 * All columns marked with the 'Column' annotation are considered columns
		 */
		PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", column_annot_name);
		if (!zend_is_true(has_annotation)) {
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}

		/** 
		 * Fetch the 'column' annotation
		 */
		PHALCON_CALL_METHOD(&column_annotation, prop_annotations, "get", column_annot_name);

		/** 
		 * Check column map
		 */
		PHALCON_CALL_METHOD(&real_property, column_annotation, "getargument", column_map_name);
		if (!PHALCON_IS_EMPTY(real_property)) {
			phalcon_array_update_zval(&ordered_column_map, real_property, property, PH_COPY);
			phalcon_array_update_zval(&reversed_column_map, property, real_property, PH_COPY);
		} else {
			phalcon_array_update_zval(&ordered_column_map, property, property, PH_COPY);
			phalcon_array_update_zval(&reversed_column_map, property, property, PH_COPY);
		}

		zend_hash_move_forward_ex(ah0, &hp0);
	}

	array_init_size(return_value, 2);
	phalcon_array_update_long(&return_value, 0, ordered_column_map, PH_COPY);
	phalcon_array_update_long(&return_value, 1, reversed_column_map, PH_COPY);

	PHALCON_MM_RESTORE();
}
Beispiel #2
0
/**
 * The meta-data is obtained by reading the column descriptions from the database information schema
 *
 * @param Phalcon\Mvc\ModelInterface $model
 * @param Phalcon\DiInterface $dependencyInjector
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getMetaData){

	zval *model, *dependency_injector, *service;
	zval *annotations = NULL, *class_name, *reflection = NULL;
	zval *exception_message = NULL, *properties_annotations = NULL;
	zval *attributes, *primary_keys, *non_primary_keys;
	zval *numeric_typed, *not_null, *field_types, *field_sizes, *field_bytes, *field_scales;
	zval *field_bind_types, *automatic_create_attributes, *automatic_update_attributes;
	zval *identity_field = NULL, *column_annot_name;
	zval *primary_annot_name, *id_annot_name;
	zval *column_map_name, *column_type_name, *column_size_name, *column_bytes_name, *column_scale_name, *column_nullable_name;
	zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL;
	zval *column_annotation = NULL, *real_property = NULL, *feature = NULL;
	zval *field_default_values, *column_default_value = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &model, &dependency_injector);

	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid");
		return;
	}

	PHALCON_INIT_VAR(service);
	ZVAL_STRING(service, "annotations", 1);

	PHALCON_CALL_METHOD(&annotations, dependency_injector, "get", service);

	PHALCON_INIT_VAR(class_name);
	phalcon_get_class(class_name, model, 0 TSRMLS_CC);

	PHALCON_CALL_METHOD(&reflection, annotations, "get", class_name);
	if (Z_TYPE_P(reflection) != IS_OBJECT) {
		PHALCON_INIT_VAR(exception_message);
		PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name);
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message);
		return;
	}

	/** 
	 * Get the properties defined in 
	 */
	PHALCON_CALL_METHOD(&properties_annotations, reflection, "getpropertiesannotations");

	if (!zend_is_true(properties_annotations) || !phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) {
		PHALCON_INIT_NVAR(exception_message);
		PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name);
		PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message);
		return;
	}

	/** 
	 * Initialize meta-data
	 */
	PHALCON_INIT_VAR(attributes);
	array_init(attributes);

	PHALCON_INIT_VAR(primary_keys);
	array_init(primary_keys);

	PHALCON_INIT_VAR(non_primary_keys);
	array_init(non_primary_keys);

	PHALCON_INIT_VAR(numeric_typed);
	array_init(numeric_typed);

	PHALCON_INIT_VAR(not_null);
	array_init(not_null);

	PHALCON_INIT_VAR(field_types);
	array_init(field_types);

	PHALCON_INIT_VAR(field_sizes);
	array_init(field_sizes);

	PHALCON_INIT_VAR(field_bytes);
	array_init(field_bytes);

	PHALCON_INIT_VAR(field_scales);
	array_init(field_scales);

	PHALCON_INIT_VAR(field_bind_types);
	array_init(field_bind_types);

	PHALCON_INIT_VAR(automatic_create_attributes);
	array_init(automatic_create_attributes);

	PHALCON_INIT_VAR(automatic_update_attributes);
	array_init(automatic_update_attributes);

	PHALCON_INIT_VAR(identity_field);
	ZVAL_FALSE(identity_field);

	PHALCON_INIT_VAR(field_default_values);
	array_init(field_default_values);

	PHALCON_INIT_VAR(column_annot_name);
	ZVAL_STRING(column_annot_name, "Column", 1);

	PHALCON_INIT_VAR(primary_annot_name);
	ZVAL_STRING(primary_annot_name, "Primary", 1);

	PHALCON_INIT_VAR(id_annot_name);
	ZVAL_STRING(id_annot_name, "Identity", 1);

	PHALCON_INIT_VAR(column_map_name);
	ZVAL_STRING(column_map_name, "column", 1);

	PHALCON_INIT_VAR(column_type_name);
	ZVAL_STRING(column_type_name, "type", 1);

	PHALCON_INIT_VAR(column_size_name);
	ZVAL_STRING(column_size_name, "size", 1);

	PHALCON_INIT_VAR(column_bytes_name);
	ZVAL_STRING(column_bytes_name, "bytes", 1);

	PHALCON_INIT_VAR(column_scale_name);
	ZVAL_STRING(column_scale_name, "scale", 1);

	PHALCON_INIT_VAR(column_default_value);
	ZVAL_STRING(column_default_value, "default", 1);

	PHALCON_INIT_VAR(column_nullable_name);
	ZVAL_STRING(column_nullable_name, "nullable", 1);

	phalcon_is_iterable(properties_annotations, &ah0, &hp0, 0, 0);
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HKEY(property, ah0, hp0);
		PHALCON_GET_HVALUE(prop_annotations);

		/** 
		 * All columns marked with the 'Column' annotation are considered columns
		 */
		PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", column_annot_name);
		if (!zend_is_true(has_annotation)) {
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}

		/** 
		 * Fetch the 'column' annotation
		 */
		PHALCON_CALL_METHOD(&column_annotation, prop_annotations, "get", column_annot_name);

		/** 
		 * Check column map
		 */
		PHALCON_CALL_METHOD(&real_property, column_annotation, "getargument", column_map_name);

		if (PHALCON_IS_EMPTY(real_property)) {
			PHALCON_CPY_WRT(real_property, property);
		}

		/** 
		 * Check if annotation has the 'type' named parameter
		 */
		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_type_name);

		if (PHALCON_IS_STRING(feature, "integer")) {
			phalcon_array_update_zval_long(&field_types, real_property, 0, PH_COPY);
			phalcon_array_update_zval_long(&field_bind_types, real_property, 1, PH_COPY);
			phalcon_array_update_zval_bool(&numeric_typed, real_property, 1, PH_COPY);
		} else if (PHALCON_IS_STRING(feature, "decimal")) {
			phalcon_array_update_zval_long(&field_types, real_property, 3, PH_COPY);
			phalcon_array_update_zval_long(&field_bind_types, real_property, 32, PH_COPY);
			phalcon_array_update_zval_bool(&numeric_typed, real_property, 1, PH_COPY);
		} else if (PHALCON_IS_STRING(feature, "boolean")) {
			phalcon_array_update_zval_long(&field_types, real_property, 8, PH_COPY);
			phalcon_array_update_zval_long(&field_bind_types, real_property, 5, PH_COPY);
		} else {
			if (PHALCON_IS_STRING(feature, "date")) {
				phalcon_array_update_zval_long(&field_types, real_property, 1, PH_COPY);
			} else {
				/**
				 * By default all columns are varchar/string
				 */
				phalcon_array_update_zval_long(&field_types, real_property, 2, PH_COPY);
			}
			phalcon_array_update_zval_long(&field_bind_types, real_property, 2, PH_COPY);
		}

		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_size_name);
		if (!PHALCON_IS_EMPTY(feature)) {
			phalcon_array_update_zval(&field_sizes, real_property, feature, PH_COPY);
			phalcon_array_update_zval(&field_bytes, real_property, feature, PH_COPY);
		}

		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_bytes_name);
		if (!PHALCON_IS_EMPTY(feature)) {
			phalcon_array_update_zval(&field_bytes, real_property, feature, PH_COPY);
		}

		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_scale_name);
		if (!PHALCON_IS_EMPTY(feature)) {
			phalcon_array_update_zval(&field_scales, real_property, feature, PH_COPY);
		}

		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_default_value);
		if (!PHALCON_IS_EMPTY(feature)) {
			phalcon_array_update_zval(&field_default_values, real_property, feature, PH_COPY);
		}

		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_default_value);
		if (!PHALCON_IS_EMPTY(feature)) {
			phalcon_array_update_zval(&field_default_values, property, feature, PH_COPY);
		}

		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_default_value);
		if (!PHALCON_IS_EMPTY(feature)) {
			phalcon_array_update_zval(&field_default_values, property, feature, PH_COPY);
		}

		/** 
		 * All columns marked with the 'Primary' annotation are considered primary keys
		 */
		PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", primary_annot_name);
		if (zend_is_true(has_annotation)) {
			phalcon_array_append(&primary_keys, real_property, PH_COPY);
		} else {
			phalcon_array_append(&non_primary_keys, real_property, PH_COPY);
		}

		/** 
		 * All columns marked with the 'Primary' annotation are considered primary keys
		 */
		PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", id_annot_name);
		if (zend_is_true(has_annotation)) {
			PHALCON_CPY_WRT(identity_field, real_property);
		}

		/** 
		 * Check if the column 
		 */
		PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_nullable_name);
		if (!zend_is_true(feature)) {
			phalcon_array_append(&not_null, real_property, PH_COPY);
		}

		phalcon_array_append(&attributes, real_property, PH_COPY);
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	/** 
	 * Create an array using the MODELS_* constants as indexes
	 */
	array_init_size(return_value, 14);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_ATTRIBUTES,  attributes, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_PRIMARY_KEY,  primary_keys, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_NON_PRIMARY_KEY,  non_primary_keys, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_NOT_NULL,  not_null, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_TYPES,  field_types, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_TYPES_NUMERIC,  numeric_typed, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_IDENTITY_COLUMN,  identity_field, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_TYPES_BIND,  field_bind_types, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_AUTOMATIC_DEFAULT_INSERT, automatic_create_attributes, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_AUTOMATIC_DEFAULT_UPDATE, automatic_update_attributes, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_DEFAULT_VALUE, field_default_values, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_SZIE, field_sizes, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_SCALE, field_scales, PH_COPY);
	phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_BYTE, field_bytes, PH_COPY);
	
	PHALCON_MM_RESTORE();
}
Beispiel #3
0
/**
 * Handles a MVC request
 *
 * @param string $uri
 * @return Phalcon\Http\ResponseInterface
 */
PHP_METHOD(Phalcon_Mvc_JsonRpc, handle){

	zval *uri = NULL, *dependency_injector, *events_manager;
	zval *status = NULL, *service = NULL, *request = NULL, *response = NULL;
	zval *json = NULL, *data = NULL, *jsonrpc_message, *jsonrpc_error, *jsonrpc_result = NULL;
	zval *jsonrpc_method, *jsonrpc_params, *jsonrpc_id;
	zval *url = NULL, *router = NULL, *module_name = NULL;
	zval *module_object = NULL, *modules;
	zval *module, *class_name = NULL, *module_params;
	zval *namespace_name = NULL;
	zval *controller_name = NULL, *action_name = NULL, *params = NULL, *exact = NULL;
	zval *dispatcher = NULL, *controller = NULL, *returned_response = NULL;
	zval *path;

	PHALCON_MM_GROW();
	
	dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY);
	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "A dependency injection object is required to access internal services");
		return;
	}
	
	events_manager = phalcon_read_property(getThis(), SL("_eventsManager"), PH_NOISY);
	if (Z_TYPE_P(events_manager) != IS_OBJECT) {
		events_manager = NULL;
	}
	else {
		PHALCON_VERIFY_INTERFACE_EX(events_manager, phalcon_events_managerinterface_ce, phalcon_mvc_jsonrpc_exception_ce, 1);
	}

	/* Call boot event, this allows the developer to perform initialization actions */
	if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:boot", getThis(), NULL)) {
		RETURN_MM_FALSE;
	}

	/* Deserializer Json */

	PHALCON_INIT_NVAR(service);
	ZVAL_STR(service, IS(request));
	
	PHALCON_CALL_METHOD(&request, dependency_injector, "getshared", service);
	PHALCON_VERIFY_INTERFACE(request, phalcon_http_requestinterface_ce);

	PHALCON_CALL_METHOD(&json, request, "getrawbody");
	PHALCON_CALL_FUNCTION(&data, "json_decode", json, &PHALCON_GLOBAL(z_true));


	PHALCON_INIT_NVAR(service);
	ZVAL_STR(service, IS(response));

	PHALCON_CALL_METHOD(&response, dependency_injector, "getshared", service);
	PHALCON_VERIFY_INTERFACE(response, phalcon_http_responseinterface_ce);

	PHALCON_INIT_VAR(jsonrpc_message);
	array_init(jsonrpc_message);
	
	PHALCON_INIT_VAR(jsonrpc_error);
	array_init(jsonrpc_error);

	if (PHALCON_IS_EMPTY(data)) {
		phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
		phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Parse error"), PH_COPY);
	} else if (Z_TYPE_P(data) != IS_ARRAY) {
		phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
		phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Parse error"), PH_COPY);
	} else if (!phalcon_array_isset_str(data, SL("jsonrpc"))) {		
			phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
			phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Invalid Request"), PH_COPY);
	} else if (!phalcon_array_isset_str(data, SL("method"))) {
			phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0);
			phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Invalid Request"), PH_COPY);
	} else {
		PHALCON_OBS_VAR(jsonrpc_method);
		phalcon_array_fetch_str(&jsonrpc_method, data, SL("method"), PH_NOISY);

		if (phalcon_array_isset_str(data, SL("params"))) {
			PHALCON_OBS_VAR(jsonrpc_params);
			phalcon_array_fetch_str(&jsonrpc_params, data, SL("params"), PH_NOISY);
		} else {
			PHALCON_INIT_VAR(jsonrpc_params);
			array_init(jsonrpc_params);
		}

		PHALCON_INIT_NVAR(service);
		ZVAL_STR(service, IS(url));
		PHALCON_CALL_METHOD(&url, dependency_injector, "getshared", service);
		PHALCON_VERIFY_INTERFACE(url, phalcon_mvc_urlinterface_ce);

		PHALCON_CALL_METHOD(&uri, url, "get", jsonrpc_method);

		PHALCON_INIT_NVAR(service);
		ZVAL_STR(service, IS(router));
		PHALCON_CALL_METHOD(&router, dependency_injector, "getshared", service);
		PHALCON_VERIFY_INTERFACE(router, phalcon_mvc_routerinterface_ce);

		/* Handle the URI pattern (if any) */
		PHALCON_CALL_METHOD(NULL, router, "handle", uri);
		
		/* Load module config */
		PHALCON_CALL_METHOD(&module_name, router, "getmodulename");

		/* Load module config */
		PHALCON_CALL_METHOD(&module_name, router, "getmodulename");
		
		/* If the router doesn't return a valid module we use the default module */
		if (!zend_is_true(module_name)) {
			module_name = phalcon_read_property(getThis(), SL("_defaultModule"), PH_NOISY);
		}
		
		/** 
		 * Process the module definition
		 */
		if (zend_is_true(module_name)) {
			if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:beforeStartModule", getThis(), module_name)) {
				RETURN_MM_FALSE;
			}

			/** 
			 * Check if the module passed by the router is registered in the modules container
			 */
			modules = phalcon_read_property(getThis(), SL("_modules"), PH_NOISY);
			if (!phalcon_array_isset_fetch(&module, modules, module_name)) {
				convert_to_string(module_name);
				zend_throw_exception_ex(phalcon_mvc_jsonrpc_exception_ce, 0, "Module %s is not registered in the jsonrpc container", Z_STRVAL_P(module_name));
				RETURN_MM();
			}
		
			/** 
			 * A module definition must be an array or an object
			 */
			if (Z_TYPE_P(module) != IS_ARRAY && Z_TYPE_P(module) != IS_OBJECT) {
				PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "Invalid module definition");
				return;
			}
		
			/* An array module definition contains a path to a module definition class */
			if (Z_TYPE_P(module) == IS_ARRAY) { 
				/* Class name used to load the module definition */
				if (phalcon_array_isset_str(module, SL("className"))) {
					PHALCON_OBS_VAR(class_name);
					phalcon_array_fetch_str(&class_name, module, SL("className"), PH_NOISY);
				} else {
					PHALCON_INIT_NVAR(class_name);
					ZVAL_STRING(class_name, "Module");
				}
		
				/* If the developer has specified a path, try to include the file */
				if (phalcon_array_isset_str(module, SL("path"))) {
		
					PHALCON_OBS_VAR(path);
					phalcon_array_fetch_str(&path, module, SL("path"), PH_NOISY);
					convert_to_string_ex(path);
					if (Z_TYPE_P(class_name) != IS_STRING || phalcon_class_exists(class_name, 0) == NULL) {
						if (phalcon_file_exists(path) == SUCCESS) {
							RETURN_MM_ON_FAILURE(phalcon_require(Z_STRVAL_P(path)));
						} else {
							zend_throw_exception_ex(phalcon_mvc_jsonrpc_exception_ce, 0, "Module definition path '%s' does not exist", Z_STRVAL_P(path));
							RETURN_MM();
						}
					}
				}
		
				PHALCON_CALL_METHOD(&module_object, dependency_injector, "get", class_name);
		
				/** 
				 * 'registerAutoloaders' and 'registerServices' are automatically called
				 */
				PHALCON_CALL_METHOD(NULL, module_object, "registerautoloaders", dependency_injector);
				PHALCON_CALL_METHOD(NULL, module_object, "registerservices", dependency_injector);
			} else if (Z_TYPE_P(module) == IS_OBJECT && instanceof_function(Z_OBJCE_P(module), zend_ce_closure)) {
				/* A module definition object, can be a Closure instance */
				PHALCON_INIT_VAR(module_params);
				array_init_size(module_params, 1);
				phalcon_array_append(module_params, dependency_injector, PH_COPY);

				PHALCON_CALL_USER_FUNC_ARRAY(&status, module, module_params);
			} else {
				PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "Invalid module definition");
				return;
			}
		
			/* Calling afterStartModule event */
			if (events_manager) {
				if (!module_object) {
					module_object = &PHALCON_GLOBAL(z_null);
				}

				phalcon_update_property_this(getThis(), SL("_moduleObject"), module_object);
				if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:afterStartModule", getThis(), module_name)) {
					RETURN_MM_FALSE;
				}
			}
		}
		
		/* We get the parameters from the router and assign them to the dispatcher */
		PHALCON_CALL_METHOD(&module_name, router, "getmodulename");
		PHALCON_CALL_METHOD(&namespace_name, router, "getnamespacename");
		PHALCON_CALL_METHOD(&controller_name, router, "getcontrollername");
		PHALCON_CALL_METHOD(&action_name, router, "getactionname");
		PHALCON_CALL_METHOD(&params, router, "getparams");
		PHALCON_CALL_METHOD(&exact, router, "isexactcontrollername");

		PHALCON_INIT_NVAR(service);
		ZVAL_STR(service, IS(dispatcher));
		
		PHALCON_CALL_METHOD(&dispatcher, dependency_injector, "getshared", service);
		PHALCON_VERIFY_INTERFACE(dispatcher, phalcon_dispatcherinterface_ce);
		
		/* Assign the values passed from the router */
		PHALCON_CALL_METHOD(NULL, dispatcher, "setmodulename", module_name);
		PHALCON_CALL_METHOD(NULL, dispatcher, "setnamespacename", namespace_name);
		PHALCON_CALL_METHOD(NULL, dispatcher, "setcontrollername", controller_name, exact);
		PHALCON_CALL_METHOD(NULL, dispatcher, "setactionname", action_name);
		PHALCON_CALL_METHOD(NULL, dispatcher, "setparams", jsonrpc_params);
		
		/* Calling beforeHandleRequest */
		RETURN_MM_ON_FAILURE(phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:beforeHandleRequest", getThis(), dispatcher));
		
		/* The dispatcher must return an object */
		PHALCON_CALL_METHOD(&controller, dispatcher, "dispatch");
		
		PHALCON_INIT_VAR(returned_response);
		
		/* Get the latest value returned by an action */
		PHALCON_CALL_METHOD(&jsonrpc_result, dispatcher, "getreturnedvalue");
	}
		
	/* Calling afterHandleRequest */
	if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:afterHandleRequest", getThis(), controller) && EG(exception)) {
		RETURN_MM();
	}
	
	phalcon_array_update_str_str(jsonrpc_message, SL("jsonrpc"), SL("2.0"), PH_COPY);

	if (PHALCON_IS_NOT_EMPTY(jsonrpc_error)) {
		phalcon_array_update_str(jsonrpc_message, SL("error"), jsonrpc_error, PH_COPY);
	}

	if (jsonrpc_result != NULL) {
		phalcon_array_update_str(jsonrpc_message, SL("result"), jsonrpc_result, PH_COPY);
	}
	
	if (phalcon_array_isset_str_fetch(&jsonrpc_id, data, SL("id"))) {
		phalcon_array_update_str(jsonrpc_message, SL("id"), jsonrpc_id, PH_COPY);
	} else {
		phalcon_array_update_str(jsonrpc_message, SL("id"), &PHALCON_GLOBAL(z_null), PH_COPY);
	}

	PHALCON_CALL_METHOD(NULL, response, "setjsoncontent", jsonrpc_message);
	

	/* Calling beforeSendResponse */
	if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:beforeSendResponse", getThis(), response) && EG(exception)) {
		RETURN_MM();
	}
	
	/* Headers are automatically sent */
	PHALCON_CALL_METHOD(NULL, response, "sendheaders");
	
	/* Cookies are automatically sent */
	PHALCON_CALL_METHOD(NULL, response, "sendcookies");
	
	/* Return the response */
	RETURN_CCTOR(response);
}
Beispiel #4
0
/**
 * Executes validator
 *
 * @param Phalcon\Mvc\ModelInterface $record
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){

	zval *record, *field = NULL, *is_set = NULL, *domain = NULL;
	zval *value = NULL, *option, *message = NULL, *joined_domain, *is_set_code = NULL, *code = NULL;
	zval *type;
	zval *allow_empty = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &record);
	
	PHALCON_INIT_VAR(option);
	ZVAL_STRING(option, "field", 1);
	
	PHALCON_CALL_METHOD(&field, this_ptr, "getoption", option);
	if (Z_TYPE_P(field) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string");
		return;
	}
	
	/** 
	 * The 'domain' option must be a valid array of not allowed values
	 */
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "domain", 1);
	
	PHALCON_CALL_METHOD(&is_set, this_ptr, "issetoption", option);
	if (PHALCON_IS_FALSE(is_set)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator");
		return;
	}
	
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "domain", 1);
	
	PHALCON_CALL_METHOD(&domain, this_ptr, "getoption", option);
	if (Z_TYPE_P(domain) != IS_ARRAY) { 
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array");
		return;
	}
	
	PHALCON_CALL_METHOD(&value, record, "readattribute", field);

	/*
	 * Allow empty
	 */
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "allowEmpty", 1);

	PHALCON_CALL_METHOD(&allow_empty, this_ptr, "getoption", option);
	if (allow_empty && zend_is_true(allow_empty) && PHALCON_IS_EMPTY(value)) {
		RETURN_MM_TRUE;
	}
	
	/** 
	 * Check if the value is contained in the array
	 */
	if (!phalcon_fast_in_array(value, domain TSRMLS_CC)) {
	
		/** 
		 * Check if the developer has defined a custom message
		 */
		PHALCON_INIT_NVAR(option);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_message);
	
		PHALCON_CALL_METHOD(&message, this_ptr, "getoption", option);
		if (!zend_is_true(message)) {
			PHALCON_INIT_VAR(joined_domain);
			phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC);
	
			PHALCON_INIT_NVAR(message);
			PHALCON_CONCAT_SVSV(message, "Value of field '", field, "' must be part of list: ", joined_domain);
		}
	
		PHALCON_INIT_VAR(type);
		ZVAL_STRING(type, "Inclusion", 1);

		/*
		 * Is code set
		 */
		PHALCON_INIT_NVAR(option);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_code);

		PHALCON_CALL_METHOD(&is_set_code, this_ptr, "issetoption", option);
		if (zend_is_true(is_set_code)) {
			PHALCON_CALL_METHOD(&code, this_ptr, "getoption", option);
		} else {
			PHALCON_INIT_VAR(code);
			ZVAL_LONG(code, 0);
		}

		PHALCON_CALL_METHOD(NULL, this_ptr, "appendmessage", message, field, type, code);
		RETURN_MM_FALSE;
	}
	
	RETURN_MM_TRUE;
}
Beispiel #5
0
/**
 * Encrypts a text
 *
 *<code>
 *	$encrypted = $crypt->encrypt("Ultra-secret text", "encrypt password");
 *</code>
 *
 * @param string $text
 * @param string $key
 * @param int $option
 * @return string
 */
PHP_METHOD(Phalcon_Crypt, encrypt){

	zval *source, *key = NULL, *options = NULL, handler = {}, arguments = {}, value = {}, text = {}, encrypt_key = {}, encrypt_options = {};
	zval method = {}, iv_size = {}, iv = {}, encrypt = {};

	phalcon_fetch_params(0, 1, 2, &source, &key, &options);

	if (phalcon_function_exists_ex(SL("openssl_decrypt")) == FAILURE) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_crypt_exception_ce, "openssl extension is required");
		return;
	}

	phalcon_read_property(&handler, getThis(), SL("_beforeEncrypt"), PH_NOISY);

	if (phalcon_is_callable(&handler)) {
		PHALCON_SEPARATE_PARAM(source);

		array_init_size(&arguments, 1);
		phalcon_array_append(&arguments, source, PH_COPY);

		PHALCON_CALL_USER_FUNC_ARRAYW(&value, &handler, &arguments);

		source = &value;
	}

	/* Do not use make_printable_zval() here: we need the conversion with type juggling */
	if (Z_TYPE_P(source) != IS_STRING) {
		phalcon_cast(&text, source, IS_STRING);
	} else {
		PHALCON_CPY_WRT_CTOR(&text, source);
	}

	if (!key || Z_TYPE_P(key) == IS_NULL) {
		phalcon_return_property(&encrypt_key, getThis(), SL("_key"));
	} else {
		PHALCON_CPY_WRT_CTOR(&encrypt_key, key);
		if (Z_TYPE(encrypt_key) != IS_STRING) {
			convert_to_string(&encrypt_key);
		}
	}

	if (PHALCON_IS_EMPTY(&encrypt_key)) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_crypt_exception_ce, "Encryption key cannot be empty");
		return;
	}

	if (!options || Z_TYPE_P(options) == IS_NULL) {
		phalcon_return_property(&encrypt_options, getThis(), SL("_options"));
	} else {
		PHALCON_CPY_WRT_CTOR(&encrypt_options, options);
	}

	phalcon_read_property(&method, getThis(), SL("_method"), PH_NOISY);

	PHALCON_CALL_FUNCTIONW(&iv_size, "openssl_cipher_iv_length", &method);
	PHALCON_CALL_FUNCTIONW(&iv, "openssl_random_pseudo_bytes", &iv_size);
	PHALCON_CALL_FUNCTIONW(&encrypt, "openssl_encrypt", &text, &method, &encrypt_key, &encrypt_options, &iv);
	PHALCON_CONCAT_VV(return_value, &iv, &encrypt);

	phalcon_read_property(&handler, getThis(), SL("_afterEncrypt"), PH_NOISY);

	if (phalcon_is_callable(&handler)) {
		array_init_size(&arguments, 1);
		phalcon_array_append(&arguments, return_value, PH_COPY);

		PHALCON_CALL_USER_FUNC_ARRAYW(&value, &handler, &arguments);

		RETURN_CTORW(&value);
	}
}
Beispiel #6
0
/**
 * Executes the validator
 *
 * @param Phalcon\Mvc\ModelInterface $record
 * @return boolean
 */
PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){

	zval *record, *option = NULL, *field = NULL, *value = NULL, *message = NULL;
	zval *type, *is_set_code = NULL, *code = NULL;
	zval *allow_empty = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &record);
	
	PHALCON_INIT_VAR(option);
	ZVAL_STRING(option, "field", 1);
	
	PHALCON_CALL_METHOD(&field, this_ptr, "getoption", option);
	if (Z_TYPE_P(field) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string");
		return;
	}
	
	PHALCON_CALL_METHOD(&value, record, "readattribute", field);

	/*
	 * Allow empty
	 */
	PHALCON_INIT_NVAR(option);
	ZVAL_STRING(option, "allowEmpty", 1);

	PHALCON_CALL_METHOD(&allow_empty, this_ptr, "getoption", option);
	if (allow_empty && zend_is_true(allow_empty) && PHALCON_IS_EMPTY(value)) {
		RETURN_MM_TRUE;
	}
	
	/** 
	 * Check if the value is numeric using is_numeric in the PHP userland
	 */
	if (!phalcon_is_numeric(value)) {
	
		/** 
		 * Check if the developer has defined a custom message
		 */
		PHALCON_INIT_NVAR(option);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_message);
	
		PHALCON_CALL_METHOD(&message, this_ptr, "getoption", option);
		if (!zend_is_true(message)) {
			PHALCON_INIT_NVAR(message);
			PHALCON_CONCAT_SVS(message, "Value of field '", field, "' must be numeric");
		}
	
		PHALCON_INIT_VAR(type);
		ZVAL_STRING(type, "Numericality", 1);

		/*
		 * Is code set
		 */
		PHALCON_INIT_NVAR(option);
		PHALCON_ZVAL_MAYBE_INTERNED_STRING(option, phalcon_interned_code);

		PHALCON_CALL_METHOD(&is_set_code, this_ptr, "issetoption", option);
		if (zend_is_true(is_set_code)) {
			PHALCON_CALL_METHOD(&code, this_ptr, "getoption", option);
		} else {
			PHALCON_INIT_VAR(code);
			ZVAL_LONG(code, 0);
		}

		PHALCON_CALL_METHOD(NULL, this_ptr, "appendmessage", message, field, type, code);
		RETURN_MM_FALSE;
	}
	
	RETURN_MM_TRUE;
}
Beispiel #7
0
/**
 * Traverses a collection calling the callback to generate its HTML
 *
 * @param Phalcon\Assets\Collection $collection
 * @param callback $callback
 * @param string $type
 */
PHP_METHOD(Phalcon_Assets_Manager, output){

	zval *collection, *callback, *type = NULL, *output, *use_implicit_output;
	zval *resources = NULL, *filters = NULL, *prefix = NULL, *source_base_path = NULL;
	zval *target_base_path = NULL, *options, *collection_source_path = NULL;
	zval *complete_source_path = NULL, *collection_target_path = NULL;
	zval *complete_target_path = NULL, *filtered_joined_content = NULL;
	zval *join = NULL, *exception_message = NULL, *is_directory;
	zval *resource = NULL, *filter_needed = NULL, *local = NULL, *source_path = NULL;
	zval *target_path = NULL, *path = NULL, *prefixed_path = NULL, *attributes = NULL;
	zval *parameters = NULL, *html = NULL, *content = NULL, *must_filter = NULL;
	zval *filter = NULL, *filtered_content = NULL, *target_uri = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	zval *type_css;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 1, &collection, &callback, &type);
	
	PHALCON_INIT_VAR(output);
	
	PHALCON_OBS_VAR(use_implicit_output);
	phalcon_read_property_this(&use_implicit_output, this_ptr, SL("_implicitOutput"), PH_NOISY TSRMLS_CC);
	
	/** 
	 * Get the resources as an array
	 */
	PHALCON_CALL_METHOD(&resources, collection, "getresources");
	
	/** 
	 * Get filters in the collection
	 */
	PHALCON_CALL_METHOD(&filters, collection, "getfilters");
	
	/** 
	 * Get the collection's prefix
	 */
	PHALCON_CALL_METHOD(&prefix, collection, "getprefix");

	PHALCON_INIT_VAR(type_css);
	ZVAL_STRING(type_css, "css", 1);
	
	/** 
	 * Prepare options if the collection must be filtered
	 */
	if (Z_TYPE_P(filters) == IS_ARRAY) { 
	
		PHALCON_INIT_VAR(source_base_path);
	
		PHALCON_INIT_VAR(target_base_path);
	
		PHALCON_OBS_VAR(options);
		phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY TSRMLS_CC);
	
		/** 
		 * Check for global options in the assets manager
		 */
		if (Z_TYPE_P(options) == IS_ARRAY) { 
	
			/** 
			 * The source base path is a global location where all resources are located
			 */
			if (phalcon_array_isset_string(options, SS("sourceBasePath"))) {
				PHALCON_OBS_NVAR(source_base_path);
				phalcon_array_fetch_string(&source_base_path, options, SL("sourceBasePath"), PH_NOISY);
			}
	
			/** 
			 * The target base path is a global location where all resources are written
			 */
			if (phalcon_array_isset_string(options, SS("targetBasePath"))) {
				PHALCON_OBS_NVAR(target_base_path);
				phalcon_array_fetch_string(&target_base_path, options, SL("targetBasePath"), PH_NOISY);
			}
		}
	
		/** 
		 * Check if the collection have its own source base path
		 */
		PHALCON_CALL_METHOD(&collection_source_path, collection, "getsourcepath");
	
		/** 
		 * Concatenate the global base source path with the collection one
		 */
		if (PHALCON_IS_NOT_EMPTY(collection_source_path)) {
			PHALCON_INIT_VAR(complete_source_path);
			PHALCON_CONCAT_VV(complete_source_path, source_base_path, collection_source_path);
		} else {
			PHALCON_CPY_WRT(complete_source_path, source_base_path);
		}
	
		/** 
		 * Check if the collection have its own target base path
		 */
		PHALCON_CALL_METHOD(&collection_target_path, collection, "gettargetpath");
	
		/** 
		 * Concatenate the global base source path with the collection one
		 */
		if (PHALCON_IS_NOT_EMPTY(collection_target_path)) {
			PHALCON_INIT_VAR(complete_target_path);
			PHALCON_CONCAT_VV(complete_target_path, target_base_path, collection_target_path);
		} else {
			PHALCON_CPY_WRT(complete_target_path, target_base_path);
		}
	
		/** 
		 * Global filtered content
		 */
		PHALCON_INIT_VAR(filtered_joined_content);
	
		/** 
		 * Check if all the resources in the collection must be joined
		 */
		PHALCON_CALL_METHOD(&join, collection, "getjoin");
	
		/** 
		 * Check for valid target paths if the collection must be joined
		 */
		if (zend_is_true(join)) {
	
			/** 
			 * We need a valid final target path
			 */
			if (PHALCON_IS_EMPTY(complete_target_path)) {
				PHALCON_INIT_VAR(exception_message);
				PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (1)");
				PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
				return;
			}
	
			PHALCON_INIT_VAR(is_directory);
			phalcon_is_dir(is_directory, complete_target_path TSRMLS_CC);
	
			/** 
			 * The targetpath needs to be a valid file
			 */
			if (PHALCON_IS_TRUE(is_directory)) {
				PHALCON_INIT_NVAR(exception_message);
				PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (2)");
				PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
				return;
			}
		}
	}
	
	phalcon_is_iterable(resources, &ah0, &hp0, 0, 0);
	
	while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
		PHALCON_GET_HVALUE(resource);
	
		PHALCON_INIT_NVAR(filter_needed);
		ZVAL_FALSE(filter_needed);

		if (!type) {
			PHALCON_CALL_METHOD(&type, resource, "gettype");
		}

		/** 
		 * Is the resource local?
		 */
		PHALCON_CALL_METHOD(&local, resource, "getlocal");
	
		/** 
		 * If the collection must not be joined we must print a HTML for each one
		 */
		if (Z_TYPE_P(filters) == IS_ARRAY) { 
			if (zend_is_true(local)) {

				/** 
				 * Get the complete path
				 */
				PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path);

				/** 
				 * We need a valid source path
				 */
				if (!zend_is_true(source_path)) {
					PHALCON_CALL_METHOD(&source_path, resource, "getpath");

					PHALCON_INIT_NVAR(exception_message);
					PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path");
					PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
					return;
				}
			} else {
				/** 
				 * Get the complete source path
				 */
				PHALCON_CALL_METHOD(&source_path, resource, "getpath");

				/** 
				 * resources paths are always filtered
				 */
				PHALCON_INIT_NVAR(filter_needed);
				ZVAL_TRUE(filter_needed);
			}

			/** 
			 * Get the target path, we need to write the filtered content to a file
			 */
			PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path);

			/** 
			 * We need a valid final target path
			 */
			if (PHALCON_IS_EMPTY(target_path)) {
				PHALCON_INIT_NVAR(exception_message);
				PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path");
				PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
				return;
			}

			if (zend_is_true(local)) {

				/** 
				 * Make sure the target path is not the same source path
				 */
				if (PHALCON_IS_EQUAL(target_path, source_path)) {
					PHALCON_INIT_NVAR(exception_message);
					PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths");
					PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message);
					return;
				}
				if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) {
					if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) {
						PHALCON_INIT_NVAR(filter_needed);
						ZVAL_TRUE(filter_needed);
					}
				} else {
					PHALCON_INIT_NVAR(filter_needed);
					ZVAL_TRUE(filter_needed);
				}
			}
		}
	
		/** 
		 * If there are no filters, just print/buffer the HTML
		 */
		if (Z_TYPE_P(filters) != IS_ARRAY) { 
			PHALCON_CALL_METHOD(&path, resource, "getrealtargeturi");
			if (Z_TYPE_P(prefix) != IS_NULL) {
				PHALCON_INIT_NVAR(prefixed_path);
				PHALCON_CONCAT_VV(prefixed_path, prefix, path);
			} else {
				PHALCON_CPY_WRT(prefixed_path, path);
			}
	
			/** 
			 * Gets extra HTML attributes in the resource
			 */
			PHALCON_CALL_METHOD(&attributes, resource, "getattributes");
	
			/** 
			 * Prepare the parameters for the callback
			 */
			PHALCON_INIT_NVAR(parameters);
			array_init_size(parameters, 2);
			if (Z_TYPE_P(attributes) == IS_ARRAY) { 
				phalcon_array_update_long(&attributes, 0, prefixed_path, PH_COPY | PH_SEPARATE);
	
				phalcon_array_append(&parameters, attributes, 0);
			} else {
				phalcon_array_append(&parameters, prefixed_path, 0);
			}

			phalcon_array_append(&parameters, local, 0);
	
			/** 
			 * Call the callback to generate the HTML
			 */
			PHALCON_INIT_NVAR(html);/**/
			PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters);
	
			/** 
			 * Implicit output prints the content directly
			 */
			if (zend_is_true(use_implicit_output)) {
				zend_print_zval(html, 0);
			} else {
				phalcon_concat_self(&output, html TSRMLS_CC);
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
			continue;
		}
	
		if (zend_is_true(filter_needed)) {
	
			/** 
			 * Get the resource's content
			 */
			PHALCON_CALL_METHOD(&content, resource, "getcontent", complete_source_path);
	
			/** 
			 * Check if the resource must be filtered
			 */
			PHALCON_CALL_METHOD(&must_filter, resource, "getfilter");
	
			/** 
			 * Only filter the resource if it's marked as 'filterable'
			 */
			if (zend_is_true(must_filter)) {
	
				phalcon_is_iterable(filters, &ah1, &hp1, 0, 0);
	
				while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) {
	
					PHALCON_GET_HVALUE(filter);
	
					/** 
					 * Filters must be valid objects
					 */
					if (Z_TYPE_P(filter) != IS_OBJECT) {
						PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Filter is invalid");
						return;
					}
	
					/** 
					 * Calls the method 'filter' which must return a filtered version of the content
					 */
					PHALCON_CALL_METHOD(&filtered_content, filter, "filter", content);
					PHALCON_CPY_WRT_CTOR(content, filtered_content);

					zend_hash_move_forward_ex(ah1, &hp1);
				}

				/**
				 * Update the joined filtered content
				 */
				if (zend_is_true(join)) {
					if (PHALCON_IS_EQUAL(type, type_css)) {
						if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
							PHALCON_INIT_NVAR(filtered_joined_content);
							PHALCON_CONCAT_VS(filtered_joined_content, content, "");
						} else {
							PHALCON_SCONCAT_VS(filtered_joined_content, content, "");
						}
					} else {
						if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
							PHALCON_INIT_NVAR(filtered_joined_content);
							PHALCON_CONCAT_VS(filtered_joined_content, content, ";");
						} else {
							PHALCON_SCONCAT_VS(filtered_joined_content, content, ";");
						}
					}
				}

			} else {
				/** 
				 * Update the joined filtered content
				 */
				if (zend_is_true(join)) {
					if (Z_TYPE_P(filtered_joined_content) == IS_NULL) {
						PHALCON_CPY_WRT(filtered_joined_content, content);
					} else {
						phalcon_concat_self(&filtered_joined_content, content TSRMLS_CC);
					}
				} else {
					PHALCON_CPY_WRT(filtered_content, content);
				}
			}
	
			if (!zend_is_true(join)) {
				/** 
				 * Write the file using file-put-contents. This respects the openbase-dir also
				 * writes to streams
				 */
				phalcon_file_put_contents(NULL, target_path, filtered_content TSRMLS_CC);
			}
		}
	
		if (!zend_is_true(join)) {
	
			/** 
			 * Generate the HTML using the original path in the resource
			 */
			PHALCON_CALL_METHOD(&path, resource, "getrealtargeturi");
			if (Z_TYPE_P(prefix) != IS_NULL) {
				PHALCON_INIT_NVAR(prefixed_path);
				PHALCON_CONCAT_VV(prefixed_path, prefix, path);
			} else {
				PHALCON_CPY_WRT(prefixed_path, path);
			}
	
			/** 
			 * Gets extra HTML attributes in the resource
			 */
			PHALCON_CALL_METHOD(&attributes, resource, "getattributes");
	
			/** 
			 * Filtered resources are always local
			 */
			PHALCON_INIT_NVAR(local);
			ZVAL_TRUE(local);
	
			/** 
			 * Prepare the parameters for the callback
			 */
			PHALCON_INIT_NVAR(parameters);
			array_init_size(parameters, 2);
			if (Z_TYPE_P(attributes) == IS_ARRAY) { 
				phalcon_array_update_long(&attributes, 0, prefixed_path, PH_COPY | PH_SEPARATE);
	
				phalcon_array_append(&parameters, attributes, 0);
			} else {
				phalcon_array_append(&parameters, prefixed_path, 0);
			}

			phalcon_array_append(&parameters, local, 0);

			/** 
			 * Call the callback to generate the HTML
			 */
			PHALCON_INIT_NVAR(html);/**/
			PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters);
	
			/** 
			 * Implicit output prints the content directly
			 */
			if (zend_is_true(use_implicit_output)) {
				zend_print_zval(html, 0);
			} else {
				phalcon_concat_self(&output, html TSRMLS_CC);
			}
		}
	
		zend_hash_move_forward_ex(ah0, &hp0);
	}
	
	if (Z_TYPE_P(filters) == IS_ARRAY) { 
		if (zend_is_true(join)) {
	
			/** 
			 * Write the file using file_put_contents. This respects the openbase-dir also
			 * writes to streams
			 */
			phalcon_file_put_contents(NULL, complete_target_path, filtered_joined_content TSRMLS_CC);
	
			/** 
			 * Generate the HTML using the original path in the resource
			 */
			PHALCON_CALL_METHOD(&target_uri, collection, "gettargeturi");
			if (Z_TYPE_P(prefix) != IS_NULL) {
				PHALCON_INIT_NVAR(prefixed_path);
				PHALCON_CONCAT_VV(prefixed_path, prefix, target_uri);
			} else {
				PHALCON_CPY_WRT(prefixed_path, target_uri);
			}
	
			/** 
			 * Gets extra HTML attributes in the resource
			 */
			PHALCON_CALL_METHOD(&attributes, collection, "getattributes");
			PHALCON_CALL_METHOD(&local, collection, "gettargetlocal");
	
			/** 
			 * Prepare the parameters for the callback
			 */
			PHALCON_INIT_NVAR(parameters);
			array_init_size(parameters, 2);
			if (Z_TYPE_P(attributes) == IS_ARRAY) { 
				phalcon_array_update_long(&attributes, 0, prefixed_path, PH_COPY | PH_SEPARATE);
	
				phalcon_array_append(&parameters, attributes, 0);
			} else {
				phalcon_array_append(&parameters, prefixed_path, 0);
			}

			phalcon_array_append(&parameters, local, 0);

			/** 
			 * Call the callback to generate the HTML
			 */
			PHALCON_INIT_NVAR(html);/**/
			PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters);
	
			/** 
			 * Implicit output prints the content directly
			 */
			if (zend_is_true(use_implicit_output)) {
				zend_print_zval(html, 0);
			} else {
				phalcon_concat_self(&output, html TSRMLS_CC);
			}
		}
	}
	
	RETURN_CCTOR(output);
}