Example #1
0
/**
 * Sets a Expires header to use HTTP cache
 *
 *<code>
 *	$this->response->setExpires(new DateTime());
 *</code>
 *
 * @param DateTime $datetime
 * @return Phalcon\Http\ResponseInterface
 */
PHP_METHOD(Phalcon_Http_Response, setExpires){

	zval *datetime, *headers, *date, *utc_zone, *timezone;
	zval *format, *utc_format, *utc_date, *expires_header;
	zend_class_entry *ce0;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 0, &datetime);
	
	if (Z_TYPE_P(datetime) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "datetime parameter must be an instance of DateTime");
		return;
	}
	
	PHALCON_INIT_VAR(headers);
	phalcon_call_method(headers, this_ptr, "getheaders");
	
	PHALCON_INIT_VAR(date);
	if (phalcon_clone(date, datetime TSRMLS_CC) == FAILURE) {
		return;
	}
	
	/** 
	 * All the expiration times are sent in UTC
	 */
	PHALCON_INIT_VAR(utc_zone);
	ZVAL_STRING(utc_zone, "UTC", 1);
	ce0 = zend_fetch_class(SL("DateTimeZone"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
	
	PHALCON_INIT_VAR(timezone);
	object_init_ex(timezone, ce0);
	if (phalcon_has_constructor(timezone TSRMLS_CC)) {
		phalcon_call_method_p1_noret(timezone, "__construct", utc_zone);
	}
	
	/** 
	 * Change the timezone to utc
	 */
	phalcon_call_method_p1_noret(date, "settimezone", timezone);
	
	PHALCON_INIT_VAR(format);
	ZVAL_STRING(format, "D, d M Y H:i:s", 1);
	
	PHALCON_INIT_VAR(utc_format);
	phalcon_call_method_p1(utc_format, date, "format", format);
	
	PHALCON_INIT_VAR(utc_date);
	PHALCON_CONCAT_VS(utc_date, utc_format, " GMT");
	
	/** 
	 * The 'Expires' header set this info
	 */
	PHALCON_INIT_VAR(expires_header);
	ZVAL_STRING(expires_header, "Expires", 1);
	phalcon_call_method_p2_noret(this_ptr, "setheader", expires_header, utc_date);
	
	RETURN_THIS();
}
Example #2
0
/**
 * Executes the validator
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Model_Validator_Uniqueness, validate){

	zval *record = NULL, *field = NULL, *conditions = NULL, *compose_field = NULL;
	zval *value = NULL, *manager = NULL, *meta_data = NULL, *primary_fields = NULL;
	zval *primary_field = NULL, *options = NULL;
	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL;
	zval *i0 = NULL;
	zval *a0 = NULL;
	zval *c0 = NULL, *c1 = NULL, *c2 = NULL;
	zval *t0 = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_CALL_METHOD(r0, this_ptr, "isrequired", PHALCON_NO_CHECK);
	if (zend_is_true(r0)) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		PHALCON_CALL_METHOD(r1, this_ptr, "getrecord", PHALCON_NO_CHECK);
		PHALCON_ALLOC_ZVAL_MM(i0);
		if (phalcon_clone(i0, r1 TSRMLS_CC) == FAILURE){
			return;
		}
		PHALCON_CPY_WRT(record, i0);
		
		PHALCON_ALLOC_ZVAL_MM(r2);
		PHALCON_CALL_METHOD(r2, this_ptr, "getfieldname", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(field, r2);
		
		PHALCON_INIT_VAR(a0);
		array_init(a0);
		PHALCON_CPY_WRT(conditions, a0);
		if (Z_TYPE_P(field) == IS_ARRAY) { 
			if (phalcon_valid_foreach(field TSRMLS_CC)) {
				ah0 = Z_ARRVAL_P(field);
				zend_hash_internal_pointer_reset_ex(ah0, &hp0);
				fes_d73d_0:
				if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
					goto fee_d73d_0;
				}
				PHALCON_INIT_VAR(compose_field);
				ZVAL_ZVAL(compose_field, *hd, 1, 0);
				PHALCON_INIT_VAR(r3);
				PHALCON_INIT_VAR(r4);
				PHALCON_CALL_METHOD_PARAMS_1(r4, record, "readattribute", compose_field, PHALCON_NO_CHECK);
				PHALCON_CALL_FUNC_PARAMS_1(r3, "addslashes", r4, 0x00F);
				PHALCON_CPY_WRT(value, r3);
				
				PHALCON_INIT_VAR(r5);
				PHALCON_CONCAT_VSVS(r5, compose_field, "='", value, "'");
				phalcon_array_append(&conditions, r5, PHALCON_SEPARATE_PLZ TSRMLS_CC);
				zend_hash_move_forward_ex(ah0, &hp0);
				goto fes_d73d_0;
				fee_d73d_0:
				if(0){}
			} else {
				return;
			}
		} else {
			PHALCON_ALLOC_ZVAL_MM(r6);
			PHALCON_ALLOC_ZVAL_MM(r7);
			PHALCON_CALL_METHOD(r7, this_ptr, "getvalue", PHALCON_NO_CHECK);
			PHALCON_CALL_FUNC_PARAMS_1(r6, "addslashes", r7, 0x00F);
			PHALCON_CPY_WRT(value, r6);
			
			PHALCON_ALLOC_ZVAL_MM(r8);
			PHALCON_CONCAT_VSVS(r8, field, "='", value, "'");
			phalcon_array_append(&conditions, r8, PHALCON_SEPARATE_PLZ TSRMLS_CC);
		}
		
		PHALCON_ALLOC_ZVAL_MM(r9);
		PHALCON_CALL_METHOD(r9, record, "getmanager", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(manager, r9);
		
		PHALCON_ALLOC_ZVAL_MM(r10);
		PHALCON_CALL_METHOD(r10, manager, "getmetadata", PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(meta_data, r10);
		
		PHALCON_ALLOC_ZVAL_MM(r11);
		PHALCON_CALL_METHOD_PARAMS_1(r11, meta_data, "getprimarykeyattributes", record, PHALCON_NO_CHECK);
		PHALCON_CPY_WRT(primary_fields, r11);
		if (phalcon_valid_foreach(primary_fields TSRMLS_CC)) {
			ah1 = Z_ARRVAL_P(primary_fields);
			zend_hash_internal_pointer_reset_ex(ah1, &hp1);
			fes_d73d_1:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_d73d_1;
			}
			
			PHALCON_INIT_VAR(primary_field);
			ZVAL_ZVAL(primary_field, *hd, 1, 0);
			PHALCON_INIT_VAR(r12);
			PHALCON_INIT_VAR(r13);
			PHALCON_INIT_VAR(r14);
			PHALCON_CALL_METHOD_PARAMS_1(r14, record, "readattribute", primary_field, PHALCON_NO_CHECK);
			PHALCON_CALL_FUNC_PARAMS_1(r13, "addslashes", r14, 0x00F);
			PHALCON_CONCAT_VSVS(r12, primary_field, "<>'", r13, "'");
			phalcon_array_append(&conditions, r12, PHALCON_SEPARATE_PLZ TSRMLS_CC);
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_d73d_1;
			fee_d73d_1:
			if(0){}
		} else {
			return;
		}
		
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, " AND ", 1);
		
		PHALCON_ALLOC_ZVAL_MM(r15);
		phalcon_fast_join(r15, c0, conditions TSRMLS_CC);
		PHALCON_CPY_WRT(conditions, r15);
		
		PHALCON_ALLOC_ZVAL_MM(r16);
		PHALCON_CALL_STATIC_ZVAL_PARAMS_1(r16, record, "count", conditions);
		
		PHALCON_INIT_VAR(t0);
		ZVAL_LONG(t0, 0);
		
		PHALCON_INIT_VAR(r17);
		is_smaller_function(r17, t0, r16 TSRMLS_CC);
		if (zend_is_true(r17)) {
			PHALCON_ALLOC_ZVAL_MM(r18);
			PHALCON_CALL_METHOD(r18, this_ptr, "getoptions", PHALCON_NO_CHECK);
			PHALCON_CPY_WRT(options, r18);
			eval_int = phalcon_array_isset_string(options, "message", strlen("message")+1);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(r19);
				phalcon_array_fetch_string(&r19, options, "message", strlen("message"), PHALCON_NOISY TSRMLS_CC);
				PHALCON_INIT_VAR(c1);
				ZVAL_STRING(c1, "unique", 1);
				PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "appendmessage", r19, field, c1, PHALCON_NO_CHECK);
			} else {
				PHALCON_ALLOC_ZVAL_MM(r20);
				PHALCON_CONCAT_SVS(r20, "Value of field '", field, "' is already present in another record");
				PHALCON_INIT_VAR(c2);
				ZVAL_STRING(c2, "unique", 1);
				PHALCON_CALL_METHOD_PARAMS_3_NORETURN(this_ptr, "appendmessage", r20, field, c2, PHALCON_NO_CHECK);
			}
			
			PHALCON_MM_RESTORE();
			RETURN_FALSE;
		}
	}
	PHALCON_MM_RESTORE();
	RETURN_TRUE;
}
Example #3
0
/**
 * Listens for notifications from the models manager
 *
 * @param string $type
 * @param Phalcon\Mvc\ModelInterface $model
 */
PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){

	zval *type, *model, *options, *skip, *value, *field, *actual_value;
	zval *update_model, *status, *messages, *message = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &type, &model);
	
	if (PHALCON_IS_STRING(type, "beforeDelete")) {
	
		PHALCON_INIT_VAR(options);
		phalcon_call_method(options, this_ptr, "getoptions");
		if (!phalcon_array_isset_string(options, SS("value"))) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'value' is required");
			return;
		}
	
		if (!phalcon_array_isset_string(options, SS("field"))) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required");
			return;
		}
	
		PHALCON_INIT_VAR(skip);
		ZVAL_BOOL(skip, 1);
	
		/** 
		 * Skip the current operation
		 */
		phalcon_call_method_p1_noret(model, "skipoperation", skip);
	
		/** 
		 * 'value' is the value to be updated instead of delete the record
		 */
		PHALCON_OBS_VAR(value);
		phalcon_array_fetch_string(&value, options, SL("value"), PH_NOISY_CC);
	
		/** 
		 * 'field' is the attribute to be updated instead of delete the record
		 */
		PHALCON_OBS_VAR(field);
		phalcon_array_fetch_string(&field, options, SL("field"), PH_NOISY_CC);
	
		PHALCON_INIT_VAR(actual_value);
		phalcon_call_method_p1(actual_value, model, "readattribute", field);
	
		/** 
		 * If the record is already flagged as 'deleted' we don't delete it again
		 */
		if (!PHALCON_IS_EQUAL(actual_value, value)) {
	
			/** 
			 * Clone the current model to make a clean new operation
			 */
			PHALCON_INIT_VAR(update_model);
			if (phalcon_clone(update_model, model TSRMLS_CC) == FAILURE) {
				return;
			}
			phalcon_call_method_p2_noret(update_model, "writeattribute", field, value);
	
			/** 
			 * Update the cloned model
			 */
			PHALCON_INIT_VAR(status);
			phalcon_call_method(status, update_model, "save");
			if (!zend_is_true(status)) {
	
				/** 
				 * Transfer the messages from the cloned model to the original model
				 */
				PHALCON_INIT_VAR(messages);
				phalcon_call_method(messages, update_model, "getmessages");
	
				phalcon_is_iterable(messages, &ah0, &hp0, 0, 0);
	
				while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
					PHALCON_GET_HVALUE(message);
	
					phalcon_call_method_p1_noret(model, "appendmessage", message);
	
					zend_hash_move_forward_ex(ah0, &hp0);
				}
	
				RETURN_MM_FALSE;
			}
	
			/** 
			 * Update the original model too
			 */
			phalcon_call_method_p2_noret(model, "writeattribute", field, value);
		}
	}
	
	PHALCON_MM_RESTORE();
}
Example #4
0
/**
 * Executes the validator
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Model_Validator_Uniqueness, validate){

	zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL;
	zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL;
	zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL, *r18 = NULL, *r19 = NULL, *r20 = NULL;
	zval *r21 = NULL, *r22 = NULL, *r23 = NULL;
	zval *v0 = NULL, *v1 = NULL, *v2 = NULL, *v3 = NULL, *v4 = NULL, *v5 = NULL, *v6 = NULL;
	zval *v7 = NULL, *v8 = NULL, *v9 = NULL;
	zval *i0 = NULL;
	zval *a0 = NULL;
	zval *c0 = NULL;
	zval *t0 = NULL;
	zval *p4[] = { NULL }, *p9[] = { NULL }, *p11[] = { NULL }, *p13[] = { NULL }, *p15[] = { NULL, NULL, NULL }, *p16[] = { NULL, NULL, NULL };
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	int eval_int;

	PHALCON_MM_GROW();
	PHALCON_ALLOC_ZVAL_MM(r0);
	PHALCON_CALL_METHOD(r0, this_ptr, "isrequired", PHALCON_CALL_DEFAULT);
	if (zend_is_true(r0)) {
		PHALCON_ALLOC_ZVAL_MM(r1);
		PHALCON_CALL_METHOD(r1, this_ptr, "getrecord", PHALCON_CALL_DEFAULT);
		PHALCON_ALLOC_ZVAL_MM(i0);
		phalcon_clone(i0, r1 TSRMLS_CC);
		PHALCON_CPY_WRT(v0, i0);
		PHALCON_ALLOC_ZVAL_MM(r2);
		PHALCON_CALL_METHOD(r2, this_ptr, "getfieldname", PHALCON_CALL_DEFAULT);
		PHALCON_CPY_WRT(v1, r2);
		PHALCON_INIT_VAR(a0);
		array_init(a0);
		PHALCON_CPY_WRT(v2, a0);
		if (Z_TYPE_P(v1) == IS_ARRAY) { 
			if (Z_TYPE_P(v1) != IS_ARRAY) {
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument supplied for foreach()");
			} else {
				ah0 = Z_ARRVAL_P(v1);
				zend_hash_internal_pointer_reset_ex(ah0, &hp0);
				fes_d73d_0:
				if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
					goto fee_d73d_0;
				}
				PHALCON_INIT_VAR(v3);
				ZVAL_ZVAL(v3, *hd, 1, 0);
				PHALCON_INIT_VAR(r3);
				PHALCON_INIT_VAR(r4);
				Z_ADDREF_P(v3);
				p4[0] = v3;
				PHALCON_CALL_METHOD_PARAMS(r4, v0, "readattribute", 1, p4, PHALCON_CALL_DEFAULT);
				Z_DELREF_P(p4[0]);
				Z_ADDREF_P(r4);
				PHALCON_CALL_FUNC_PARAMS_1(r3, "addslashes", r4, 0x01F);
				Z_DELREF_P(r4);
				PHALCON_CPY_WRT(v4, r3);
				PHALCON_INIT_VAR(r5);
				PHALCON_CONCAT_VBOTH(r5, v3, "='", v4);
				PHALCON_INIT_VAR(r6);
				PHALCON_CONCAT_RIGHT(r6, r5, "'");
				Z_ADDREF_P(r6);
				PHALCON_SEPARATE_ARRAY(v2);
				phalcon_array_append(v2, r6 TSRMLS_CC);
				zend_hash_move_forward_ex(ah0, &hp0);
				goto fes_d73d_0;
				fee_d73d_0:
				if(0){ };
			}
		} else {
			PHALCON_ALLOC_ZVAL_MM(r7);
			PHALCON_ALLOC_ZVAL_MM(r8);
			PHALCON_CALL_METHOD(r8, this_ptr, "getvalue", PHALCON_CALL_DEFAULT);
			Z_ADDREF_P(r8);
			PHALCON_CALL_FUNC_PARAMS_1(r7, "addslashes", r8, 0x01F);
			Z_DELREF_P(r8);
			PHALCON_CPY_WRT(v4, r7);
			PHALCON_ALLOC_ZVAL_MM(r9);
			PHALCON_CONCAT_VBOTH(r9, v1, "='", v4);
			PHALCON_ALLOC_ZVAL_MM(r10);
			PHALCON_CONCAT_RIGHT(r10, r9, "'");
			Z_ADDREF_P(r10);
			PHALCON_SEPARATE_ARRAY(v2);
			phalcon_array_append(v2, r10 TSRMLS_CC);
		}
		PHALCON_ALLOC_ZVAL_MM(r11);
		PHALCON_CALL_METHOD(r11, v0, "getmanager", PHALCON_CALL_DEFAULT);
		PHALCON_CPY_WRT(v5, r11);
		PHALCON_ALLOC_ZVAL_MM(r12);
		PHALCON_CALL_METHOD(r12, v5, "getmetadata", PHALCON_CALL_DEFAULT);
		PHALCON_CPY_WRT(v6, r12);
		PHALCON_ALLOC_ZVAL_MM(r13);
		Z_ADDREF_P(v0);
		p9[0] = v0;
		PHALCON_CALL_METHOD_PARAMS(r13, v6, "getprimarykeyattributes", 1, p9, PHALCON_CALL_DEFAULT);
		Z_DELREF_P(p9[0]);
		PHALCON_CPY_WRT(v7, r13);
		if (Z_TYPE_P(v7) != IS_ARRAY) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid argument supplied for foreach()");
		} else {
			ah1 = Z_ARRVAL_P(v7);
			zend_hash_internal_pointer_reset_ex(ah1, &hp1);
			fes_d73d_1:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_d73d_1;
			}
			PHALCON_INIT_VAR(v8);
			ZVAL_ZVAL(v8, *hd, 1, 0);
			PHALCON_INIT_VAR(r15);
			PHALCON_INIT_VAR(r16);
			Z_ADDREF_P(v8);
			p11[0] = v8;
			PHALCON_CALL_METHOD_PARAMS(r16, v0, "readattribute", 1, p11, PHALCON_CALL_DEFAULT);
			Z_DELREF_P(p11[0]);
			Z_ADDREF_P(r16);
			PHALCON_CALL_FUNC_PARAMS_1(r15, "addslashes", r16, 0x01F);
			Z_DELREF_P(r16);
			PHALCON_INIT_VAR(r14);
			PHALCON_CONCAT_VBOTH(r14, v8, "<>'", r15);
			PHALCON_INIT_VAR(r17);
			PHALCON_CONCAT_RIGHT(r17, r14, "'");
			Z_ADDREF_P(r17);
			PHALCON_SEPARATE_ARRAY(v2);
			phalcon_array_append(v2, r17 TSRMLS_CC);
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_d73d_1;
			fee_d73d_1:
			if(0){ };
		}
		PHALCON_ALLOC_ZVAL_MM(r18);
		PHALCON_INIT_VAR(c0);
		ZVAL_STRING(c0, " AND ", 1);
		PHALCON_CALL_FUNC_PARAMS_2(r18, "join", c0, v2, 0x00F);
		PHALCON_CPY_WRT(v2, r18);
		PHALCON_ALLOC_ZVAL_MM(r19);
		Z_ADDREF_P(v2);
		p13[0] = v2;
		PHALCON_CALL_STATIC_ZVAL_PARAMS(r19, v0, "count", 1, p13);
		Z_DELREF_P(p13[0]);
		PHALCON_INIT_VAR(t0);
		ZVAL_LONG(t0, 0);
		PHALCON_INIT_VAR(r20);
		is_smaller_function(r20, t0, r19 TSRMLS_CC);
		if (zend_is_true(r20)) {
			PHALCON_ALLOC_ZVAL_MM(r21);
			PHALCON_CALL_METHOD(r21, this_ptr, "getoptions", PHALCON_CALL_DEFAULT);
			PHALCON_CPY_WRT(v9, r21);
			eval_int = phalcon_array_isset_string(v9, "message", strlen("message")+1);
			if (eval_int) {
				PHALCON_ALLOC_ZVAL_MM(r22);
				phalcon_array_fetch_string(&r22, v9, "message", strlen("message"), PHALCON_NOISY_FETCH TSRMLS_CC);
				Z_ADDREF_P(r22);
				p15[0] = r22;
				Z_ADDREF_P(v1);
				p15[1] = v1;
				PHALCON_INIT_VAR(p15[2]);
				ZVAL_STRING(p15[2], "unique", 1);
				PHALCON_CALL_METHOD_PARAMS_NORETURN(this_ptr, "appendmessage", 3, p15, PHALCON_CALL_DEFAULT);
				Z_DELREF_P(p15[0]);
				Z_DELREF_P(p15[1]);
			} else {
				PHALCON_ALLOC_ZVAL_MM(r23);
				PHALCON_CONCAT_BOTH(r23,  "Value of field '", v1, "' is already present in another record");
				Z_ADDREF_P(r23);
				p16[0] = r23;
				Z_ADDREF_P(v1);
				p16[1] = v1;
				PHALCON_INIT_VAR(p16[2]);
				ZVAL_STRING(p16[2], "unique", 1);
				PHALCON_CALL_METHOD_PARAMS_NORETURN(this_ptr, "appendmessage", 3, p16, PHALCON_CALL_DEFAULT);
				Z_DELREF_P(p16[0]);
				Z_DELREF_P(p16[1]);
			}
			PHALCON_MM_RESTORE();
			RETURN_FALSE;
		}
	}
	PHALCON_MM_RESTORE();
	RETURN_TRUE;
}
Example #5
0
/**
 * Internal handler to call a queue of events
 *
 * @param \SplPriorityQueue $queue
 * @param Phalcon\Events\Event $event
 * @return mixed
 */
