/** * Gets a value from the the internal related entity or from the default value * * @param string $name * @return mixed */ PHP_METHOD(Phalcon_Forms_Form, getValue){ zval *name, *entity, *method, *value = NULL, *data; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(entity); phalcon_read_property(&entity, this_ptr, SL("_entity"), PH_NOISY_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { /** * Check if the entity has a getter */ PHALCON_INIT_VAR(method); PHALCON_CONCAT_SV(method, "get", name); if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD(value, entity, Z_STRVAL_P(method)); RETURN_CCTOR(value); } /** * Check if the entity has a public property */ if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, entity, name, PH_NOISY_CC); RETURN_CCTOR(value); } } PHALCON_OBS_VAR(data); phalcon_read_property(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (Z_TYPE_P(data) == IS_ARRAY) { /** * Check if the data is in the data array */ if (phalcon_array_isset(data, name)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, data, name, PH_NOISY_CC); RETURN_CCTOR(value); } } RETURN_MM_NULL(); }
/** * Reads an attribute value by its name * *<code> * echo $robot->readAttribute('name'); *</code> * * @param string $attribute * @return mixed */ PHP_METHOD(Phalcon_Mvc_Collection_Document, readAttribute){ zval *attribute, *attribute_value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); if (phalcon_isset_property_zval(getThis(), attribute)) { attribute_value = phalcon_read_property_zval(getThis(), attribute, PH_NOISY); RETURN_CTOR(attribute_value); } RETURN_MM_NULL(); }
/** * Returns the value of a field using the ArrayAccess interfase * * @param string $index * @return mixed */ PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetGet){ zval *index, *value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &index); if (phalcon_isset_property_zval(getThis(), index)) { value = phalcon_read_property_zval(getThis(), index, PH_NOISY); RETURN_CTOR(value); } PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); return; }
/** * Reads an attribute value by its name * * @param string $property * @return mixed */ PHP_METHOD(Phalcon_Mvc_Model_Row, readAttribute){ zval *property = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &property) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property_zval(&t0, this_ptr, property, PH_NOISY_CC); RETURN_CCTOR(t0); }
/** * Gets row in a specific position of the row * * @param int $index * @return string|\Phalcon\Mvc\ModelInterface */ PHP_METHOD(Phalcon_Mvc_Model_Row, offsetGet){ zval *index, *value; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { RETURN_MM_NULL(); } if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { PHALCON_OBS_VAR(value); phalcon_read_property_zval(&value, this_ptr, index, PH_NOISY_CC); RETURN_CCTOR(value); } PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The index does not exist in the row"); return; }
/** * Gets the a value to validate in the array/object data source * * @param string $attribute * @return mixed */ PHP_METHOD(Phalcon_Validation, getValue){ zval *attribute, *entity, *method, *value = NULL, *data, *values; zval *filters, *field_filters, *service_name; zval *dependency_injector = NULL, *filter_service; zval *filtered; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); PHALCON_OBS_VAR(entity); phalcon_read_property_this(&entity, this_ptr, SL("_entity"), PH_NOISY_CC); /** * If the entity is an object use it to retrieve the values */ if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_INIT_VAR(method); PHALCON_CONCAT_SV(method, "get", attribute); if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(value); phalcon_call_method_zval(value, entity, method); } else { if (phalcon_method_exists_ex(entity, SS("readattribute") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_NVAR(value); phalcon_call_method(value, entity, "readattribute"); } else { if (phalcon_isset_property_zval(entity, attribute TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, entity, attribute, PH_NOISY_CC); } else { PHALCON_INIT_NVAR(value); } } } RETURN_CCTOR(value); } PHALCON_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (Z_TYPE_P(data) != IS_ARRAY) { if (Z_TYPE_P(data) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There is no data to validate"); return; } } /** * Check if there is a calculated value */ PHALCON_OBS_VAR(values); phalcon_read_property_this(&values, this_ptr, SL("_values"), PH_NOISY_CC); if (phalcon_array_isset(values, attribute)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, values, attribute, PH_NOISY_CC); RETURN_CCTOR(value); } PHALCON_INIT_NVAR(value); if (Z_TYPE_P(data) == IS_ARRAY) { if (phalcon_array_isset(data, attribute)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, data, attribute, PH_NOISY_CC); } } else { if (Z_TYPE_P(data) == IS_OBJECT) { if (phalcon_isset_property_zval(data, attribute TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, data, attribute, PH_NOISY_CC); } } } if (Z_TYPE_P(value) != IS_NULL) { PHALCON_OBS_VAR(filters); phalcon_read_property_this(&filters, this_ptr, SL("_filters"), PH_NOISY_CC); if (Z_TYPE_P(filters) == IS_ARRAY) { if (phalcon_array_isset(filters, attribute)) { PHALCON_OBS_VAR(field_filters); phalcon_array_fetch(&field_filters, filters, attribute, PH_NOISY_CC); if (zend_is_true(field_filters)) { PHALCON_INIT_VAR(service_name); ZVAL_STRING(service_name, "filter", 1); PHALCON_INIT_VAR(dependency_injector); phalcon_call_method(dependency_injector, this_ptr, "getdi"); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_NVAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "A dependency injector is required to obtain the 'filter' service"); return; } } PHALCON_INIT_VAR(filter_service); phalcon_call_method_p1(filter_service, dependency_injector, "getshared", service_name); if (Z_TYPE_P(filter_service) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Returned 'filter' service is invalid"); return; } PHALCON_INIT_VAR(filtered); phalcon_call_method_p2(filtered, filter_service, "sanitize", value, field_filters); RETURN_CCTOR(filtered); } } } /** * Cache the calculated value */ phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC); RETURN_CCTOR(value); } RETURN_MM_NULL(); }