/** * Handles method calls when a method is not implemented * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_View_Engine, __call){ zval *method, *args = NULL, method_name = {}, arguments = {}, *methods, func = {}, exception_message = {}, service_name = {}, service = {}, callback = {}; phalcon_fetch_params(0, 1, 1, &method, &arguments); PHALCON_CPY_WRT(&method_name, method); if (!args) { array_init(&arguments); } else { PHALCON_CPY_WRT(&arguments, args); } methods = phalcon_read_property(getThis(), SL("_methods"), PH_NOISY); if (phalcon_array_isset_fetch(&func, methods, &method_name)) { PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &func, &arguments); return; } if (phalcon_compare_strict_string(&method_name, SL("get")) || phalcon_compare_strict_string(&method_name, SL("getPost")) || phalcon_compare_strict_string(&method_name, SL("getPut")) || phalcon_compare_strict_string(&method_name, SL("getQuery")) || phalcon_compare_strict_string(&method_name, SL("getServer"))) { ZVAL_STRING(&service_name, ISV(request)); } else if (phalcon_compare_strict_string(&method_name, SL("getSession"))) { ZVAL_STRING(&method_name, "get"); ZVAL_STRING(&service_name, ISV(session)); } else if (phalcon_compare_strict_string(&method_name, SL("getParam"))) { ZVAL_STRING(&service_name, ISV(dispatcher)); } PHALCON_CALL_METHODW(&service, getThis(), "getresolveservice", &service_name); if (Z_TYPE(service) != IS_OBJECT) { PHALCON_CONCAT_SVS(&exception_message, "The injected service '", &service_name, "' is not valid"); PHALCON_THROW_EXCEPTION_ZVALW(phalcon_mvc_view_exception_ce, &exception_message); return; } if (!phalcon_method_exists(&service, &method_name) == FAILURE) { PHALCON_CONCAT_SVS(&exception_message, "The method \"", &method_name, "\" doesn't exist on view"); PHALCON_THROW_EXCEPTION_ZVALW(phalcon_mvc_view_exception_ce, &exception_message); return; } array_init(&callback); phalcon_array_append(&callback, &service, PH_COPY); phalcon_array_append(&callback, &method_name, PH_COPY); PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &callback, &arguments); }
/** * Initializes the internal handler, calling functions on it * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ zval *method, *arguments, handler = {}, definition = {}, call_handler = {}; zend_class_entry *ce0; phalcon_fetch_params(0, 2, 0, &method, &arguments); phalcon_return_property(&handler, getThis(), SL("_handler")); if (Z_TYPE(handler) != IS_OBJECT) { phalcon_read_property(&definition, getThis(), SL("_definition"), PH_NOISY); ce0 = phalcon_fetch_class(&definition, ZEND_FETCH_CLASS_DEFAULT); PHALCON_OBJECT_INIT(&handler, ce0); if (phalcon_has_constructor(&handler)) { PHALCON_CALL_METHODW(NULL, &handler, "__construct"); } phalcon_update_property_zval(getThis(), SL("_handler"), &handler); } array_init_size(&call_handler, 2); phalcon_array_append(&call_handler, &handler, PH_COPY); phalcon_array_append(&call_handler, method, PH_COPY); /** * Call the handler */ PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &call_handler, arguments); }
/** * Decrypts an encrypted text * *<code> * echo $crypt->decrypt($encrypted, "decrypt password"); *</code> * * @param string $text * @param string $key * @param int $options * @return string */ PHP_METHOD(Phalcon_Crypt, decrypt){ zval *source, *key = NULL, *options = NULL, handler = {}, arguments = {}, value = {}, text = {}, encrypt_key = {}, encrypt_options = {}; zval method = {}, iv_size = {}, iv = {}, text_to_decipher = {}; phalcon_fetch_params(0, 1, 2, &source, &key, &options); if (phalcon_function_exists_ex(SL("openssl_encrypt")) == FAILURE) { PHALCON_THROW_EXCEPTION_STRW(phalcon_crypt_exception_ce, "openssl extension is required"); return; } phalcon_read_property(&handler, getThis(), SL("_beforeDecrypt"), 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 (!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); if (Z_LVAL(iv_size) <= 0) { ZVAL_NULL(&iv); PHALCON_CPY_WRT_CTOR(&text_to_decipher, &text); } else { phalcon_substr(&iv, &text, 0, Z_LVAL(iv_size)); phalcon_substr(&text_to_decipher, &text, Z_LVAL(iv_size), 0); } PHALCON_CALL_FUNCTIONW(return_value, "openssl_decrypt", &text_to_decipher, &method, &encrypt_key, &encrypt_options, &iv); if (unlikely(Z_TYPE_P(return_value) != IS_STRING)) { convert_to_string(return_value); } phalcon_read_property(&handler, getThis(), SL("_afterDecrypt"), 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); } }
/** * Resolves the service * * @param array $parameters * @param Phalcon\DIInterface $dependencyInjector * @return object */ PHP_METHOD(Phalcon_DI_Service, resolve){ zval *parameters = NULL, *dependency_injector = NULL, name = {}, shared = {}, shared_instance = {}, definition = {}, builder = {}; int found = 0, ishared = 0; phalcon_fetch_params(0, 0, 2, ¶meters, &dependency_injector); if (!parameters) { parameters = &PHALCON_GLOBAL(z_null); } if (!dependency_injector) { dependency_injector = &PHALCON_GLOBAL(z_null); } phalcon_return_property(&shared, getThis(), SL("_shared")); phalcon_return_property(&shared_instance, getThis(), SL("_sharedInstance")); ishared = zend_is_true(&shared); /* Check if the service is shared */ if (ishared && Z_TYPE(shared_instance) != IS_NULL) { RETURN_CTORW(&shared_instance); } phalcon_return_property(&definition, getThis(), SL("_definition")); if (Z_TYPE(definition) == IS_STRING) { /* String definitions can be class names without implicit parameters */ if (phalcon_class_exists(&definition, 1) != NULL) { found = 1; if (Z_TYPE_P(parameters) == IS_ARRAY) { RETURN_ON_FAILURE(phalcon_create_instance_params(return_value, &definition, parameters)); } else { RETURN_ON_FAILURE(phalcon_create_instance(return_value, &definition)); } } } else if (likely(Z_TYPE(definition) == IS_OBJECT)) { /* Object definitions can be a Closure or an already resolved instance */ found = 1; if (instanceof_function_ex(Z_OBJCE(definition), zend_ce_closure, 0)) { if (likely(Z_TYPE_P(dependency_injector) == IS_OBJECT)) { PHALCON_CALL_CE_STATICW(&definition, zend_ce_closure, "bind", &definition, dependency_injector); } if (Z_TYPE_P(parameters) == IS_ARRAY) { PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &definition, parameters); } else { PHALCON_CALL_USER_FUNCW(return_value, &definition); } } else { PHALCON_CPY_WRT(return_value, &definition); } } else if (Z_TYPE(definition) == IS_ARRAY) { found = 1; /* Array definitions require a 'className' parameter */ object_init_ex(&builder, phalcon_di_service_builder_ce); PHALCON_CALL_METHODW(return_value, &builder, "build", dependency_injector, &definition, parameters); } if (!EG(exception)) { if (found) { if (ishared) { phalcon_update_property_zval(getThis(), SL("_sharedInstance"), return_value); } /* Update the shared instance if the service is shared */ phalcon_update_property_bool(getThis(), SL("_resolved"), 1); } else { phalcon_return_property(&name, getThis(), SL("_name")); PHALCON_THROW_EXCEPTION_FORMATW(phalcon_di_exception_ce, "Service '%s' cannot be resolved", Z_STRVAL(name)); } } }