int phalcon_array_update_long_bool(zval **arr, ulong index, int value, int flags TSRMLS_DC){ zval *zvalue; ALLOC_INIT_ZVAL(zvalue); ZVAL_BOOL(zvalue, value); return phalcon_array_update_long(arr, index, &zvalue, flags TSRMLS_CC); }
/** * Updates multi-dimensional arrays with one long index and other string * * $foo[10]["lol"] = $x */ void phalcon_array_update_long_string_multi_2(zval **arr, long index1, char *index2, uint index2_length, zval **value, int flags TSRMLS_DC){ zval *temp; if (Z_TYPE_PP(arr) == IS_ARRAY) { phalcon_array_fetch_long(&temp, *arr, index1, PH_SILENT_CC); if (Z_REFCOUNT_P(temp) > 1) { phalcon_array_update_long(arr, index1, &temp, PH_COPY | PH_CTOR TSRMLS_CC); } if (Z_TYPE_P(temp) != IS_ARRAY) { convert_to_array(temp); phalcon_array_update_long(arr, index1, &temp, PH_COPY TSRMLS_CC); } phalcon_array_update_string(&temp, index2, index2_length, value, flags | PH_COPY TSRMLS_CC); zval_ptr_dtor(&temp); } }
int phalcon_array_update_long_string(zval **arr, ulong index, char *value, uint value_length, int flags TSRMLS_DC){ zval *zvalue; ALLOC_INIT_ZVAL(zvalue); ZVAL_STRINGL(zvalue, value, value_length, 1); return phalcon_array_update_long(arr, index, &zvalue, flags TSRMLS_CC); }
/** * Updates an array with a long value in a long index */ int phalcon_array_update_long_long(zval **arr, unsigned long index, long value, int flags TSRMLS_DC){ zval *zvalue; ALLOC_INIT_ZVAL(zvalue); ZVAL_LONG(zvalue, value); return phalcon_array_update_long(arr, index, &zvalue, flags TSRMLS_CC); }
/** * Updates multi-dimensional arrays with two long indices * * $foo[10][4] = $x */ void phalcon_array_update_long_long_multi_2(zval **arr, long index1, long index2, zval **value, int flags TSRMLS_DC){ zval *temp; ALLOC_INIT_ZVAL(temp); if (Z_TYPE_PP(arr) == IS_ARRAY) { phalcon_array_fetch_long(&temp, *arr, index1, PH_SILENT_CC); if (Z_REFCOUNT_P(temp) > 1) { phalcon_array_update_long(arr, index1, &temp, PH_COPY | PH_CTOR TSRMLS_CC); } if (Z_TYPE_P(temp) != IS_ARRAY) { convert_to_array(temp); phalcon_array_update_long(arr, index1, &temp, PH_COPY TSRMLS_CC); } phalcon_array_update_long(&temp, index2, value, flags | PH_COPY TSRMLS_CC); } zval_ptr_dtor(&temp); }
PHP_METHOD(Phalcon_Internal_TestTemp, e9a){ zval *a = NULL; zval *a0 = NULL; zval *t0 = NULL; PHALCON_MM_GROW(); PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(a, a0); PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, "LOL", 1); phalcon_array_update_long(&a, 0, &t0, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_RETURN_CTOR(a); }
/** * Builds a HTML TEXTAREA tag * *<code> * echo Phalcon\Tag::textArea(array("comments", "cols" => 10, "rows" => 4)) *</code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, textArea){ zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; zval *avalue = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { eval_int = phalcon_array_isset_string(params, SS("id")); if (eval_int) { PHALCON_INIT_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_string(params, SS("name")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } eval_int = phalcon_array_isset_string(params, SS("id")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } eval_int = phalcon_array_isset_string(params, SS("value")); if (eval_int) { PHALCON_INIT_VAR(content); phalcon_array_fetch_string(&content, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("value")); } else { PHALCON_INIT_NVAR(content); PHALCON_CALL_SELF_PARAMS_1(content, this_ptr, "getvalue", id); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<textarea", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_SCONCAT_SVS(code, ">", content, "</textarea>"); RETURN_CTOR(code); }
/** * Builds generic INPUT tags * * @param string $type * @param array $parameters * @param boolean $asValue * @return string */ PHP_METHOD(Phalcon_Tag, _inputField){ zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL; zval *id = NULL, *name, *code, *key = NULL, *five, *doctype, *is_xhtml; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &type, ¶meters, &as_value); if (!as_value) { PHALCON_INIT_VAR(as_value); ZVAL_BOOL(as_value, 0); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 1); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(value); if (PHALCON_IS_FALSE(as_value)) { if (!phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_OBS_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); if (!phalcon_array_isset_string(params, SS("name"))) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } /** * Automatically assign the id if the name is not an array */ if (!phalcon_memnstr_str(id, SL("[") TSRMLS_CC)) { if (!phalcon_array_isset_string(params, SS("id"))) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } if (!phalcon_array_isset_string(params, SS("value"))) { PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch_long(&value, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } /** * Automatically check inputs */ if (PHALCON_IS_STRING(type, "checkbox")) { if (zend_is_true(value)) { phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } else { if (PHALCON_IS_STRING(type, "radio")) { if (zend_is_true(value)) { phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<input type=\"", type, "\""); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(five); ZVAL_LONG(five, 5); PHALCON_OBS_VAR(doctype); phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); /** * Check if Doctype is XHTML */ PHALCON_INIT_VAR(is_xhtml); is_smaller_function(is_xhtml, five, doctype TSRMLS_CC); if (zend_is_true(is_xhtml)) { phalcon_concat_self_str(&code, SL(" />") TSRMLS_CC); } else { phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); } RETURN_CTOR(code); }
/** * Returns an array of prepared attributes for Phalcon\Tag helpers * according to the element's parameters * * @param array $attributes * @param boolean $useChecked * @return array */ PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ zval *attributes = NULL, *use_checked = NULL, *name, *widget_attributes = NULL; zval *default_attributes, *merged_attributes = NULL; zval *value, *current_value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &attributes, &use_checked); if (!attributes) { PHALCON_INIT_VAR(attributes); } if (!use_checked) { PHALCON_INIT_VAR(use_checked); ZVAL_BOOL(use_checked, 0); } PHALCON_OBS_VAR(name); phalcon_read_property_this(&name, this_ptr, SL("_name"), PH_NOISY_CC); /** * Create an array of parameters */ if (Z_TYPE_P(attributes) != IS_ARRAY) { PHALCON_INIT_VAR(widget_attributes); array_init(widget_attributes); } else { PHALCON_CPY_WRT(widget_attributes, attributes); } phalcon_array_update_long(&widget_attributes, 0, &name, PH_COPY | PH_SEPARATE TSRMLS_CC); /** * Merge passed parameters with default ones */ PHALCON_OBS_VAR(default_attributes); phalcon_read_property_this(&default_attributes, this_ptr, SL("_attributes"), PH_NOISY_CC); if (Z_TYPE_P(default_attributes) == IS_ARRAY) { PHALCON_INIT_VAR(merged_attributes); phalcon_fast_array_merge(merged_attributes, &default_attributes, &widget_attributes TSRMLS_CC); } else { PHALCON_CPY_WRT(merged_attributes, widget_attributes); } /** * Get the current element's value */ PHALCON_INIT_VAR(value); phalcon_call_method(value, this_ptr, "getvalue"); /** * If the widget has a value set it as default value */ if (Z_TYPE_P(value) != IS_NULL) { if (zend_is_true(use_checked)) { /** * Check if the element already has a default value, compare it with the one in the * attributes, if they are the same mark the element as checked */ if (phalcon_array_isset_string(merged_attributes, SS("value"))) { PHALCON_OBS_VAR(current_value); phalcon_array_fetch_string(¤t_value, merged_attributes, SL("value"), PH_NOISY_CC); if (PHALCON_IS_EQUAL(current_value, value)) { phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } else { /** * Evaluate the current value and mark the check as checked */ if (zend_is_true(value)) { phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } phalcon_array_update_string(&merged_attributes, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { phalcon_array_update_string(&merged_attributes, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } RETURN_CCTOR(merged_attributes); }
/** * The meta-data is obtained by reading the column descriptions from the database information schema * * @param Phalcon\Mvc\ModelInterface $model * @param Phalcon\DiInterface $dependencyInjector * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getMetaData) { zval *model, *dependency_injector, *class_name; zval *schema, *table, *read_connection, *exists; zval *complete_table = NULL, *exception_message = NULL; zval *columns, *attributes, *primary_keys, *non_primary_keys; zval *numeric_typed, *not_null, *field_types; zval *field_bind_types, *automatic_default; zval *identity_field = NULL, *column = NULL, *field_name = NULL, *feature = NULL; zval *type = NULL, *bind_type = NULL, *model_metadata; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model, 0 TSRMLS_CC); PHALCON_INIT_VAR(schema); phalcon_call_method(schema, model, "getschema"); PHALCON_INIT_VAR(table); phalcon_call_method(table, model, "getsource"); /** * Check if the mapped table exists on the database */ PHALCON_INIT_VAR(read_connection); phalcon_call_method(read_connection, model, "getreadconnection"); PHALCON_INIT_VAR(exists); phalcon_call_method_p2(exists, read_connection, "tableexists", table, schema); if (!zend_is_true(exists)) { if (zend_is_true(schema)) { PHALCON_INIT_VAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } /** * The table not exists */ PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVSV(exception_message, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Try to describe the table */ PHALCON_INIT_VAR(columns); phalcon_call_method_p2(columns, read_connection, "describecolumns", table, schema); if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { if (zend_is_true(schema)) { PHALCON_INIT_NVAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } /** * The table not exists */ PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSV(exception_message, "Cannot obtain table columns for the mapped source \"", complete_table, "\" used in model ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Initialize meta-data */ PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(field_bind_types); array_init(field_bind_types); PHALCON_INIT_VAR(automatic_default); array_init(automatic_default); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(column); PHALCON_INIT_NVAR(field_name); phalcon_call_method(field_name, column, "getname"); phalcon_array_append(&attributes, field_name, PH_SEPARATE); /** * To mark fields as primary keys */ PHALCON_INIT_NVAR(feature); phalcon_call_method(feature, column, "isprimary"); if (PHALCON_IS_TRUE(feature)) { phalcon_array_append(&primary_keys, field_name, PH_SEPARATE); } else { phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE); } /** * To mark fields as numeric */ PHALCON_INIT_NVAR(feature); phalcon_call_method(feature, column, "isnumeric"); if (PHALCON_IS_TRUE(feature)) { phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE); } /** * To mark fields as not null */ PHALCON_INIT_NVAR(feature); phalcon_call_method(feature, column, "isnotnull"); if (PHALCON_IS_TRUE(feature)) { phalcon_array_append(¬_null, field_name, PH_SEPARATE); } /** * To mark fields as identity columns */ PHALCON_INIT_NVAR(feature); phalcon_call_method(feature, column, "isautoincrement"); if (PHALCON_IS_TRUE(feature)) { PHALCON_CPY_WRT(identity_field, field_name); } /** * To get the internal types */ PHALCON_INIT_NVAR(type); phalcon_call_method(type, column, "gettype"); phalcon_array_update_zval(&field_types, field_name, &type, PH_COPY | PH_SEPARATE); /** * To mark how the fields must be escaped */ PHALCON_INIT_NVAR(bind_type); phalcon_call_method(bind_type, column, "getbindtype"); phalcon_array_update_zval(&field_bind_types, field_name, &bind_type, PH_COPY | PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } /** * Create an array using the MODELS_* constants as indexes */ PHALCON_INIT_VAR(model_metadata); array_init(model_metadata); phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); RETURN_CTOR(model_metadata); }
/** * Initialize the metadata for certain table * * @param Phalcon\Mvc\Model $model * @param string $table * @param string $schema */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initializeMetaData){ zval *model = NULL, *table = NULL, *schema = NULL, *key = NULL, *connection = NULL, *exists = NULL; zval *complete_table = NULL, *attributes = NULL, *primary_keys = NULL; zval *non_primary_keys = NULL, *numeric_typed = NULL, *not_null = NULL; zval *field_types = NULL, *identity_field = NULL, *columns = NULL; zval *column = NULL, *field_name = NULL, *table_metadata = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *i0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *a0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(key); PHALCON_CONCAT_VV(key, schema, table); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PH_NOISY_CC); eval_int = phalcon_array_isset(t0, key); if (!eval_int) { PHALCON_INIT_VAR(connection); PHALCON_CALL_METHOD(connection, model, "getconnection", PH_NO_CHECK); PHALCON_INIT_VAR(exists); PHALCON_CALL_METHOD_PARAMS_2(exists, connection, "tableexists", table, schema, PH_NO_CHECK); if (!zend_is_true(exists)) { if (zend_is_true(schema)) { PHALCON_INIT_VAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_mvc_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_get_class(r0, model TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CONCAT_SVSV(r1, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", r0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); PHALCON_INIT_VAR(columns); PHALCON_CALL_METHOD_PARAMS_2(columns, connection, "describecolumns", table, schema, PH_NO_CHECK); if (!phalcon_valid_foreach(columns TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(columns); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_c40c_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_c40c_0; } PHALCON_INIT_VAR(column); ZVAL_ZVAL(column, *hd, 1, 0); PHALCON_INIT_VAR(field_name); PHALCON_CALL_METHOD(field_name, column, "getname", PH_NO_CHECK); phalcon_array_append(&attributes, field_name, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(r2); PHALCON_CALL_METHOD(r2, column, "isprimary", PH_NO_CHECK); if (zend_is_true(r2)) { phalcon_array_append(&primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r3); PHALCON_CALL_METHOD(r3, column, "isnumeric", PH_NO_CHECK); if (zend_is_true(r3)) { phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r4); PHALCON_CALL_METHOD(r4, column, "isnotnull", PH_NO_CHECK); if (zend_is_true(r4)) { phalcon_array_append(¬_null, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r5); PHALCON_CALL_METHOD(r5, column, "isautoincrement", PH_NO_CHECK); if (zend_is_true(r5)) { PHALCON_CPY_WRT(identity_field, field_name); } PHALCON_INIT_VAR(r6); PHALCON_CALL_METHOD(r6, column, "gettype", PH_NO_CHECK); phalcon_array_update_zval(&field_types, field_name, &r6, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_c40c_0; fee_c40c_0: if(0){} PHALCON_INIT_VAR(table_metadata); array_init(table_metadata); phalcon_array_update_long(&table_metadata, 0, &attributes, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_metaData"), PH_NOISY_CC); phalcon_array_update_zval(&t1, key, &table_metadata, PH_COPY TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_changed"), PH_NOISY_CC); if (!zend_is_true(t2)) { PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); phalcon_array_append(&a0, this_ptr, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(a0, SL("storeMetaData"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("register_shutdown_function", a0); phalcon_update_property_bool(this_ptr, SL("_changed"), 1 TSRMLS_CC); } } PHALCON_MM_RESTORE(); }
/** * The meta-data is obtained by reading the column descriptions from the database information schema * * @param Phalcon\Mvc\ModelInterface $model * @param Phalcon\DiInterface $dependencyInjector * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getMetaData){ zval *model, *dependency_injector, *service; zval *annotations = NULL, *class_name, *reflection = NULL; zval *exception_message = NULL, *properties_annotations = NULL; zval *attributes, *primary_keys, *non_primary_keys; zval *numeric_typed, *not_null, *field_types, *field_sizes, *field_bytes, *field_scales; zval *field_bind_types, *automatic_create_attributes, *automatic_update_attributes; zval *identity_field = NULL, *column_annot_name; zval *primary_annot_name, *id_annot_name; zval *column_map_name, *column_type_name, *column_size_name, *column_bytes_name, *column_scale_name, *column_nullable_name; zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL; zval *column_annotation = NULL, *real_property = NULL, *feature = NULL; zval *field_default_values, *column_default_value = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "annotations", 1); PHALCON_CALL_METHOD(&annotations, dependency_injector, "get", service); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model, 0 TSRMLS_CC); PHALCON_CALL_METHOD(&reflection, annotations, "get", class_name); if (Z_TYPE_P(reflection) != IS_OBJECT) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Get the properties defined in */ PHALCON_CALL_METHOD(&properties_annotations, reflection, "getpropertiesannotations"); if (!zend_is_true(properties_annotations) || !phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Initialize meta-data */ PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(field_sizes); array_init(field_sizes); PHALCON_INIT_VAR(field_bytes); array_init(field_bytes); PHALCON_INIT_VAR(field_scales); array_init(field_scales); PHALCON_INIT_VAR(field_bind_types); array_init(field_bind_types); PHALCON_INIT_VAR(automatic_create_attributes); array_init(automatic_create_attributes); PHALCON_INIT_VAR(automatic_update_attributes); array_init(automatic_update_attributes); PHALCON_INIT_VAR(identity_field); ZVAL_FALSE(identity_field); PHALCON_INIT_VAR(field_default_values); array_init(field_default_values); PHALCON_INIT_VAR(column_annot_name); ZVAL_STRING(column_annot_name, "Column", 1); PHALCON_INIT_VAR(primary_annot_name); ZVAL_STRING(primary_annot_name, "Primary", 1); PHALCON_INIT_VAR(id_annot_name); ZVAL_STRING(id_annot_name, "Identity", 1); PHALCON_INIT_VAR(column_map_name); ZVAL_STRING(column_map_name, "column", 1); PHALCON_INIT_VAR(column_type_name); ZVAL_STRING(column_type_name, "type", 1); PHALCON_INIT_VAR(column_size_name); ZVAL_STRING(column_size_name, "size", 1); PHALCON_INIT_VAR(column_bytes_name); ZVAL_STRING(column_bytes_name, "bytes", 1); PHALCON_INIT_VAR(column_scale_name); ZVAL_STRING(column_scale_name, "scale", 1); PHALCON_INIT_VAR(column_default_value); ZVAL_STRING(column_default_value, "default", 1); PHALCON_INIT_VAR(column_nullable_name); ZVAL_STRING(column_nullable_name, "nullable", 1); phalcon_is_iterable(properties_annotations, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(property, ah0, hp0); PHALCON_GET_HVALUE(prop_annotations); /** * All columns marked with the 'Column' annotation are considered columns */ PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", column_annot_name); if (!zend_is_true(has_annotation)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Fetch the 'column' annotation */ PHALCON_CALL_METHOD(&column_annotation, prop_annotations, "get", column_annot_name); /** * Check column map */ PHALCON_CALL_METHOD(&real_property, column_annotation, "getargument", column_map_name); if (PHALCON_IS_EMPTY(real_property)) { PHALCON_CPY_WRT(real_property, property); } /** * Check if annotation has the 'type' named parameter */ PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_type_name); if (PHALCON_IS_STRING(feature, "integer")) { phalcon_array_update_zval_long(&field_types, real_property, 0, PH_COPY); phalcon_array_update_zval_long(&field_bind_types, real_property, 1, PH_COPY); phalcon_array_update_zval_bool(&numeric_typed, real_property, 1, PH_COPY); } else if (PHALCON_IS_STRING(feature, "decimal")) { phalcon_array_update_zval_long(&field_types, real_property, 3, PH_COPY); phalcon_array_update_zval_long(&field_bind_types, real_property, 32, PH_COPY); phalcon_array_update_zval_bool(&numeric_typed, real_property, 1, PH_COPY); } else if (PHALCON_IS_STRING(feature, "boolean")) { phalcon_array_update_zval_long(&field_types, real_property, 8, PH_COPY); phalcon_array_update_zval_long(&field_bind_types, real_property, 5, PH_COPY); } else { if (PHALCON_IS_STRING(feature, "date")) { phalcon_array_update_zval_long(&field_types, real_property, 1, PH_COPY); } else { /** * By default all columns are varchar/string */ phalcon_array_update_zval_long(&field_types, real_property, 2, PH_COPY); } phalcon_array_update_zval_long(&field_bind_types, real_property, 2, PH_COPY); } PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_size_name); if (!PHALCON_IS_EMPTY(feature)) { phalcon_array_update_zval(&field_sizes, real_property, feature, PH_COPY); phalcon_array_update_zval(&field_bytes, real_property, feature, PH_COPY); } PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_bytes_name); if (!PHALCON_IS_EMPTY(feature)) { phalcon_array_update_zval(&field_bytes, real_property, feature, PH_COPY); } PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_scale_name); if (!PHALCON_IS_EMPTY(feature)) { phalcon_array_update_zval(&field_scales, real_property, feature, PH_COPY); } PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_default_value); if (!PHALCON_IS_EMPTY(feature)) { phalcon_array_update_zval(&field_default_values, real_property, feature, PH_COPY); } PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_default_value); if (!PHALCON_IS_EMPTY(feature)) { phalcon_array_update_zval(&field_default_values, property, feature, PH_COPY); } PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_default_value); if (!PHALCON_IS_EMPTY(feature)) { phalcon_array_update_zval(&field_default_values, property, feature, PH_COPY); } /** * All columns marked with the 'Primary' annotation are considered primary keys */ PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", primary_annot_name); if (zend_is_true(has_annotation)) { phalcon_array_append(&primary_keys, real_property, PH_COPY); } else { phalcon_array_append(&non_primary_keys, real_property, PH_COPY); } /** * All columns marked with the 'Primary' annotation are considered primary keys */ PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", id_annot_name); if (zend_is_true(has_annotation)) { PHALCON_CPY_WRT(identity_field, real_property); } /** * Check if the column */ PHALCON_CALL_METHOD(&feature, column_annotation, "getargument", column_nullable_name); if (!zend_is_true(feature)) { phalcon_array_append(¬_null, real_property, PH_COPY); } phalcon_array_append(&attributes, real_property, PH_COPY); zend_hash_move_forward_ex(ah0, &hp0); } /** * Create an array using the MODELS_* constants as indexes */ array_init_size(return_value, 14); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_ATTRIBUTES, attributes, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_PRIMARY_KEY, primary_keys, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_NON_PRIMARY_KEY, non_primary_keys, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_NOT_NULL, not_null, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_TYPES, field_types, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_TYPES_NUMERIC, numeric_typed, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_IDENTITY_COLUMN, identity_field, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_TYPES_BIND, field_bind_types, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_AUTOMATIC_DEFAULT_INSERT, automatic_create_attributes, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_AUTOMATIC_DEFAULT_UPDATE, automatic_update_attributes, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_DEFAULT_VALUE, field_default_values, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_SZIE, field_sizes, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_SCALE, field_scales, PH_COPY); phalcon_array_update_long(&return_value, PHALCON_MVC_MODEL_METADATA_MODELS_DATA_BYTE, field_bytes, PH_COPY); PHALCON_MM_RESTORE(); }
/** * Read the model's column map, this can't be inferred * * @param Phalcon\Mvc\ModelInterface $model * @param Phalcon\DiInterface $dependencyInjector * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getColumnMaps){ zval *model, *dependency_injector, *service; zval *ordered_column_map, *reversed_column_map = NULL; zval *annotations = NULL, *class_name, *reflection = NULL; zval *exception_message = NULL, *properties_annotations = NULL; zval *column_annot_name, *column_map_name; zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL; zval *column_annotation = NULL, *real_property = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); if (!PHALCON_GLOBAL(orm).column_renaming) { RETURN_MM_NULL(); } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "annotations", 1); PHALCON_CALL_METHOD(&annotations, dependency_injector, "get", service); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model, 0 TSRMLS_CC); PHALCON_CALL_METHOD(&reflection, annotations, "get", class_name); if (Z_TYPE_P(reflection) != IS_OBJECT) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Get the properties defined in */ PHALCON_CALL_METHOD(&properties_annotations, reflection, "getpropertiesannotations"); if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Initialize meta-data */ PHALCON_INIT_VAR(ordered_column_map); array_init(ordered_column_map); PHALCON_INIT_VAR(reversed_column_map); array_init(reversed_column_map); PHALCON_INIT_VAR(column_annot_name); ZVAL_STRING(column_annot_name, "Column", 1); PHALCON_INIT_VAR(column_map_name); ZVAL_STRING(column_map_name, "column", 1); phalcon_is_iterable(properties_annotations, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(property, ah0, hp0); PHALCON_GET_HVALUE(prop_annotations); /** * All columns marked with the 'Column' annotation are considered columns */ PHALCON_CALL_METHOD(&has_annotation, prop_annotations, "has", column_annot_name); if (!zend_is_true(has_annotation)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Fetch the 'column' annotation */ PHALCON_CALL_METHOD(&column_annotation, prop_annotations, "get", column_annot_name); /** * Check column map */ PHALCON_CALL_METHOD(&real_property, column_annotation, "getargument", column_map_name); if (!PHALCON_IS_EMPTY(real_property)) { phalcon_array_update_zval(&ordered_column_map, real_property, property, PH_COPY); phalcon_array_update_zval(&reversed_column_map, property, real_property, PH_COPY); } else { phalcon_array_update_zval(&ordered_column_map, property, property, PH_COPY); phalcon_array_update_zval(&reversed_column_map, property, property, PH_COPY); } zend_hash_move_forward_ex(ah0, &hp0); } array_init_size(return_value, 2); phalcon_array_update_long(&return_value, 0, ordered_column_map, PH_COPY); phalcon_array_update_long(&return_value, 1, reversed_column_map, PH_COPY); PHALCON_MM_RESTORE(); }
/** * Read the model's column map, this can't be infered * * @param Phalcon\Mvc\ModelInterface $model * @param Phalcon\DiInterface $dependencyInjector * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getColumnMaps){ zval *model, *dependency_injector; zval *ordered_column_map = NULL, *columns = NULL, *column_name = NULL, *reversed_column_map = NULL; zval *user_name = NULL, *name = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); if (!PHALCON_GLOBAL(orm).column_renaming) { RETURN_MM_NULL(); } /** * Check for a columnMap() method on the model */ if (phalcon_method_exists_ex(model, SS("columnmap") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(&ordered_column_map, model, "columnmap"); if (Z_TYPE_P(ordered_column_map) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array"); return; } PHALCON_CALL_METHOD(&columns, model, "getcolumns"); if (Z_TYPE_P(columns) == IS_ARRAY) { phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(column_name); if (!phalcon_array_isset(ordered_column_map, column_name)) { phalcon_array_update_zval(&ordered_column_map, column_name, column_name, PH_COPY); } zend_hash_move_forward_ex(ah0, &hp0); } } PHALCON_INIT_VAR(reversed_column_map); array_init(reversed_column_map); phalcon_is_iterable(ordered_column_map, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_HKEY(name, ah1, hp1); PHALCON_GET_HVALUE(user_name); phalcon_array_update_zval(&reversed_column_map, user_name, name, PH_COPY); zend_hash_move_forward_ex(ah1, &hp1); } } else { PHALCON_INIT_NVAR(ordered_column_map); PHALCON_INIT_VAR(reversed_column_map); } /** * Store the column map */ array_init_size(return_value, 2); phalcon_array_update_long(&return_value, 0, ordered_column_map, PH_COPY); phalcon_array_update_long(&return_value, 1, reversed_column_map, PH_COPY); PHALCON_MM_RESTORE(); }
/** * The meta-data is obtained by reading the column descriptions from the database information schema * * @param Phalcon\Mvc\ModelInterface $model * @param Phalcon\DiInterface $dependencyInjector * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getMetaData){ zval *model, *dependency_injector, *service; zval *annotations, *class_name, *reflection; zval *exception_message = NULL, *properties_annotations; zval *attributes, *primary_keys, *non_primary_keys; zval *numeric_typed, *not_null, *field_types; zval *field_bind_types, *automatic_default; zval *identity_field = NULL, *column_annot_name; zval *primary_annot_name, *id_annot_name; zval *column_type_name, *column_nullable_name; zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL; zval *column_annotation = NULL, *feature = NULL, *model_metadata; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "annotations", 1); PHALCON_INIT_VAR(annotations); phalcon_call_method_p1(annotations, dependency_injector, "get", service); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model, 0 TSRMLS_CC); PHALCON_INIT_VAR(reflection); phalcon_call_method_p1(reflection, annotations, "get", class_name); if (Z_TYPE_P(reflection) != IS_OBJECT) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Get the properties defined in */ PHALCON_INIT_VAR(properties_annotations); phalcon_call_method(properties_annotations, reflection, "getpropertiesannotations"); if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Initialize meta-data */ PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(field_bind_types); array_init(field_bind_types); PHALCON_INIT_VAR(automatic_default); array_init(automatic_default); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); PHALCON_INIT_VAR(column_annot_name); ZVAL_STRING(column_annot_name, "Column", 1); PHALCON_INIT_VAR(primary_annot_name); ZVAL_STRING(primary_annot_name, "Primary", 1); PHALCON_INIT_VAR(id_annot_name); ZVAL_STRING(id_annot_name, "Identity", 1); PHALCON_INIT_VAR(column_type_name); ZVAL_STRING(column_type_name, "type", 1); PHALCON_INIT_VAR(column_nullable_name); ZVAL_STRING(column_nullable_name, "nullable", 1); phalcon_is_iterable(properties_annotations, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(property, ah0, hp0); PHALCON_GET_HVALUE(prop_annotations); /** * All columns marked with the 'Column' annotation are considered columns */ PHALCON_INIT_NVAR(has_annotation); phalcon_call_method_p1(has_annotation, prop_annotations, "has", column_annot_name); if (!zend_is_true(has_annotation)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Fetch the 'column' annotation */ PHALCON_INIT_NVAR(column_annotation); phalcon_call_method_p1(column_annotation, prop_annotations, "get", column_annot_name); /** * Check if annotation has the 'type' named parameter */ PHALCON_INIT_NVAR(feature); phalcon_call_method_p1(feature, column_annotation, "getnamedparameter", column_type_name); if (PHALCON_IS_STRING(feature, "integer")) { phalcon_array_update_zval_long(&field_types, property, 0, PH_SEPARATE); phalcon_array_update_zval_long(&field_bind_types, property, 1, PH_SEPARATE); phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); } else { if (PHALCON_IS_STRING(feature, "decimal")) { phalcon_array_update_zval_long(&field_types, property, 3, PH_SEPARATE); phalcon_array_update_zval_long(&field_bind_types, property, 32, PH_SEPARATE); phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); } else { if (PHALCON_IS_STRING(feature, "boolean")) { phalcon_array_update_zval_long(&field_types, property, 8, PH_SEPARATE); phalcon_array_update_zval_long(&field_bind_types, property, 5, PH_SEPARATE); } else { if (PHALCON_IS_STRING(feature, "date")) { phalcon_array_update_zval_long(&field_types, property, 1, PH_SEPARATE); } else { /** * By default all columns are varchar/string */ phalcon_array_update_zval_long(&field_types, property, 2, PH_SEPARATE); } phalcon_array_update_zval_long(&field_bind_types, property, 2, PH_SEPARATE); } } } /** * All columns marked with the 'Primary' annotation are considered primary keys */ PHALCON_INIT_NVAR(has_annotation); phalcon_call_method_p1(has_annotation, prop_annotations, "has", primary_annot_name); if (zend_is_true(has_annotation)) { phalcon_array_append(&primary_keys, property, PH_SEPARATE); } else { phalcon_array_append(&non_primary_keys, property, PH_SEPARATE); } /** * All columns marked with the 'Primary' annotation are considered primary keys */ PHALCON_INIT_NVAR(has_annotation); phalcon_call_method_p1(has_annotation, prop_annotations, "has", id_annot_name); if (zend_is_true(has_annotation)) { PHALCON_CPY_WRT(identity_field, property); } /** * Check if the column */ PHALCON_INIT_NVAR(feature); phalcon_call_method_p1(feature, column_annotation, "getnamedparameter", column_nullable_name); if (!zend_is_true(feature)) { phalcon_array_append(¬_null, property, PH_SEPARATE); } phalcon_array_append(&attributes, property, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } /** * Create an array using the MODELS_* constants as indexes */ PHALCON_INIT_VAR(model_metadata); array_init(model_metadata); phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); RETURN_CTOR(model_metadata); }
/** * Traverses a collection calling the callback to generate its HTML * * @param Phalcon\Assets\Collection $collection * @param callback $callback * @param string $type * @param array $args */ PHP_METHOD(Phalcon_Assets_Manager, output){ zval *collection, *callback, *type = NULL, *args = NULL, *output, *use_implicit_output; zval *resources = NULL, *filters = NULL, *prefix = NULL, *source_base_path = NULL; zval *target_base_path = NULL, *options, *collection_source_path = NULL; zval *complete_source_path = NULL, *collection_target_path = NULL; zval *complete_target_path = NULL, *filtered_joined_content = NULL; zval *join = NULL, *exception_message = NULL, *is_directory; zval *resource = NULL, *filter_needed = NULL, *local = NULL, *source_path = NULL; zval *target_path = NULL, *path = NULL, *prefixed_path = NULL, *attributes = NULL; zval *parameters = NULL, *html = NULL, *content = NULL, *must_filter = NULL; zval *filter = NULL, *filtered_content = NULL, *target_uri = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; zval *type_css; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 2, &collection, &callback, &type, &args); if (!args) { args = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(output); PHALCON_OBS_VAR(use_implicit_output); phalcon_read_property_this(&use_implicit_output, this_ptr, SL("_implicitOutput"), PH_NOISY TSRMLS_CC); /** * Get the resources as an array */ PHALCON_CALL_METHOD(&resources, collection, "getresources"); /** * Get filters in the collection */ PHALCON_CALL_METHOD(&filters, collection, "getfilters"); /** * Get the collection's prefix */ PHALCON_CALL_METHOD(&prefix, collection, "getprefix"); PHALCON_INIT_VAR(type_css); ZVAL_STRING(type_css, "css", 1); /** * Prepare options if the collection must be filtered */ if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_INIT_VAR(source_base_path); PHALCON_INIT_VAR(target_base_path); PHALCON_OBS_VAR(options); phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); /** * Check for global options in the assets manager */ if (Z_TYPE_P(options) == IS_ARRAY) { /** * The source base path is a global location where all resources are located */ if (phalcon_array_isset_string(options, SS("sourceBasePath"))) { PHALCON_OBS_NVAR(source_base_path); phalcon_array_fetch_string(&source_base_path, options, SL("sourceBasePath"), PH_NOISY); } /** * The target base path is a global location where all resources are written */ if (phalcon_array_isset_string(options, SS("targetBasePath"))) { PHALCON_OBS_NVAR(target_base_path); phalcon_array_fetch_string(&target_base_path, options, SL("targetBasePath"), PH_NOISY); } } /** * Check if the collection have its own source base path */ PHALCON_CALL_METHOD(&collection_source_path, collection, "getsourcepath"); /** * Concatenate the global base source path with the collection one */ if (PHALCON_IS_NOT_EMPTY(collection_source_path)) { PHALCON_INIT_VAR(complete_source_path); PHALCON_CONCAT_VV(complete_source_path, source_base_path, collection_source_path); } else { PHALCON_CPY_WRT(complete_source_path, source_base_path); } /** * Check if the collection have its own target base path */ PHALCON_CALL_METHOD(&collection_target_path, collection, "gettargetpath"); /** * Concatenate the global base source path with the collection one */ if (PHALCON_IS_NOT_EMPTY(collection_target_path)) { PHALCON_INIT_VAR(complete_target_path); PHALCON_CONCAT_VV(complete_target_path, target_base_path, collection_target_path); } else { PHALCON_CPY_WRT(complete_target_path, target_base_path); } /** * Global filtered content */ PHALCON_INIT_VAR(filtered_joined_content); /** * Check if all the resources in the collection must be joined */ PHALCON_CALL_METHOD(&join, collection, "getjoin"); /** * Check for valid target paths if the collection must be joined */ if (zend_is_true(join)) { /** * We need a valid final target path */ if (PHALCON_IS_EMPTY(complete_target_path)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (1)"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } PHALCON_INIT_VAR(is_directory); phalcon_is_dir(is_directory, complete_target_path TSRMLS_CC); /** * The targetpath needs to be a valid file */ if (PHALCON_IS_TRUE(is_directory)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (2)"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } } } phalcon_is_iterable(resources, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(resource); PHALCON_INIT_NVAR(filter_needed); ZVAL_FALSE(filter_needed); if (!type) { PHALCON_CALL_METHOD(&type, resource, "gettype"); } /** * Is the resource local? */ PHALCON_CALL_METHOD(&local, resource, "getlocal"); /** * If the collection must not be joined we must print a HTML for each one */ if (Z_TYPE_P(filters) == IS_ARRAY) { if (zend_is_true(local)) { /** * Get the complete path */ PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); /** * We need a valid source path */ if (!zend_is_true(source_path)) { PHALCON_CALL_METHOD(&source_path, resource, "getpath"); PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } } else { /** * Get the complete source path */ PHALCON_CALL_METHOD(&source_path, resource, "getpath"); /** * resources paths are always filtered */ PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } /** * Get the target path, we need to write the filtered content to a file */ PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); /** * We need a valid final target path */ if (PHALCON_IS_EMPTY(target_path)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } if (zend_is_true(local)) { /** * Make sure the target path is not the same source path */ if (PHALCON_IS_EQUAL(target_path, source_path)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } } else { PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } } } /** * If there are no filters, just print/buffer the HTML */ if (Z_TYPE_P(filters) != IS_ARRAY) { PHALCON_CALL_METHOD(&path, resource, "getrealtargeturi"); if (Z_TYPE_P(prefix) != IS_NULL) { PHALCON_INIT_NVAR(prefixed_path); PHALCON_CONCAT_VV(prefixed_path, prefix, path); } else { PHALCON_CPY_WRT(prefixed_path, path); } /** * Gets extra HTML attributes in the resource */ PHALCON_CALL_METHOD(&attributes, resource, "getattributes"); /** * Prepare the parameters for the callback */ PHALCON_INIT_NVAR(parameters); array_init_size(parameters, 3); if (Z_TYPE_P(attributes) == IS_ARRAY) { phalcon_array_update_long(&attributes, 0, prefixed_path, PH_COPY); phalcon_array_append(¶meters, attributes, PH_COPY); } else { phalcon_array_append(¶meters, prefixed_path, PH_COPY); } phalcon_array_append(¶meters, local, PH_COPY); phalcon_array_append(¶meters, args, PH_COPY); /** * Call the callback to generate the HTML */ PHALCON_INIT_NVAR(html);/**/ PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); /** * Implicit output prints the content directly */ if (zend_is_true(use_implicit_output)) { zend_print_zval(html, 0); } else { phalcon_concat_self(&output, html TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); continue; } if (zend_is_true(filter_needed)) { /** * Get the resource's content */ PHALCON_CALL_METHOD(&content, resource, "getcontent", complete_source_path); /** * Check if the resource must be filtered */ PHALCON_CALL_METHOD(&must_filter, resource, "getfilter"); /** * Only filter the resource if it's marked as 'filterable' */ if (zend_is_true(must_filter)) { phalcon_is_iterable(filters, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_HVALUE(filter); /** * Filters must be valid objects */ if (Z_TYPE_P(filter) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Filter is invalid"); return; } /** * Calls the method 'filter' which must return a filtered version of the content */ PHALCON_CALL_METHOD(&filtered_content, filter, "filter", content); PHALCON_CPY_WRT_CTOR(content, filtered_content); zend_hash_move_forward_ex(ah1, &hp1); } /** * Update the joined filtered content */ if (zend_is_true(join)) { if (PHALCON_IS_EQUAL(type, type_css)) { if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { PHALCON_INIT_NVAR(filtered_joined_content); PHALCON_CONCAT_VS(filtered_joined_content, content, ""); } else { PHALCON_SCONCAT_VS(filtered_joined_content, content, ""); } } else { if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { PHALCON_INIT_NVAR(filtered_joined_content); PHALCON_CONCAT_VS(filtered_joined_content, content, ";"); } else { PHALCON_SCONCAT_VS(filtered_joined_content, content, ";"); } } } } else { /** * Update the joined filtered content */ if (zend_is_true(join)) { if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { PHALCON_CPY_WRT(filtered_joined_content, content); } else { phalcon_concat_self(&filtered_joined_content, content TSRMLS_CC); } } else { PHALCON_CPY_WRT(filtered_content, content); } } if (!zend_is_true(join)) { /** * Write the file using file-put-contents. This respects the openbase-dir also * writes to streams */ phalcon_file_put_contents(NULL, target_path, filtered_content TSRMLS_CC); } } if (!zend_is_true(join)) { /** * Generate the HTML using the original path in the resource */ PHALCON_CALL_METHOD(&path, resource, "getrealtargeturi"); if (Z_TYPE_P(prefix) != IS_NULL) { PHALCON_INIT_NVAR(prefixed_path); PHALCON_CONCAT_VV(prefixed_path, prefix, path); } else { PHALCON_CPY_WRT(prefixed_path, path); } /** * Gets extra HTML attributes in the resource */ PHALCON_CALL_METHOD(&attributes, resource, "getattributes"); /** * Filtered resources are always local */ PHALCON_INIT_NVAR(local); ZVAL_TRUE(local); /** * Prepare the parameters for the callback */ PHALCON_INIT_NVAR(parameters); array_init_size(parameters, 3); if (Z_TYPE_P(attributes) == IS_ARRAY) { phalcon_array_update_long(&attributes, 0, prefixed_path, PH_COPY); phalcon_array_append(¶meters, attributes, PH_COPY); } else { phalcon_array_append(¶meters, prefixed_path, PH_COPY); } phalcon_array_append(¶meters, local, PH_COPY); phalcon_array_append(¶meters, args, PH_COPY); /** * Call the callback to generate the HTML */ PHALCON_INIT_NVAR(html);/**/ PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); /** * Implicit output prints the content directly */ if (zend_is_true(use_implicit_output)) { zend_print_zval(html, 0); } else { phalcon_concat_self(&output, html TSRMLS_CC); } } zend_hash_move_forward_ex(ah0, &hp0); } if (Z_TYPE_P(filters) == IS_ARRAY) { if (zend_is_true(join)) { /** * Write the file using file_put_contents. This respects the openbase-dir also * writes to streams */ phalcon_file_put_contents(NULL, complete_target_path, filtered_joined_content TSRMLS_CC); /** * Generate the HTML using the original path in the resource */ PHALCON_CALL_METHOD(&target_uri, collection, "gettargeturi"); if (Z_TYPE_P(prefix) != IS_NULL) { PHALCON_INIT_NVAR(prefixed_path); PHALCON_CONCAT_VV(prefixed_path, prefix, target_uri); } else { PHALCON_CPY_WRT(prefixed_path, target_uri); } /** * Gets extra HTML attributes in the resource */ PHALCON_CALL_METHOD(&attributes, collection, "getattributes"); PHALCON_CALL_METHOD(&local, collection, "gettargetlocal"); /** * Prepare the parameters for the callback */ PHALCON_INIT_NVAR(parameters); array_init_size(parameters, 3); if (Z_TYPE_P(attributes) == IS_ARRAY) { phalcon_array_update_long(&attributes, 0, prefixed_path, PH_COPY); phalcon_array_append(¶meters, attributes, PH_COPY); } else { phalcon_array_append(¶meters, prefixed_path, PH_COPY); } phalcon_array_append(¶meters, local, PH_COPY); phalcon_array_append(¶meters, args, PH_COPY); /** * Call the callback to generate the HTML */ PHALCON_INIT_NVAR(html);/**/ PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); /** * Implicit output prints the content directly */ if (zend_is_true(use_implicit_output)) { zend_print_zval(html, 0); } else { phalcon_concat_self(&output, html TSRMLS_CC); } } } RETURN_CCTOR(output); }
/** * Helper method to query records based on a relation definition * * @param array $relation * @param string $method * @param Phalcon\Mvc\Model $record */ PHP_METHOD(Phalcon_Mvc_Model_Manager, _getRelationRecords){ zval *relation = NULL, *method = NULL, *record = NULL, *conditions = NULL, *placeholders = NULL; zval *field = NULL, *value = NULL, *referenced_field = NULL, *condition = NULL; zval *i = NULL, *fields = NULL, *number_args = NULL, *function_arguments = NULL; zval *key = NULL, *join_conditions = NULL, *find_params = NULL, *arguments = NULL; zval *reference_table = NULL, *referenced_entity = NULL; zval *call_object = NULL, *records = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *c0 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &relation, &method, &record) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(conditions); array_init(conditions); PHALCON_INIT_VAR(placeholders); array_init(placeholders); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, relation, SL("fi"), PH_NOISY_CC); if (Z_TYPE_P(r0) != IS_ARRAY) { PHALCON_INIT_VAR(field); phalcon_array_fetch_string(&field, relation, SL("fi"), PH_NOISY_CC); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch_string(&referenced_field, relation, SL("rf"), PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VS(condition, referenced_field, " = ?0"); phalcon_array_update_long(&conditions, 0, &condition, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(i); ZVAL_LONG(i, 0); PHALCON_INIT_VAR(fields); phalcon_array_fetch_string(&fields, relation, SL("fi"), PH_NOISY_CC); if (!phalcon_valid_foreach(fields TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fields); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_74b5_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_74b5_0; } PHALCON_INIT_VAR(field); ZVAL_ZVAL(field, *hd, 1, 0); PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD_PARAMS_1(value, record, "readattribute", field, PH_NO_CHECK); PHALCON_INIT_VAR(r1); phalcon_array_fetch_string(&r1, relation, SL("rf"), PH_NOISY_CC); PHALCON_INIT_VAR(referenced_field); phalcon_array_fetch(&referenced_field, r1, i, PH_NOISY_CC); PHALCON_INIT_VAR(condition); PHALCON_CONCAT_VSV(condition, referenced_field, " = ?", i); phalcon_array_append(&conditions, condition, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&placeholders, value, PH_SEPARATE TSRMLS_CC); PHALCON_SEPARATE(i); increment_function(i); zend_hash_move_forward_ex(ah0, &hp0); goto fes_74b5_0; fee_74b5_0: if(0){} } PHALCON_INIT_VAR(number_args); PHALCON_CALL_FUNC(number_args, "func_num_args"); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 4); PHALCON_ALLOC_ZVAL_MM(r2); is_smaller_function(r2, t0, number_args TSRMLS_CC); if (zend_is_true(r2)) { PHALCON_INIT_VAR(function_arguments); PHALCON_CALL_FUNC(function_arguments, "func_get_args"); if (!phalcon_valid_foreach(function_arguments TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(function_arguments); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_74b5_1: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_74b5_1; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah1, hp1); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); PHALCON_INIT_VAR(t1); ZVAL_LONG(t1, 0); PHALCON_INIT_VAR(r3); is_equal_function(r3, key, t1 TSRMLS_CC); PHALCON_INIT_VAR(t2); ZVAL_STRING(t2, "conditions", 1); PHALCON_INIT_VAR(r4); is_equal_function(r4, key, t2 TSRMLS_CC); PHALCON_INIT_VAR(r5); ZVAL_BOOL(r5, zend_is_true(r3) || zend_is_true(r4)); if (zend_is_true(r5)) { phalcon_array_append(&conditions, value, PH_SEPARATE TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto fes_74b5_1; fee_74b5_1: if(0){} } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, " AND ", 1); PHALCON_INIT_VAR(join_conditions); phalcon_fast_join(join_conditions, c0, conditions TSRMLS_CC); PHALCON_INIT_VAR(find_params); array_init(find_params); phalcon_array_append(&find_params, join_conditions, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string(&find_params, SL("bind"), &placeholders, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, find_params, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(reference_table); phalcon_array_fetch_string(&reference_table, relation, SL("rt"), PH_NOISY_CC); ce0 = phalcon_fetch_class(reference_table TSRMLS_CC); PHALCON_INIT_VAR(referenced_entity); object_init_ex(referenced_entity, ce0); PHALCON_CALL_METHOD_NORETURN(referenced_entity, "__construct", PH_CHECK); PHALCON_ALLOC_ZVAL_MM(r6); PHALCON_CALL_METHOD(r6, record, "getconnectionservice", PH_NO_CHECK); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(referenced_entity, "setconnectionservice", r6, PH_NO_CHECK); PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&call_object, method, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(records); PHALCON_CALL_FUNC_PARAMS_2(records, "call_user_func_array", call_object, arguments); RETURN_CCTOR(records); }
/** * Builds generic INPUT tags * * @param string $type * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, _inputField){ zval *type = NULL, *parameters = NULL, *params = NULL, *id = NULL, *name = NULL, *value = NULL; zval *code = NULL, *key = NULL, *attribute = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &type, ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { PHALCON_INIT_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_string(params, SL("name")+1); if (!eval_int) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } eval_int = phalcon_array_isset_string(params, SL("id")+1); if (!eval_int) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } eval_int = phalcon_array_isset_string(params, SL("value")+1); if (!eval_int) { PHALCON_INIT_VAR(value); PHALCON_CALL_SELF_PARAMS_1(value, this_ptr, "getvalue", id); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<input type=\"", type, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_2; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_SVSVS(attribute, " ", key, "=\"", value, "\""); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_2; fee_9b93_2: PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, "/>", 1); phalcon_concat_self(&code, t0 TSRMLS_CC); RETURN_CTOR(code); }
/** * Generates a SELECT tag * * @param array $parameters * @param array $data */ PHP_METHOD(Phalcon_Tag_Select, selectField){ zval *parameters, *data = NULL, *params = NULL, *eol, *id = NULL, *name, *value = NULL; zval *use_empty = NULL, *empty_value = NULL, *empty_text = NULL, *code; zval *avalue = NULL, *key = NULL, *close_option, *options = NULL, *using; zval *resultset_options, *array_options; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", ¶meters, &data) == FAILURE) { RETURN_MM_NULL(); } if (!data) { PHALCON_INIT_VAR(data); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, data, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(eol); zend_get_constant(SL("PHP_EOL"), eol TSRMLS_CC); if (!phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_OBS_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); if (!phalcon_array_isset_string(params, SS("name"))) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } if (!phalcon_array_isset_string(params, SS("id"))) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } if (!phalcon_array_isset_string(params, SS("value"))) { PHALCON_INIT_VAR(value); PHALCON_CALL_STATIC_PARAMS_2(value, "phalcon\\tag", "getvalue", id, params); } else { PHALCON_OBS_NVAR(value); phalcon_array_fetch_string(&value, params, SL("value"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("value")); } PHALCON_INIT_VAR(use_empty); ZVAL_BOOL(use_empty, 0); if (phalcon_array_isset_string(params, SS("useEmpty"))) { if (!phalcon_array_isset_string(params, SS("emptyValue"))) { PHALCON_INIT_VAR(empty_value); ZVAL_STRING(empty_value, "", 1); } else { PHALCON_OBS_NVAR(empty_value); phalcon_array_fetch_string(&empty_value, params, SL("emptyValue"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("emptyValue")); } if (!phalcon_array_isset_string(params, SS("emptyText"))) { PHALCON_INIT_VAR(empty_text); ZVAL_STRING(empty_text, "Choose...", 1); } else { PHALCON_OBS_NVAR(empty_text); phalcon_array_fetch_string(&empty_text, params, SL("emptyText"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("emptyText")); } PHALCON_OBS_NVAR(use_empty); phalcon_array_fetch_string(&use_empty, params, SL("useEmpty"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("useEmpty")); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<select", 1); if (Z_TYPE_P(params) == IS_ARRAY) { if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { if (Z_TYPE_P(avalue) != IS_ARRAY) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } } zend_hash_move_forward_ex(ah0, &hp0); } } PHALCON_SCONCAT_SV(code, ">", eol); PHALCON_INIT_VAR(close_option); PHALCON_CONCAT_SV(close_option, "</option>", eol); if (zend_is_true(use_empty)) { /** * Create an empty value */ PHALCON_SCONCAT_SVSVV(code, "\t<option value=\"", empty_value, "\">", empty_text, close_option); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("useEmpty")); } if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_VAR(options); phalcon_array_fetch_long(&options, params, 1, PH_NOISY_CC); } else { PHALCON_CPY_WRT(options, data); } if (Z_TYPE_P(options) == IS_OBJECT) { /** * The options is a resultset */ if (!phalcon_array_isset_string(params, SS("using"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "The 'using' parameter is required"); return; } else { PHALCON_OBS_VAR(using); phalcon_array_fetch_string(&using, params, SL("using"), PH_NOISY_CC); if (Z_TYPE_P(using) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "The 'using' parameter should be an Array"); return; } } /** * Create the SELECT's option from a resultset */ PHALCON_INIT_VAR(resultset_options); PHALCON_CALL_SELF_PARAMS_4(resultset_options, this_ptr, "_optionsfromresultset", options, using, value, close_option); phalcon_concat_self(&code, resultset_options TSRMLS_CC); } else { if (Z_TYPE_P(options) == IS_ARRAY) {
PHP_METHOD(Phalcon_Model_MetaData, _initializeMetaData){ zval *model = NULL, *table = NULL, *schema = NULL, *key = NULL, *connection = NULL, *is_view = NULL; zval *exists = NULL, *meta_datas = NULL, *attributes = NULL, *primary_keys = NULL; zval *non_primary_keys = NULL, *numeric_typed = NULL, *not_null = NULL; zval *field_types = NULL, *identity_field = NULL, *meta_data = NULL; zval *field_name = NULL, *type = NULL, *table_metadata = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL; zval *a7 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_VV(r0, schema, table); PHALCON_CPY_WRT(key, r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset(t0, key); if (!eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, model, "getconnection", PHALCON_NO_CHECK); PHALCON_CPY_WRT(connection, r1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD(r2, model, "isview", PHALCON_NO_CHECK); PHALCON_CPY_WRT(is_view, r2); if (!zend_is_true(is_view)) { PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CALL_METHOD_PARAMS_2(r3, connection, "tableexists", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(exists, r3); } else { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD_PARAMS_2(r4, connection, "viewexists", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(exists, r4); } if (!zend_is_true(exists)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_ALLOC_ZVAL_MM(r6); phalcon_get_class(r6, model TSRMLS_CC); PHALCON_CONCAT_SVSVSV(r5, "Table \"", schema, "\".\"", table, "\" doesn't exist on database when dumping information for ", r6); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r5, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } else { if (zend_is_true(is_view)) { PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_CALL_METHOD_PARAMS_2(r7, connection, "describeview", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_datas, r7); } else { PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CALL_METHOD_PARAMS_2(r8, connection, "describetable", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_datas, r8); } PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(attributes, a0); PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CPY_WRT(primary_keys, a1); PHALCON_INIT_VAR(a2); array_init(a2); PHALCON_CPY_WRT(non_primary_keys, a2); PHALCON_INIT_VAR(a3); array_init(a3); PHALCON_CPY_WRT(numeric_typed, a3); PHALCON_INIT_VAR(a4); array_init(a4); PHALCON_CPY_WRT(not_null, a4); PHALCON_INIT_VAR(a5); array_init(a5); PHALCON_CPY_WRT(field_types, a5); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); if (phalcon_valid_foreach(meta_datas TSRMLS_CC)) { ah0 = Z_ARRVAL_P(meta_datas); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_f5c6_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_f5c6_0; } PHALCON_INIT_VAR(meta_data); ZVAL_ZVAL(meta_data, *hd, 1, 0); PHALCON_INIT_VAR(r9); phalcon_array_fetch_string(&r9, meta_data, SL("Field"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(field_name, r9); phalcon_array_append(&attributes, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_INIT_VAR(r10); phalcon_array_fetch_string(&r10, meta_data, SL("Key"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r10, "PRI")) { phalcon_array_append(&primary_keys, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } PHALCON_INIT_VAR(r11); phalcon_array_fetch_string(&r11, meta_data, SL("Type"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(type, r11); phalcon_array_update(&field_types, field_name, &type, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "char", 1); PHALCON_INIT_VAR(r12); phalcon_fast_strpos(r12, type, c0 TSRMLS_CC); if (Z_TYPE_P(r12) == IS_BOOL && !Z_BVAL_P(r12)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "int", 1); PHALCON_INIT_VAR(r13); phalcon_fast_strpos(r13, type, c1 TSRMLS_CC); if (Z_TYPE_P(r13) != IS_BOOL || (Z_TYPE_P(r13) == IS_BOOL && Z_BVAL_P(r13))) { PHALCON_INIT_VAR(t1); ZVAL_BOOL(t1, 1); phalcon_array_update(&numeric_typed, field_name, &t1, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "decimal", 1); PHALCON_INIT_VAR(r14); phalcon_fast_strpos(r14, type, c2 TSRMLS_CC); if (Z_TYPE_P(r14) != IS_BOOL || (Z_TYPE_P(r14) == IS_BOOL && Z_BVAL_P(r14))) { PHALCON_INIT_VAR(t2); ZVAL_BOOL(t2, 1); phalcon_array_update(&numeric_typed, field_name, &t2, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(c3); ZVAL_STRING(c3, "numeric", 1); PHALCON_INIT_VAR(r15); phalcon_fast_strpos(r15, type, c3 TSRMLS_CC); if (Z_TYPE_P(r15) != IS_BOOL || (Z_TYPE_P(r15) == IS_BOOL && Z_BVAL_P(r15))) { PHALCON_INIT_VAR(t3); ZVAL_BOOL(t3, 1); phalcon_array_update(&numeric_typed, field_name, &t3, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } } } } PHALCON_INIT_VAR(r16); phalcon_array_fetch_string(&r16, meta_data, SL("Null"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r16, "NO")) { phalcon_array_append(¬_null, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } PHALCON_INIT_VAR(r17); phalcon_array_fetch_string(&r17, meta_data, SL("Extra"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r17, "auto_increment")) { PHALCON_CPY_WRT(identity_field, field_name); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_f5c6_0; fee_f5c6_0: if(0){} } else { return; } PHALCON_INIT_VAR(a6); array_init(a6); PHALCON_CPY_WRT(table_metadata, a6); phalcon_array_update_long(&table_metadata, 0, &attributes, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t4); phalcon_read_property(&t4, this_ptr, SL("_metaData"), PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t4, key, &table_metadata, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t4 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t5); phalcon_read_property(&t5, this_ptr, SL("_changed"), PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t5)) { PHALCON_INIT_VAR(a7); array_init(a7); phalcon_array_append(&a7, this_ptr, PHALCON_SEPARATE_PLZ TSRMLS_CC); add_next_index_stringl(a7, SL("storeMetaData"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("register_shutdown_function", a7); phalcon_update_property_bool(this_ptr, SL("_changed"), 1 TSRMLS_CC); } } } PHALCON_MM_RESTORE(); }
/** * Builds a HTML TEXTAREA tag * *<code> * echo Phalcon\Tag::textArea(array("comments", "cols" => 10, "rows" => 4)) *</code> * * Volt syntax: *<code> * {{ text_area("comments", "cols": 10, "rows": 4) }} *</code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, textArea){ zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; zval *avalue = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, ¶meters); if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 1); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_long(params, 0)) { if (phalcon_array_isset_string(params, SS("id"))) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } PHALCON_OBS_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); if (!phalcon_array_isset_string(params, SS("name"))) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_OBS_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } if (!phalcon_array_isset_string(params, SS("id"))) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } if (phalcon_array_isset_string(params, SS("value"))) { PHALCON_OBS_VAR(content); phalcon_array_fetch_string(&content, params, SL("value"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("value"), PH_SEPARATE); } else { PHALCON_INIT_NVAR(content); PHALCON_CALL_SELF_PARAMS_2(content, this_ptr, "getvalue", id, params); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<textarea", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_SCONCAT_SVS(code, ">", content, "</textarea>"); RETURN_CTOR(code); }
/** * Builds generic INPUT tags * * @param string $type * @param array $parameters * @param boolean $asValue * @return string */ PHP_METHOD(Phalcon_Tag, _inputField){ zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL; zval *id = NULL, *name, *code, *key = NULL, *doctype; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &type, ¶meters, &as_value) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!as_value) { PHALCON_INIT_NVAR(as_value); ZVAL_BOOL(as_value, 0); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(value); if (PHALCON_IS_FALSE(as_value)) { eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { PHALCON_INIT_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_string(params, SS("name")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } eval_int = phalcon_array_isset_string(params, SS("id")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } eval_int = phalcon_array_isset_string(params, SS("value")); if (!eval_int) { PHALCON_CALL_SELF_PARAMS_1(value, this_ptr, "getvalue", id); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_NVAR(value); phalcon_array_fetch_long(&value, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } /** * Automatically check inputs */ if (PHALCON_COMPARE_STRING(type, "checkbox")) { if (zend_is_true(value)) { phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<input type=\"", type, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: /** * Check if Doctype is XHTML */ PHALCON_INIT_VAR(doctype); PHALCON_CALL_SELF(doctype, this_ptr, "getdoctype"); if (phalcon_memnstr_str(doctype, SL("XHTML") TSRMLS_CC)) { phalcon_concat_self_str(code, SL(" />") TSRMLS_CC); } else { phalcon_concat_self_str(code, SL(">") TSRMLS_CC); } RETURN_CTOR(code); }
/** * Initialize the metadata for certain table * * @param Phalcon\Mvc\Model $model * @param string $key * @param string $table * @param string $schema */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initializeMetaData){ zval *model, *key, *table, *schema, *meta_data, *data; zval *table_metadata = NULL, *class_name = NULL, *exception_message = NULL; zval *connection, *exists, *complete_table = NULL, *attributes; zval *primary_keys, *non_primary_keys, *numeric_typed; zval *not_null, *field_types, *field_bind_types; zval *automatic_default, *identity_field = NULL; zval *columns, *column = NULL, *field_name = NULL, *feature = NULL, *type = NULL; zval *bind_type = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzz", &model, &key, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(meta_data); phalcon_read_property(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC); eval_int = phalcon_array_isset(meta_data, key); if (!eval_int) { PHALCON_INIT_VAR(data); PHALCON_CALL_METHOD_PARAMS_1(data, this_ptr, "read", key, PH_NO_CHECK); if (Z_TYPE_P(data) != IS_NULL) { phalcon_array_update_zval(&meta_data, key, &data, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), meta_data TSRMLS_CC); PHALCON_MM_RESTORE(); RETURN_NULL(); } if (phalcon_method_exists_ex(model, SS("metadata") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(table_metadata); PHALCON_CALL_METHOD(table_metadata, model, "metadata", PH_NO_CHECK); if (Z_TYPE_P(table_metadata) != IS_ARRAY) { PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model TSRMLS_CC); PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "Invalid meta-data for model ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } } else { PHALCON_INIT_VAR(connection); PHALCON_CALL_METHOD(connection, model, "getconnection", PH_NO_CHECK); PHALCON_INIT_VAR(exists); PHALCON_CALL_METHOD_PARAMS_2(exists, connection, "tableexists", table, schema, PH_NO_CHECK); if (!zend_is_true(exists)) { if (zend_is_true(schema)) { PHALCON_INIT_VAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, model TSRMLS_CC); PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSV(exception_message, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(field_bind_types); array_init(field_bind_types); PHALCON_INIT_VAR(automatic_default); array_init(automatic_default); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); PHALCON_INIT_VAR(columns); PHALCON_CALL_METHOD_PARAMS_2(columns, connection, "describecolumns", table, schema, PH_NO_CHECK); if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { if (zend_is_true(schema)) { PHALCON_INIT_NVAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, model TSRMLS_CC); PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSV(exception_message, "Cannot obtain table columns for the mapped source \"", complete_table, "\" used in model ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } if (!phalcon_valid_foreach(columns TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(columns); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(column); PHALCON_INIT_NVAR(field_name); PHALCON_CALL_METHOD(field_name, column, "getname", PH_NO_CHECK); phalcon_array_append(&attributes, field_name, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isprimary", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { phalcon_array_append(&primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isnumeric", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isnotnull", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { phalcon_array_append(¬_null, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isautoincrement", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { PHALCON_CPY_WRT(identity_field, field_name); } PHALCON_INIT_NVAR(type); PHALCON_CALL_METHOD(type, column, "gettype", PH_NO_CHECK); phalcon_array_update_zval(&field_types, field_name, &type, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(bind_type); PHALCON_CALL_METHOD(bind_type, column, "getbindtype", PH_NO_CHECK); phalcon_array_update_zval(&field_bind_types, field_name, &bind_type, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_NVAR(table_metadata); array_init(table_metadata); phalcon_array_update_long(&table_metadata, 0, &attributes, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PH_NOISY_CC); phalcon_array_update_zval(&t0, key, &table_metadata, PH_COPY TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t0 TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "write", key, table_metadata, PH_NO_CHECK); } PHALCON_MM_RESTORE(); }
/** * Initialize the metadata for certain table * * @param Phalcon\Mvc\ModelInterface $model * @param string $key * @param string $table * @param string $schema */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initialize){ zval *model, *key, *table, *schema, *class_name = NULL, *meta_data = NULL; zval *data = NULL, *table_metadata = NULL, *exception_message = NULL; zval *connection, *exists, *complete_table = NULL, *columns; zval *attributes, *primary_keys, *non_primary_keys; zval *numeric_typed, *not_null, *field_types; zval *field_bind_types, *automatic_default; zval *identity_field = NULL, *column = NULL, *field_name = NULL, *feature = NULL; zval *type = NULL, *bind_type = NULL, *column_map = NULL, *ordered_column_map = NULL; zval *reversed_column_map = NULL, *user_column_map; zval *user_name = NULL, *name = NULL, *model_column_map; zval *t0 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzz", &model, &key, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, model TSRMLS_CC); if (Z_TYPE_P(key) != IS_NULL) { PHALCON_INIT_VAR(meta_data); phalcon_read_property(&meta_data, this_ptr, SL("_metaData"), PH_NOISY_CC); eval_int = phalcon_array_isset(meta_data, key); if (!eval_int) { /** * The meta-data is read from the adapter always */ PHALCON_INIT_VAR(data); PHALCON_CALL_METHOD_PARAMS_1(data, this_ptr, "read", key, PH_NO_CHECK); if (Z_TYPE_P(data) != IS_NULL) { if (Z_TYPE_P(meta_data) != IS_ARRAY) { PHALCON_INIT_NVAR(meta_data); array_init(meta_data); } phalcon_array_update_zval(&meta_data, key, &data, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), meta_data TSRMLS_CC); } else { /** * Check if there is a method 'metaData' in the model and retrieve data from it */ if (phalcon_method_exists_ex(model, SS("metadata") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(table_metadata); PHALCON_CALL_METHOD(table_metadata, model, "metadata", PH_NO_CHECK); if (Z_TYPE_P(table_metadata) != IS_ARRAY) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "Invalid meta-data for model ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } } else { /** * Check if the mapped table exists on the database */ PHALCON_INIT_VAR(connection); PHALCON_CALL_METHOD(connection, model, "getconnection", PH_NO_CHECK); PHALCON_INIT_VAR(exists); PHALCON_CALL_METHOD_PARAMS_2(exists, connection, "tableexists", table, schema, PH_NO_CHECK); if (!zend_is_true(exists)) { if (zend_is_true(schema)) { PHALCON_INIT_VAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSV(exception_message, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Try to describe the table */ PHALCON_INIT_VAR(columns); PHALCON_CALL_METHOD_PARAMS_2(columns, connection, "describecolumns", table, schema, PH_NO_CHECK); if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { if (zend_is_true(schema)) { PHALCON_INIT_NVAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSV(exception_message, "Cannot obtain table columns for the mapped source \"", complete_table, "\" used in model ", class_name); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } /** * Initialize meta-data */ PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(field_bind_types); array_init(field_bind_types); PHALCON_INIT_VAR(automatic_default); array_init(automatic_default); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); if (!phalcon_valid_foreach(columns TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(columns); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(column); PHALCON_INIT_NVAR(field_name); PHALCON_CALL_METHOD(field_name, column, "getname", PH_NO_CHECK); phalcon_array_append(&attributes, field_name, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isprimary", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { phalcon_array_append(&primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isnumeric", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isnotnull", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { phalcon_array_append(¬_null, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(feature); PHALCON_CALL_METHOD(feature, column, "isautoincrement", PH_NO_CHECK); if (PHALCON_IS_TRUE(feature)) { PHALCON_CPY_WRT(identity_field, field_name); } PHALCON_INIT_NVAR(type); PHALCON_CALL_METHOD(type, column, "gettype", PH_NO_CHECK); phalcon_array_update_zval(&field_types, field_name, &type, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(bind_type); PHALCON_CALL_METHOD(bind_type, column, "getbindtype", PH_NO_CHECK); phalcon_array_update_zval(&field_bind_types, field_name, &bind_type, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: /** * Create an array using the MODELS_* constants as indexes */ PHALCON_INIT_NVAR(table_metadata); array_init(table_metadata); phalcon_array_update_long(&table_metadata, 0, &attributes, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PH_NOISY_CC); phalcon_array_update_zval(&t0, key, &table_metadata, PH_COPY TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t0 TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "write", key, table_metadata, PH_NO_CHECK); } } } /** * Check for a column map, store in _columnMap in order and reversed order */ PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, model TSRMLS_CC); PHALCON_INIT_VAR(column_map); phalcon_read_property(&column_map, this_ptr, SL("_columnMap"), PH_NOISY_CC); eval_int = phalcon_array_isset(column_map, class_name); if (!eval_int) { if (Z_TYPE_P(column_map) != IS_ARRAY) { PHALCON_INIT_NVAR(column_map); array_init(column_map); } PHALCON_INIT_NVAR(data); PHALCON_CALL_METHOD_PARAMS_1(data, this_ptr, "read", class_name, PH_NO_CHECK); if (Z_TYPE_P(data) != IS_NULL) { phalcon_array_update_zval(&column_map, class_name, &data, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_columnMap"), column_map TSRMLS_CC); } else { PHALCON_INIT_VAR(ordered_column_map); PHALCON_INIT_VAR(reversed_column_map); /** * Check for a columnMap() method on the model */ if (phalcon_method_exists_ex(model, SS("columnmap") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(user_column_map); PHALCON_CALL_METHOD(user_column_map, model, "columnmap", PH_NO_CHECK); if (Z_TYPE_P(user_column_map) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array"); return; } array_init(reversed_column_map); PHALCON_CPY_WRT(ordered_column_map, user_column_map); if (!phalcon_valid_foreach(user_column_map TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(user_column_map); zend_hash_internal_pointer_reset_ex(ah1, &hp1); ph_cycle_start_1: if (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS) { goto ph_cycle_end_1; } PHALCON_GET_FOREACH_KEY(name, ah1, hp1); PHALCON_GET_FOREACH_VALUE(user_name); phalcon_array_update_zval(&reversed_column_map, user_name, &name, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); goto ph_cycle_start_1; ph_cycle_end_1: if(0){} } PHALCON_INIT_VAR(model_column_map); array_init(model_column_map); phalcon_array_update_long(&model_column_map, 0, &ordered_column_map, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&model_column_map, 1, &reversed_column_map, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_zval(&column_map, class_name, &model_column_map, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_columnMap"), column_map TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "write", class_name, model_column_map, PH_NO_CHECK); } } PHALCON_MM_RESTORE(); }