PHP_METHOD(Phalcon_Events_Manager, fireQueue){

	zval *queue, *event, *status = NULL, *arguments = NULL, *event_name;
	zval *source, *data, *cancelable, *collect, *iterator;
	zval *handler = NULL, *is_stopped = NULL;
	zval *r0 = NULL;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 0, &queue, &event);
	
	if (unlikely(Z_TYPE_P(queue) != IS_ARRAY)) { 
		if (Z_TYPE_P(queue) != IS_OBJECT) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The SplPriorityQueue is not valid");
			return;
		}
	}
	if (unlikely(Z_TYPE_P(event) != IS_OBJECT)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event is not valid");
		return;
	}
	
	PHALCON_INIT_VAR(status);
	
	PHALCON_INIT_VAR(arguments);
	
	/** 
	 * Get the event type
	 */
	PHALCON_INIT_VAR(event_name);
	phalcon_call_method(event_name, event, "gettype");
	if (unlikely(Z_TYPE_P(event_name) != IS_STRING)) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event type not valid");
		return;
	}
	
	/** 
	 * Get the object who triggered the event
	 */
	PHALCON_INIT_VAR(source);
	phalcon_call_method(source, event, "getsource");
	
	/** 
	 * Get extra data passed to the event
	 */
	PHALCON_INIT_VAR(data);
	phalcon_call_method(data, event, "getdata");
	
	/** 
	 * Tell if the event is cancelable
	 */
	PHALCON_INIT_VAR(cancelable);
	phalcon_call_method(cancelable, event, "getcancelable");
	
	/** 
	 * Responses need to be traced?
	 */
	PHALCON_OBS_VAR(collect);
	phalcon_read_property_this(&collect, this_ptr, SL("_collect"), PH_NOISY_CC);
	if (Z_TYPE_P(queue) == IS_OBJECT) {
	
		/** 
		 * We need to clone the queue before iterate over it
		 */
		PHALCON_INIT_VAR(iterator);
		if (phalcon_clone(iterator, queue TSRMLS_CC) == FAILURE) {
			return;
		}
	
		/** 
		 * Move the queue to the top
		 */
		phalcon_call_method_noret(iterator, "top");
	
		while (1) {
	
			PHALCON_INIT_NVAR(r0);
			phalcon_call_method(r0, iterator, "valid");
			if (zend_is_true(r0)) {
			} else {
				break;
			}
	
			/** 
			 * Get the current data
			 */
			PHALCON_INIT_NVAR(handler);
			phalcon_call_method(handler, iterator, "current");
	
			/** 
			 * Only handler objects are valid
			 */
			if (likely(Z_TYPE_P(handler) == IS_OBJECT)) {
	
				/** 
				 * Check if the event is a closure
				 */
				if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) {
	
					/** 
					 * Create the closure arguments
					 */
					if (Z_TYPE_P(arguments) == IS_NULL) {
						PHALCON_INIT_NVAR(arguments);
						array_init_size(arguments, 3);
						phalcon_array_append(&arguments, event, PH_SEPARATE);
						phalcon_array_append(&arguments, source, PH_SEPARATE);
						phalcon_array_append(&arguments, data, PH_SEPARATE);
					}
	
					/** 
					 * Call the function in the PHP userland
					 */
					PHALCON_INIT_NVAR(status);
					PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments);
	
					/** 
					 * Trace the response
					 */
					if (zend_is_true(collect)) {
						phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
					}
	
					if (zend_is_true(cancelable)) {
	
						/** 
						 * Check if the event was stopped by the user
						 */
						PHALCON_INIT_NVAR(is_stopped);
						phalcon_call_method(is_stopped, event, "isstopped");
						if (zend_is_true(is_stopped)) {
							break;
						}
					}
				} else {
					/** 
					 * Check if the listener has implemented an event with the same name
					 */
					if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) {
	
						/** 
						 * Call the function in the PHP userland
						 */
						PHALCON_INIT_NVAR(status);
						phalcon_call_method_zval_p3(status, handler, event_name, event, source, data);
	
						/** 
						 * Collect the response
						 */
						if (zend_is_true(collect)) {
							phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
						}
	
						if (zend_is_true(cancelable)) {
	
							/** 
							 * Check if the event was stopped by the user
							 */
							PHALCON_INIT_NVAR(is_stopped);
							phalcon_call_method(is_stopped, event, "isstopped");
							if (zend_is_true(is_stopped)) {
								break;
							}
						}
					}
				}
			}
	
			/** 
			 * Move the queue to the next handler
			 */
			phalcon_call_method_noret(iterator, "next");
		}
	} else {
	
		phalcon_is_iterable(queue, &ah0, &hp0, 0, 0);
	
		while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
			PHALCON_GET_HVALUE(handler);
	
			/** 
			 * Only handler objects are valid
			 */
			if (likely(Z_TYPE_P(handler) == IS_OBJECT)) {
	
				/** 
				 * Check if the event is a closure
				 */
				if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) {
	
					/** 
					 * Create the closure arguments
					 */
					if (Z_TYPE_P(arguments) == IS_NULL) {
						PHALCON_INIT_NVAR(arguments);
						array_init_size(arguments, 3);
						phalcon_array_append(&arguments, event, PH_SEPARATE);
						phalcon_array_append(&arguments, source, PH_SEPARATE);
						phalcon_array_append(&arguments, data, PH_SEPARATE);
					}
	
					/** 
					 * Call the function in the PHP userland
					 */
					PHALCON_INIT_NVAR(status);
					PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments);
	
					/** 
					 * Trace the response
					 */
					if (zend_is_true(collect)) {
						phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
					}
	
					if (zend_is_true(cancelable)) {
	
						/** 
						 * Check if the event was stopped by the user
						 */
						PHALCON_INIT_NVAR(is_stopped);
						phalcon_call_method(is_stopped, event, "isstopped");
						if (zend_is_true(is_stopped)) {
							break;
						}
					}
				} else {
					/** 
					 * Check if the listener has implemented an event with the same name
					 */
					if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) {
	
						/** 
						 * Call the function in the PHP userland
						 */
						PHALCON_INIT_NVAR(status);
						phalcon_call_method_zval_p3(status, handler, event_name, event, source, data);
	
						/** 
						 * Collect the response
						 */
						if (zend_is_true(collect)) {
							phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC);
						}
	
						if (zend_is_true(cancelable)) {
	
							/** 
							 * Check if the event was stopped by the user
							 */
							PHALCON_INIT_NVAR(is_stopped);
							phalcon_call_method(is_stopped, event, "isstopped");
							if (zend_is_true(is_stopped)) {
								break;
							}
						}
					}
				}
			}
	
			zend_hash_move_forward_ex(ah0, &hp0);
		}
	
	}
	
	RETURN_CCTOR(status);
}
Example #6
0
/**
 * Assigns values to a row from an array returning a new row
 *
 * @param array $result
 * @return Phalcon\Mvc\Model $result
 */
