/** * 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) { zend_function *_8 = NULL, *_9 = NULL, *_11 = NULL, *_12 = NULL, *_14 = NULL; HashTable *_3, *_16; HashPosition _2, _15; 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 = NULL, *_0, *_1, **_4, *_5, *_6 = NULL, *_7 = NULL, *_10 = NULL, *_13 = NULL, **_17, *_18, *_19, *_20, *_21, *_22; 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_INIT_LNVAR(_6); object_init_ex(_6, test_router_exception_ce); ZEPHIR_INIT_NVAR(_7); ZVAL_STRING(_7, "A dependency injection container is required to access the 'request' service", 1); zephir_call_method_p1_cache_noret(_6, "__construct", &_8, _7); zephir_throw_exception(_6 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_NVAR(_7); ZVAL_STRING(_7, "request", 1); ZEPHIR_INIT_NVAR(request); zephir_call_method_p1_cache(request, dependencyInjector, "getshared", &_9, _7); } ZEPHIR_INIT_NVAR(_7); zephir_call_method_p1(_7, request, "ismethod", methods); if (ZEPHIR_IS_FALSE(_7)) { 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_INIT_LNVAR(_6); object_init_ex(_6, test_router_exception_ce); ZEPHIR_INIT_NVAR(_10); ZVAL_STRING(_10, "A dependency injection container is required to access the 'request' service", 1); zephir_call_method_p1_cache_noret(_6, "__construct", &_11, _10); zephir_throw_exception(_6 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } ZEPHIR_INIT_NVAR(_7); ZVAL_STRING(_7, "request", 1); ZEPHIR_INIT_NVAR(request); zephir_call_method_p1_cache(request, dependencyInjector, "getshared", &_12, _7); } 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(_13); zephir_preg_match(matched, &(matched), regexHostName, currentHostName, _13, 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_INIT_LNVAR(_6); object_init_ex(_6, test_router_exception_ce); ZEPHIR_INIT_NVAR(_7); ZVAL_STRING(_7, "Before-Match callback is not callable in matched route", 1); zephir_call_method_p1_cache_noret(_6, "__construct", &_14, _7); zephir_throw_exception(_6 TSRMLS_CC); ZEPHIR_MM_RESTORE(); 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, &_16, &_15, 0, 0); for ( ; zend_hash_get_current_data_ex(_16, (void**) &_17, &_15) == SUCCESS ; zephir_hash_move_forward_ex(_16, &_15) ) { ZEPHIR_GET_HMKEY(part, _16, _15); ZEPHIR_GET_HVALUE(position, _17); ZEPHIR_OBS_NVAR(matchPosition); if (zephir_array_isset_fetch(&matchPosition, matches, position, 0 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))) { ZEPHIR_OBS_VAR(notFoundPaths); zephir_read_property_this(¬FoundPaths, 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)) { ZEPHIR_OBS_VAR(vnamespace); if (zephir_array_isset_string_fetch(&vnamespace, parts, SS("namespace"), 0 TSRMLS_CC)) { if (!(zephir_is_numeric(vnamespace))) { zephir_update_property_this(this_ptr, SL("_namespace"), vnamespace TSRMLS_CC); } zephir_array_fetch_string(&_18, parts, SL("namespace"), PH_NOISY | PH_READONLY TSRMLS_CC); zephir_array_unset(&parts, _18, 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); } ZEPHIR_OBS_VAR(module); if (zephir_array_isset_string_fetch(&module, parts, SS("module"), 0 TSRMLS_CC)) { if (!(zephir_is_numeric(module))) { zephir_update_property_this(this_ptr, SL("_module"), module TSRMLS_CC); } zephir_array_fetch_string(&_18, parts, SL("module"), PH_NOISY | PH_READONLY TSRMLS_CC); zephir_array_unset(&parts, _18, 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); } ZEPHIR_OBS_VAR(controller); if (zephir_array_isset_string_fetch(&controller, parts, SS("controller"), 0 TSRMLS_CC)) { if (!(zephir_is_numeric(controller))) { zephir_update_property_this(this_ptr, SL("_controller"), controller TSRMLS_CC); } zephir_array_fetch_string(&_18, parts, SL("controller"), PH_NOISY | PH_READONLY TSRMLS_CC); zephir_array_unset(&parts, _18, 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); } ZEPHIR_OBS_VAR(action); if (zephir_array_isset_string_fetch(&action, parts, SS("action"), 0 TSRMLS_CC)) { if (!(zephir_is_numeric(action))) { zephir_update_property_this(this_ptr, SL("_action"), action TSRMLS_CC); } zephir_array_fetch_string(&_18, parts, SL("action"), PH_NOISY | PH_READONLY TSRMLS_CC); zephir_array_unset(&parts, _18, 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); } ZEPHIR_OBS_VAR(paramsStr); if (zephir_array_isset_string_fetch(¶msStr, parts, SS("params"), 0 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(&_18, parts, SL("params"), PH_NOISY | PH_READONLY TSRMLS_CC); zephir_array_unset(&parts, _18, 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); _19 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultModule"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_module"), _19 TSRMLS_CC); _20 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultController"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_controller"), _20 TSRMLS_CC); _21 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultAction"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_action"), _21 TSRMLS_CC); _22 = zephir_fetch_nproperty_this(this_ptr, SL("_defaultParams"), PH_NOISY_CC); zephir_update_property_this(this_ptr, SL("_params"), _22 TSRMLS_CC); } ZEPHIR_MM_RESTORE(); }
PHP_METHOD(Test_FortyTwo, proof) { zend_function *_10 = NULL; zend_class_entry *_9; zend_bool _5; HashTable *_3; HashPosition _2; int i, j, _6, _7; zval *box, *side = NULL, *_0 = NULL, *_1 = NULL, **_4, *_8; ZEPHIR_MM_GROW(); ZEPHIR_INIT_VAR(box); array_init_size(box, 17); ZEPHIR_INIT_VAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_VAR(_1); ZVAL_LONG(_1, 10); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 24); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 8); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 8); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 15); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 19); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 19); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 17); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 6); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 6); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 16); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 20); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 20); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 13); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 9); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 9); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 11); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 22); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 22); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 2); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 18); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 18); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 4); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 20); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 5); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 21); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 16); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 16); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 3); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 23); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 23); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 7); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 12); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 12); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 25); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 5); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 24); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 7); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 11); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 11); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 27); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 4); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); ZEPHIR_INIT_BNVAR(_0); array_init_size(_0, 5); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 11); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 27); zephir_array_fast_append(_0, _1); ZEPHIR_INIT_BNVAR(_1); ZVAL_LONG(_1, 4); zephir_array_fast_append(_0, _1); zephir_array_fast_append(box, _0); zephir_is_iterable(box, &_3, &_2, 0, 0); for ( ; zend_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS ; zend_hash_move_forward_ex(_3, &_2) ) { ZEPHIR_GET_HVALUE(side, _4); j = 0; _7 = 2; _6 = 0; _5 = 0; if ((_6 <= _7)) { while (1) { if (_5) { _6++; if (!((_6 <= _7))) { break; } } else { _5 = 1; } i = _6; zephir_array_fetch_long(&_8, side, i, PH_NOISY | PH_READONLY TSRMLS_CC); j += zephir_get_numberval(_8); } } if ((j != 42)) { ZEPHIR_INIT_NVAR(_0); _9 = zend_fetch_class(SL("Exception"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); object_init_ex(_0, _9); ZEPHIR_INIT_NVAR(_1); ZVAL_STRING(_1, "not true", 1); zephir_call_method_p1_cache_noret(_0, "__construct", &_10, _1); zephir_throw_exception(_0 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } } ZEPHIR_MM_RESTORE(); }