Exemplo n.º 1
0
PHP_METHOD(Test_Flow, testFor3) {

	HashTable *_2;
	HashPosition _1;
	zval *v = NULL, *b, *c, *_0, **_3;

	ZEPHIR_MM_GROW();

	ZEPHIR_INIT_VAR(c);
	array_init(c);
	ZEPHIR_INIT_VAR(b);
	array_init_size(b, 5);
	ZEPHIR_INIT_VAR(_0);
	ZVAL_LONG(_0, 1);
	zephir_array_fast_append(b, _0);
	ZEPHIR_INIT_BNVAR(_0);
	ZVAL_LONG(_0, 2);
	zephir_array_fast_append(b, _0);
	ZEPHIR_INIT_BNVAR(_0);
	ZVAL_LONG(_0, 3);
	zephir_array_fast_append(b, _0);
	ZEPHIR_INIT_BNVAR(_0);
	ZVAL_LONG(_0, 4);
	zephir_array_fast_append(b, _0);
	zephir_is_iterable(b, &_2, &_1, 0, 1);
	for (
		; zend_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS
		; zend_hash_move_backwards_ex(_2, &_1)
	) {
		ZEPHIR_GET_HVALUE(v, _3);
		zephir_array_append(&c, v, PH_SEPARATE);
	}
	RETURN_CCTOR(c);

}
Exemplo n.º 2
0
/**
 * Create/Returns a new transaction or an existing one
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getOrCreateTransaction) {

	HashTable *_2$$5;
	HashPosition _1$$5;
	zend_long ZEPHIR_LAST_CALL_STATUS;
	zval *autoBegin_param = NULL, *dependencyInjector = NULL, *transaction = NULL, *transactions = NULL, *_0, *_5, *_6, **_3$$5, *_4$$7 = NULL;
	zend_bool autoBegin;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &autoBegin_param);

	if (!autoBegin_param) {
		autoBegin = 1;
	} else {
		autoBegin = zephir_get_boolval(autoBegin_param);
	}


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
	ZEPHIR_CPY_WRT(dependencyInjector, _0);
	if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM", "phalcon/mvc/model/transaction/manager.zep", 188);
		return;
	}
	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_number"), PH_NOISY_CC);
	if (zephir_is_true(_0)) {
		ZEPHIR_OBS_VAR(transactions);
		zephir_read_property_this(&transactions, this_ptr, SL("_transactions"), PH_NOISY_CC);
		if (Z_TYPE_P(transactions) == IS_ARRAY) {
			zephir_is_iterable(transactions, &_2$$5, &_1$$5, 0, 1, "phalcon/mvc/model/transaction/manager.zep", 200);
			for (
			  ; zend_hash_get_current_data_ex(_2$$5, (void**) &_3$$5, &_1$$5) == SUCCESS
			  ; zend_hash_move_backwards_ex(_2$$5, &_1$$5)
			) {
				ZEPHIR_GET_HVALUE(transaction, _3$$5);
				if (Z_TYPE_P(transaction) == IS_OBJECT) {
					ZEPHIR_INIT_NVAR(_4$$7);
					ZVAL_BOOL(_4$$7, 0);
					ZEPHIR_CALL_METHOD(NULL, transaction, "setisnewtransaction", NULL, 0, _4$$7);
					zephir_check_call_status();
					RETURN_CCTOR(transaction);
				}
			}
		}
	}
	ZEPHIR_INIT_NVAR(transaction);
	object_init_ex(transaction, phalcon_mvc_model_transaction_ce);
	_5 = zephir_fetch_nproperty_this(this_ptr, SL("_service"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(_6);
	if (autoBegin) {
		ZVAL_BOOL(_6, 1);
	} else {
		ZVAL_BOOL(_6, 0);
	}
	ZEPHIR_CALL_METHOD(NULL, transaction, "__construct", NULL, 383, dependencyInjector, _6, _5);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(NULL, transaction, "settransactionmanager", NULL, 384, this_ptr);
	zephir_check_call_status();
	zephir_update_property_array_append(this_ptr, SL("_transactions"), transaction TSRMLS_CC);
	RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_number") TSRMLS_CC));
	RETURN_CCTOR(transaction);

}
Exemplo n.º 3
0
/**
 * Handles routing information received from the rewrite engine
 *
 *<code>
 * //Read the info from the rewrite engine
 * $router->handle();
 *
 * //Manually passing an URL
 * $router->handle('/posts/edit/1');
 *</code>
 *
 * @param string uri
 */