PHP_METHOD(Phalcon_Mvc_Model_Row, dumpResult){

	zval *result = NULL, *object_row = NULL, *columns = NULL, *value = NULL, *field = NULL;
	zval *i0 = NULL;
	zval *t0 = NULL, *t1 = NULL, *t2 = NULL;
	zval *r0 = NULL, *r1 = NULL;
	HashTable *ah0, *ah1;
	HashPosition hp0, hp1;
	zval **hd;
	char *hash_index;
	uint hash_index_len;
	ulong hash_num;
	int hash_type;

	PHALCON_MM_GROW();
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &result) == FAILURE) {
		PHALCON_MM_RESTORE();
		RETURN_NULL();
	}

	PHALCON_ALLOC_ZVAL_MM(i0);
	if (phalcon_clone(i0, this_ptr TSRMLS_CC) == FAILURE){
		return;
	}
	PHALCON_CPY_WRT(object_row, i0);
	
	PHALCON_ALLOC_ZVAL_MM(t0);
	phalcon_read_property(&t0, this_ptr, SL("_columns"), PH_NOISY_CC);
	
	PHALCON_ALLOC_ZVAL_MM(r0);
	phalcon_fast_count(r0, t0 TSRMLS_CC);
	
	PHALCON_INIT_VAR(t1);
	ZVAL_LONG(t1, 0);
	
	PHALCON_ALLOC_ZVAL_MM(r1);
	is_equal_function(r1, r0, t1 TSRMLS_CC);
	if (zend_is_true(r1)) {
		PHALCON_INIT_VAR(columns);
		array_init(columns);
		if (!phalcon_valid_foreach(result TSRMLS_CC)) {
			return;
		}
		
		ah0 = Z_ARRVAL_P(result);
		zend_hash_internal_pointer_reset_ex(ah0, &hp0);
		fes_4c15_0:
			if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){
				goto fee_4c15_0;
			}
			
			PHALCON_INIT_VAR(field);
			PHALCON_GET_FOREACH_KEY(field, ah0, hp0);
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			phalcon_array_update_zval_bool(&columns, field, 1, PH_SEPARATE TSRMLS_CC);
			phalcon_update_property_zval_zval(object_row, field, value TSRMLS_CC);
			zend_hash_move_forward_ex(ah0, &hp0);
			goto fes_4c15_0;
		fee_4c15_0:
		if(0){}
		
		phalcon_update_property_zval(object_row, SL("_columns"), columns TSRMLS_CC);
		phalcon_update_property_zval(this_ptr, SL("_columns"), columns TSRMLS_CC);
	} else {
		if (!phalcon_valid_foreach(result TSRMLS_CC)) {
			return;
		}
		
		ah1 = Z_ARRVAL_P(result);
		zend_hash_internal_pointer_reset_ex(ah1, &hp1);
		fes_4c15_1:
			if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){
				goto fee_4c15_1;
			}
			
			PHALCON_INIT_VAR(field);
			PHALCON_GET_FOREACH_KEY(field, ah1, hp1);
			PHALCON_INIT_VAR(value);
			ZVAL_ZVAL(value, *hd, 1, 0);
			phalcon_update_property_zval_zval(object_row, field, value TSRMLS_CC);
			zend_hash_move_forward_ex(ah1, &hp1);
			goto fes_4c15_1;
		fee_4c15_1:
		if(0){}
		
		PHALCON_ALLOC_ZVAL_MM(t2);
		phalcon_read_property(&t2, this_ptr, SL("_columns"), PH_NOISY_CC);
		phalcon_update_property_zval(object_row, SL("_columns"), t2 TSRMLS_CC);
	}
	
	
	RETURN_CCTOR(object_row);
}
Example #7
0
/**
 * Perform the automatic rendering returning the output as a string
 *
 * <code>
 * 	$template = $this->view->getRender('products', 'show', array('products' => $products));
 * </code>
 *
 * @param string $controllerName
 * @param string $actionName
 * @param array $params
 * @param mixed $configCallback
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_View, getRender){

	zval *controller_name, *action_name, *params = NULL;
	zval *config_callback = NULL, *view, *status, *content;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 2, 2, &controller_name, &action_name, &params, &config_callback);
	
	if (!params) {
		PHALCON_INIT_VAR(params);
	} else {
		PHALCON_SEPARATE_PARAM(params);
	}
	
	if (!config_callback) {
		PHALCON_INIT_VAR(config_callback);
	}
	
	/** 
	 * We must to clone the current view to keep the old state
	 */
	PHALCON_INIT_VAR(view);
	if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) {
		return;
	}
	
	/** 
	 * The component must be reset to its defaults
	 */
	PHALCON_CALL_METHOD_NORETURN(view, "reset");
	
	/** 
	 * Set the render variables
	 */
	if (Z_TYPE_P(params) == IS_ARRAY) { 
		PHALCON_CALL_METHOD_PARAMS_1_NORETURN(view, "setvars", params);
	}
	
	/** 
	 * Perform extra configurations over the cloned object
	 */
	if (Z_TYPE_P(config_callback) == IS_OBJECT) {
		PHALCON_INIT_NVAR(params);
		array_init_size(params, 1);
		phalcon_array_append(&params, view, PH_SEPARATE TSRMLS_CC);
	
		PHALCON_INIT_VAR(status);
		PHALCON_CALL_USER_FUNC_ARRAY(status, config_callback, params);
	}
	
	/** 
	 * Start the output buffering
	 */
	PHALCON_CALL_METHOD_NORETURN(view, "start");
	
	/** 
	 * Perform the render passing only the controller and action
	 */
	PHALCON_CALL_METHOD_PARAMS_2_NORETURN(view, "render", controller_name, action_name);
	
	/** 
	 * Stop the output buffering
	 */
	PHALCON_CALL_FUNC_NORETURN("ob_end_clean");
	
	/** 
	 * Get the processed content
	 */
	PHALCON_INIT_VAR(content);
	PHALCON_CALL_METHOD(content, view, "getcontent");
	
	RETURN_CCTOR(content);
}