/** * Resolves a service, the resolved service is stored in the DI, subsequent requests for this service will return the same instance * * @param string $name * @param array $parameters * @return mixed */ PHP_METHOD(Phalcon_DI, getShared){ zval *name, *parameters = NULL, *noerror = NULL, instance = {}; phalcon_fetch_params(0, 1, 2, &name, ¶meters, &noerror); PHALCON_ENSURE_IS_STRING(name); if (!parameters) { parameters = &PHALCON_GLOBAL(z_null); } if (!noerror) { noerror = &PHALCON_GLOBAL(z_null); } if (phalcon_isset_property_array(getThis(), SL("_sharedInstances"), name)) { phalcon_return_property_array(&instance, getThis(), SL("_sharedInstances"), name); phalcon_update_property_bool(getThis(), SL("_freshInstance"), 0); } else { PHALCON_CALL_SELFW(&instance, "get", name, parameters, noerror); if (zend_is_true(&instance)) { phalcon_update_property_bool(getThis(), SL("_freshInstance"), 1); phalcon_update_property_array(getThis(), SL("_sharedInstances"), name, &instance); } } RETURN_CTORW(&instance); }
/** * Sets an element in the registry */ PHP_METHOD(Phalcon_Registry, __set){ zval *property, *value; phalcon_fetch_params(0, 2, 0, &property, &value); PHALCON_CALL_SELFW(NULL, "offsetset", property, value); }
PHP_METHOD(Phalcon_Registry, __unset){ zval *property; phalcon_fetch_params(0, 1, 0, &property); PHALCON_CALL_SELFW(NULL, "offsetunset", property); }
/** * Phalcon\DI\FactoryDefault\CLI constructor */ PHP_METHOD(Phalcon_DI_FactoryDefault_CLI, __construct){ zval *shared, name = {}, definition = {}; PHALCON_CALL_PARENTW(NULL, phalcon_di_factorydefault_cli_ce, getThis(), "__construct"); shared = &PHALCON_GLOBAL(z_true); ZVAL_STRING(&name, ISV(router)); ZVAL_STRING(&definition, "Phalcon\\CLI\\Router"); PHALCON_CALL_SELFW(NULL, "set", &name, &definition, shared); ZVAL_STRING(&name, ISV(dispatcher)); ZVAL_STRING(&definition, "Phalcon\\CLI\\Dispatcher"); PHALCON_CALL_SELFW(NULL, "set", &name, &definition, shared); }
/** * Sets values * * @param array $arrayConfig */ PHP_METHOD(Phalcon_Config, val){ zval *array_config, *value; zend_string *str_key; ulong idx; phalcon_fetch_params(0, 1, 0, &array_config); /** * Throw exceptions if bad parameters are passed */ if (Z_TYPE_P(array_config) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_config_exception_ce, "The configuration must be an Array"); return; } ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array_config), idx, str_key, value) { zval key; if (str_key) { ZVAL_STR(&key, str_key); } else { ZVAL_LONG(&key, idx); } PHALCON_CALL_SELFW(NULL, "offsetset", &key, value); } ZEND_HASH_FOREACH_END();
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Between, validate){ zval *validator, *attribute, value = {}, allow_empty = {}, minimum = {}, maximum = {}, label = {}, pairs = {}, valid = {}, message_str = {}, code = {}, prepared = {}, message = {}; zend_class_entry *ce = Z_OBJCE_P(getThis()); phalcon_fetch_params(0, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0); PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty))); if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) { RETURN_TRUE; } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minimum, ce, getThis(), "minimum")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maximum, ce, getThis(), "maximum")); PHALCON_CALL_SELFW(&valid, "valid", &value, &minimum, &maximum); if (PHALCON_IS_FALSE(&valid)) { RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label))); if (!zend_is_true(&label)) { PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute); if (!zend_is_true(&label)) { PHALCON_CPY_WRT_CTOR(&label, attribute); } } array_init_size(&pairs, 3); phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY); phalcon_array_update_str(&pairs, SL(":min"), &minimum, PH_COPY); phalcon_array_update_str(&pairs, SL(":max"), &maximum, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "Between")); } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code))); if (Z_TYPE_P(&code) == IS_NULL) { ZVAL_LONG(&code, 0); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "Between", &code); PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message); RETURN_FALSE; } RETURN_TRUE; }
/** * Phalcon\Config constructor * * @param array $arrayConfig */ PHP_METHOD(Phalcon_Config, __construct){ zval *array_config = NULL; phalcon_fetch_params(0, 0, 1, &array_config); /** * Throw exceptions if bad parameters are passed */ if (array_config && Z_TYPE_P(array_config) != IS_ARRAY && Z_TYPE_P(array_config) != IS_NULL) { PHALCON_THROW_EXCEPTION_STRW(phalcon_config_exception_ce, "The configuration must be an Array"); return; } if (array_config && Z_TYPE_P(array_config) == IS_ARRAY) { PHALCON_CALL_SELFW(NULL, "val", array_config); } }
/** * * @param string $session_id optional, session id * * @return boolean */ PHP_METHOD(Phalcon_Session_Adapter_Memcache, destroy){ zval *_sid = NULL, sid = {}, *memcache; phalcon_fetch_params(0, 0, 1, &_sid); if (!_sid) { PHALCON_CALL_SELFW(&sid, "getid"); } else { PHALCON_CPY_WRT(&sid, _sid); } memcache = phalcon_read_property(getThis(), SL("_memcache"), PH_NOISY); if (Z_TYPE_P(memcache) == IS_OBJECT) { PHALCON_RETURN_CALL_METHODW(memcache, "delete", &sid); return; } else { RETURN_FALSE; } }
/** * Magic method to get or set services using setters/getters * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_DI, __call){ zval *method, *arguments = NULL, possible_service = {}, name = {}, definition = {}; phalcon_fetch_params(0, 1, 1, &method, &arguments); PHALCON_ENSURE_IS_STRING(method); if (!arguments) { arguments = &PHALCON_GLOBAL(z_null); } phalcon_substr(&possible_service, method, 3, 0); phalcon_lcfirst(&name, &possible_service); /** * If the magic method starts with "get" we try to get a service with that name */ if (phalcon_start_with_str(method, SL("get"))) { if (phalcon_isset_property_array(getThis(), SL("_services"), &name)) { PHALCON_RETURN_CALL_SELFW("get", &name, arguments); return; } } /** * If the magic method starts with "set" we try to set a service using that name */ if (phalcon_start_with_str(method, SL("set"))) { if (phalcon_array_isset_fetch_long(&definition, arguments, 0)) { PHALCON_CALL_SELFW(NULL, "set", &name, &definition); return; } } /** * The method doesn't start with set/get throw an exception */ zend_throw_exception_ex(phalcon_di_exception_ce, 0, "Call to undefined method or service '%s'", Z_STRVAL_P(method)); }
PHP_METHOD(Phalcon_Http_Uri, extend) { zval *uri, parts = {}, self = {}, parts2 = {}; phalcon_fetch_params(0, 1, 0, &uri); PHALCON_CALL_SELFW(&parts, "getParts"); if (Z_TYPE_P(uri) != IS_OBJECT || Z_OBJCE_P(uri) != phalcon_http_uri_ce) { object_init_ex(&self, phalcon_http_uri_ce); PHALCON_CALL_METHODW(NULL, &self, "__construct", uri); PHALCON_CALL_METHODW(&parts2, &self, "getParts"); } else { PHALCON_CALL_METHODW(&parts2, &self, "getParts"); } phalcon_array_merge_recursive_n(&parts, &parts2); phalcon_update_property_zval(getThis(), SL("_parts"), &parts); RETURN_THISW(); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_File, validate) { zval *validator, *attribute, value = {}, allow_empty = {}, mimes = {}, minsize = {}, maxsize = {}, minwidth = {}, maxwidth = {}, minheight = {}, maxheight = {}; zval valid = {}, type = {}, code = {}, message_str = {}, message = {}, join_mimes = {}, label = {}, pairs = {}, prepared = {}; zend_class_entry *ce = Z_OBJCE_P(getThis()); phalcon_fetch_params(0, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0); PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty))); if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) { RETURN_TRUE; } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&mimes, ce, getThis(), "mimes")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minsize, ce, getThis(), "minsize")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxsize, ce, getThis(), "maxsize")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minwidth, ce, getThis(), "minwidth")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxwidth, ce, getThis(), "maxwidth")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minheight, ce, getThis(), "minheight")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxheight, ce, getThis(), "maxheight")); PHALCON_CALL_SELFW(&valid, "valid", &value, &minsize, &maxsize, &mimes, &minwidth, &maxwidth, &minheight, &maxheight); if (PHALCON_IS_FALSE(&valid)) { phalcon_return_property(&type, getThis(), SL("_type")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label))); if (!zend_is_true(&label)) { PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute); if (!zend_is_true(&label)) { PHALCON_CPY_WRT_CTOR(&label, attribute); } } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code))); if (Z_TYPE(code) == IS_NULL) { ZVAL_LONG(&code, 0); } array_init(&pairs); phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY); if (phalcon_compare_strict_string(&type, SL("TooLarge"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMaxSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLarge", &code); } else if (phalcon_compare_strict_string(&type, SL("TooSmall"))) { phalcon_array_update_str(&pairs, SL(":min"), &minsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMinSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooSmall", &code); } else if (phalcon_compare_strict_string(&type, SL("MimeValid"))) { phalcon_fast_join_str(&join_mimes, SL(", "), &mimes); phalcon_array_update_str(&pairs, SL(":mimes"), &join_mimes, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileType")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "FileType", &code); } else if (phalcon_compare_strict_string(&type, SL("TooLarge"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMaxSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLarge", &code); } else if (phalcon_compare_strict_string(&type, SL("TooNarrow"))) { phalcon_array_update_str(&pairs, SL(":min"), &minwidth, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMinWidth")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooNarrow", &code); } else if (phalcon_compare_strict_string(&type, SL("TooWide"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxwidth, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMaxWidth")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooWide", &code); } else if (phalcon_compare_strict_string(&type, SL("TooShort"))) { phalcon_array_update_str(&pairs, SL(":min"), &minheight, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMinHeight")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooShort", &code); } else if (phalcon_compare_strict_string(&type, SL("TooLong"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxheight, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMaxHeight")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLong", &code); } else { RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileValid")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "File", &code); } PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message); RETURN_FALSE; } RETURN_TRUE; }