PHP_METHOD(Test_Router, handle) {

    HashTable *_3, *_9;
    HashPosition _2, _8;
    zval *uri = NULL, *realUri = NULL, *request = NULL, *currentHostName = NULL, *routeFound = NULL, *parts = NULL, *params, *matches, *notFoundPaths, *vnamespace, *module, *controller, *action, *paramsStr, *strParams, *paramsMerge = NULL, *route = NULL, *methods = NULL, *dependencyInjector = NULL, *hostname = NULL, *regexHostName = NULL, *matched = NULL, *pattern = NULL, *handledUri = NULL, *beforeMatch = NULL, *paths = NULL, *converters = NULL, *part = NULL, *position = NULL, *matchPosition, *_0, *_1, **_4, *_5, *_6 = NULL, *_7 = NULL, **_10, *_11, *_12, *_13, *_14, *_15;

    ZEPHIR_MM_GROW();
    zephir_fetch_params(1, 0, 1, &uri);

    if (!uri) {
        uri = ZEPHIR_GLOBAL(global_null);
    }


    if (!(zephir_is_true(uri))) {
        ZEPHIR_INIT_VAR(realUri);
        zephir_call_method(realUri, this_ptr, "getrewriteuri");
    } else {
        ZEPHIR_CPY_WRT(realUri, uri);
    }
    _0 = zephir_fetch_nproperty_this(this_ptr, SL("_removeExtraSlashes"), PH_NOISY_CC);
    if (zephir_is_true(_0)) {
        ZEPHIR_INIT_VAR(handledUri);
        zephir_call_method_p1(handledUri, this_ptr, "doremoveextraslashes", realUri);
    } else {
        ZEPHIR_CPY_WRT(handledUri, realUri);
    }
    ZEPHIR_INIT_VAR(request);
    ZVAL_NULL(request);
    ZEPHIR_INIT_VAR(currentHostName);
    ZVAL_NULL(currentHostName);
    ZEPHIR_INIT_VAR(routeFound);
    ZVAL_BOOL(routeFound, 0);
    ZEPHIR_INIT_VAR(parts);
    array_init(parts);
    ZEPHIR_INIT_VAR(params);
    array_init(params);
    ZEPHIR_INIT_VAR(matches);
    ZVAL_NULL(matches);
    zephir_update_property_this(this_ptr, SL("_wasMatched"), (0) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
    zephir_update_property_this(this_ptr, SL("_matchedRoute"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);
    _1 = zephir_fetch_nproperty_this(this_ptr, SL("_routes"), PH_NOISY_CC);
    zephir_is_iterable(_1, &_3, &_2, 0, 1);
    for (
        ; zend_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS
        ; zend_hash_move_backwards_ex(_3, &_2)
    ) {
        ZEPHIR_GET_HVALUE(route, _4);
        ZEPHIR_INIT_NVAR(methods);
        zephir_call_method(methods, route, "gethttpmethods");
        if ((Z_TYPE_P(methods) != IS_NULL)) {
            if ((Z_TYPE_P(request) == IS_NULL)) {
                _5 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
                ZEPHIR_CPY_WRT(dependencyInjector, _5);
                if ((Z_TYPE_P(dependencyInjector) != IS_OBJECT)) {
                    ZEPHIR_THROW_EXCEPTION_STR(test_router_exception_ce, "A dependency injection container is required to access the 'request' service");
                    return;
                }
                ZEPHIR_INIT_NVAR(_6);
                ZVAL_STRING(_6, "request", 1);
                ZEPHIR_INIT_NVAR(request);
                zephir_call_method_p1(request, dependencyInjector, "getshared", _6);
            }
            ZEPHIR_INIT_NVAR(_6);
            zephir_call_method_p1(_6, request, "ismethod", methods);
            if (ZEPHIR_IS_FALSE(_6)) {
                continue;
            }
        }
        ZEPHIR_INIT_NVAR(hostname);
        zephir_call_method(hostname, route, "gethostname");
        if ((Z_TYPE_P(hostname) != IS_NULL)) {
            if ((Z_TYPE_P(request) == IS_NULL)) {
                ZEPHIR_OBS_NVAR(dependencyInjector);
                zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
                if ((Z_TYPE_P(dependencyInjector) != IS_OBJECT)) {
                    ZEPHIR_THROW_EXCEPTION_STR(test_router_exception_ce, "A dependency injection container is required to access the 'request' service");
                    return;
                }
                ZEPHIR_INIT_NVAR(_6);
                ZVAL_STRING(_6, "request", 1);
                ZEPHIR_INIT_NVAR(request);
                zephir_call_method_p1(request, dependencyInjector, "getshared", _6);
            }
            if ((Z_TYPE_P(currentHostName) != IS_OBJECT)) {
                ZEPHIR_INIT_NVAR(currentHostName);
                zephir_call_method(currentHostName, request, "gethttphost");
            }
            if ((Z_TYPE_P(currentHostName) != IS_NULL)) {
                continue;
            }
            ZEPHIR_INIT_NVAR(matched);
            if (zephir_memnstr_str(hostname, SL("("), "test/router.zep", 381)) {
                if (zephir_memnstr_str(hostname, SL("#"), "test/router.zep", 382)) {
                    ZEPHIR_INIT_NVAR(regexHostName);
                    ZEPHIR_CONCAT_SVS(regexHostName, "#^", hostname, "$#");
                } else {
                    ZEPHIR_CPY_WRT(regexHostName, hostname);
                }
                ZEPHIR_INIT_NVAR(_7);
                zephir_preg_match(matched, &(matched), regexHostName, currentHostName, _7, 0, 0 , 0  TSRMLS_CC);
            } else {
                ZVAL_BOOL(matched, ZEPHIR_IS_EQUAL(currentHostName, hostname));
            }
            if (!(zephir_is_true(matched))) {
                continue;
            }
        }
        ZEPHIR_INIT_NVAR(pattern);
        zephir_call_method(pattern, route, "getcompiledpattern");
        ZEPHIR_INIT_NVAR(routeFound);
        if (zephir_memnstr_str(pattern, SL("^"), "test/router.zep", 400)) {
            zephir_preg_match(routeFound, &(routeFound), pattern, handledUri, matches, 0, 0 , 0  TSRMLS_CC);
        } else {
            ZVAL_BOOL(routeFound, ZEPHIR_IS_EQUAL(pattern, handledUri));
        }
        if (zephir_is_true(routeFound)) {
            ZEPHIR_INIT_NVAR(beforeMatch);
            zephir_call_method(beforeMatch, route, "getbeforematch");
            if ((Z_TYPE_P(beforeMatch) != IS_NULL)) {
                if (zephir_is_callable(beforeMatch TSRMLS_CC)) {
                    ZEPHIR_THROW_EXCEPTION_STR(test_router_exception_ce, "Before-Match callback is not callable in matched route");
                    return;
                }
            }
        }
        if (zephir_is_true(routeFound)) {
            ZEPHIR_INIT_NVAR(paths);
            zephir_call_method(paths, route, "getpaths");
            ZEPHIR_CPY_WRT(parts, paths);
            if ((Z_TYPE_P(matches) == IS_ARRAY)) {
                ZEPHIR_INIT_NVAR(converters);
                zephir_call_method(converters, route, "getconverters");
                zephir_is_iterable(paths, &_9, &_8, 0, 0);
                for (
                    ; zend_hash_get_current_data_ex(_9, (void**) &_10, &_8) == SUCCESS
                    ; zend_hash_move_forward_ex(_9, &_8)
                ) {
                    ZEPHIR_GET_HMKEY(part, _9, _8);
                    ZEPHIR_GET_HVALUE(position, _10);
                    if (zephir_array_isset_fetch(&matchPosition, matches, position, 1 TSRMLS_CC)) {
                        if ((Z_TYPE_P(converters) == IS_ARRAY)) {
                            if (zephir_array_isset(converters, part)) {
                                continue;
                            }
                        }
                        zephir_array_update_zval(&parts, part, &matchPosition, PH_COPY | PH_SEPARATE);
                    } else {
                        if ((Z_TYPE_P(converters) == IS_ARRAY)) {
                            if (zephir_array_isset(converters, part)) {
                            }
                        }
                    }
                }
                zephir_update_property_this(this_ptr, SL("_matches"), matches TSRMLS_CC);
            }
            zephir_update_property_this(this_ptr, SL("_matchedRoute"), route TSRMLS_CC);
            break;
        }
    }
    if (zephir_is_true(routeFound)) {
        zephir_update_property_this(this_ptr, SL("_wasMatched"), (1) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
    } else {
        zephir_update_property_this(this_ptr, SL("_wasMatched"), (0) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
    }
    if (!(zephir_is_true(routeFound))) {
        notFoundPaths = zephir_fetch_nproperty_this(this_ptr, SL("_notFoundPaths"), PH_NOISY_CC);
        if ((Z_TYPE_P(notFoundPaths) != IS_NULL)) {
            ZEPHIR_CPY_WRT(parts, notFoundPaths);
            ZEPHIR_INIT_BNVAR(routeFound);
            ZVAL_BOOL(routeFound, 1);
        }
    }
    if (zephir_is_true(routeFound)) {
        if (zephir_array_isset_string_fetch(&vnamespace, parts, SS("namespace"), 1 TSRMLS_CC)) {
            if (!(zephir_is_numeric(vnamespace))) {
                zephir_update_property_this(this_ptr, SL("_namespace"), vnamespace TSRMLS_CC);
            }
            zephir_array_fetch_string(&_11, parts, SL("namespace"), PH_NOISY | PH_READONLY TSRMLS_CC);
            zephir_array_unset(&parts, _11, PH_SEPARATE);
        } else {
            _5 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultNamespace"), PH_NOISY_CC);
            zephir_update_property_this(this_ptr, SL("_namespace"), _5 TSRMLS_CC);
        }
        if (zephir_array_isset_string_fetch(&module, parts, SS("module"), 1 TSRMLS_CC)) {
            if (!(zephir_is_numeric(module))) {
                zephir_update_property_this(this_ptr, SL("_module"), module TSRMLS_CC);
            }
            zephir_array_fetch_string(&_11, parts, SL("module"), PH_NOISY | PH_READONLY TSRMLS_CC);
            zephir_array_unset(&parts, _11, PH_SEPARATE);
        } else {
            _5 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultModule"), PH_NOISY_CC);
            zephir_update_property_this(this_ptr, SL("_module"), _5 TSRMLS_CC);
        }
        if (zephir_array_isset_string_fetch(&controller, parts, SS("controller"), 1 TSRMLS_CC)) {
            if (!(zephir_is_numeric(controller))) {
                zephir_update_property_this(this_ptr, SL("_controller"), controller TSRMLS_CC);
            }
            zephir_array_fetch_string(&_11, parts, SL("controller"), PH_NOISY | PH_READONLY TSRMLS_CC);
            zephir_array_unset(&parts, _11, PH_SEPARATE);
        } else {
            _5 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultController"), PH_NOISY_CC);
            zephir_update_property_this(this_ptr, SL("_controller"), _5 TSRMLS_CC);
        }
        if (zephir_array_isset_string_fetch(&action, parts, SS("action"), 1 TSRMLS_CC)) {
            if (!(zephir_is_numeric(action))) {
                zephir_update_property_this(this_ptr, SL("_action"), action TSRMLS_CC);
            }
            zephir_array_fetch_string(&_11, parts, SL("action"), PH_NOISY | PH_READONLY TSRMLS_CC);
            zephir_array_unset(&parts, _11, PH_SEPARATE);
        } else {
            _5 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultAction"), PH_NOISY_CC);
            zephir_update_property_this(this_ptr, SL("_action"), _5 TSRMLS_CC);
        }
        if (zephir_array_isset_string_fetch(&paramsStr, parts, SS("params"), 1 TSRMLS_CC)) {
            ZEPHIR_INIT_VAR(strParams);
            zephir_substr(strParams, paramsStr, 1 , 0 );
            if (zephir_is_true(strParams)) {
                ZEPHIR_INIT_BNVAR(params);
                zephir_fast_explode_str(params, SL("/"), strParams, LONG_MAX TSRMLS_CC);
            }
            zephir_array_fetch_string(&_11, parts, SL("params"), PH_NOISY | PH_READONLY TSRMLS_CC);
            zephir_array_unset(&parts, _11, PH_SEPARATE);
        }
        if (zephir_fast_count_int(params TSRMLS_CC)) {
            ZEPHIR_INIT_VAR(paramsMerge);
            zephir_fast_array_merge(paramsMerge, &(params), &(parts) TSRMLS_CC);
        } else {
            ZEPHIR_CPY_WRT(paramsMerge, parts);
        }
        zephir_update_property_this(this_ptr, SL("_params"), paramsMerge TSRMLS_CC);
    } else {
        _5 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultNamespace"), PH_NOISY_CC);
        zephir_update_property_this(this_ptr, SL("_namespace"), _5 TSRMLS_CC);
        _12 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultModule"), PH_NOISY_CC);
        zephir_update_property_this(this_ptr, SL("_module"), _12 TSRMLS_CC);
        _13 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultController"), PH_NOISY_CC);
        zephir_update_property_this(this_ptr, SL("_controller"), _13 TSRMLS_CC);
        _14 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultAction"), PH_NOISY_CC);
        zephir_update_property_this(this_ptr, SL("_action"), _14 TSRMLS_CC);
        _15 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultParams"), PH_NOISY_CC);
        zephir_update_property_this(this_ptr, SL("_params"), _15 TSRMLS_CC);
    }
    ZEPHIR_MM_RESTORE();

}
Exemplo n.º 4
0
/**
 * Create/Returns a new transaction or an existing one
 *
 * @param boolean $autoBegin
 * @return Phalcon\Mvc\Model\TransactionInterface
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getOrCreateTransaction){

	zval *auto_begin = NULL, *dependency_injector, *number;
	zval *transactions, *transaction = NULL, *false_value = NULL;
	zval *service;
	HashTable *ah0;
	HashPosition hp0;
	zval **hd;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 0, 1, &auto_begin);
	
	if (!auto_begin) {
		PHALCON_INIT_VAR(auto_begin);
		ZVAL_BOOL(auto_begin, 1);
	}
	
	PHALCON_OBS_VAR(dependency_injector);
	phalcon_read_property_this(&dependency_injector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
	if (Z_TYPE_P(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM");
		return;
	}
	
	PHALCON_OBS_VAR(number);
	phalcon_read_property_this(&number, this_ptr, SL("_number"), PH_NOISY_CC);
	if (zend_is_true(number)) {
	
		PHALCON_OBS_VAR(transactions);
		phalcon_read_property_this(&transactions, this_ptr, SL("_transactions"), PH_NOISY_CC);
		if (Z_TYPE_P(transactions) == IS_ARRAY) { 
	
			phalcon_is_iterable(transactions, &ah0, &hp0, 0, 1);
	
			while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {
	
				PHALCON_GET_HVALUE(transaction);
	
				if (Z_TYPE_P(transaction) == IS_OBJECT) {
					PHALCON_INIT_NVAR(false_value);
					ZVAL_BOOL(false_value, 0);
					phalcon_call_method_p1_noret(transaction, "setisnewtransaction", false_value);
					RETURN_CCTOR(transaction);
				}
	
				zend_hash_move_backwards_ex(ah0, &hp0);
			}
	
		}
	}
	
	PHALCON_OBS_VAR(service);
	phalcon_read_property_this(&service, this_ptr, SL("_service"), PH_NOISY_CC);
	
	PHALCON_INIT_VAR(transaction);
	object_init_ex(transaction, phalcon_mvc_model_transaction_ce);
	phalcon_call_method_p3_noret(transaction, "__construct", dependency_injector, auto_begin, service);
	
	phalcon_call_method_p1_noret(transaction, "settransactionmanager", this_ptr);
	phalcon_update_property_array_append(this_ptr, SL("_transactions"), transaction TSRMLS_CC);
	phalcon_property_incr(this_ptr, SL("_number") TSRMLS_CC);
	
	RETURN_CTOR(transaction);
}