/** * Adds a message to the session flasher * * @param string $type * @param string $message */ PHP_METHOD(Phalcon_Flash_Session, message){ zval *type, *message, *remove, *messages = NULL, *empty_array; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &type, &message); PHALCON_INIT_VAR(remove); ZVAL_BOOL(remove, 0); PHALCON_INIT_VAR(messages); phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", remove); if (Z_TYPE_P(messages) != IS_ARRAY) { PHALCON_INIT_NVAR(messages); array_init(messages); } if (!phalcon_array_isset(messages, type)) { PHALCON_INIT_VAR(empty_array); array_init(empty_array); phalcon_array_update_zval(&messages, type, &empty_array, PH_COPY | PH_SEPARATE); } phalcon_array_update_append_multi_2(&messages, type, message, 0); phalcon_call_method_p1_noret(this_ptr, "_setsessionmessages", messages); PHALCON_MM_RESTORE(); }
/** * Attach a listener to the events manager * * @param string $eventType * @param object $handler */ PHP_METHOD(Phalcon_Events_Manager, attach){ zval *event_type = NULL, *handler = NULL, *events = NULL; zval *a0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &event_type, &handler) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (Z_TYPE_P(handler) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event handler must be an Object"); return; } PHALCON_INIT_VAR(events); phalcon_read_property(&events, this_ptr, SL("_events"), PH_NOISY_CC); eval_int = phalcon_array_isset(events, event_type); if (!eval_int) { PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); phalcon_array_update_zval(&events, event_type, &a0, PH_COPY | PH_SEPARATE TSRMLS_CC); } phalcon_array_update_append_multi_2(&events, event_type, handler, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_events"), events TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Adds a message to the session flasher * * @param string $type * @param string $message */ PHP_METHOD(Phalcon_Flash_Session, message){ zval *type, *message, *remove, *messages = NULL; zval *a0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &type, &message) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(remove); ZVAL_BOOL(remove, 0); PHALCON_INIT_VAR(messages); PHALCON_CALL_METHOD_PARAMS_1(messages, this_ptr, "_getsessionmessages", remove, PH_NO_CHECK); if (Z_TYPE_P(messages) != IS_ARRAY) { PHALCON_INIT_NVAR(messages); array_init(messages); } eval_int = phalcon_array_isset(messages, type); if (!eval_int) { PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_update_zval(&messages, type, &a0, PH_COPY | PH_SEPARATE TSRMLS_CC); } phalcon_array_update_append_multi_2(&messages, type, message, 0 TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "_setsessionmessages", messages, PH_NO_CHECK); PHALCON_MM_RESTORE(); }
/** * Adds a message to the session flasher * * @param string $type * @param string $message */ PHP_METHOD(Phalcon_Flash_Session, message){ zval *type, *message, *remove, *messages = NULL; zval *a0 = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &type, &message); PHALCON_INIT_VAR(remove); ZVAL_BOOL(remove, 0); PHALCON_INIT_VAR(messages); PHALCON_CALL_METHOD_PARAMS_1(messages, this_ptr, "_getsessionmessages", remove); if (Z_TYPE_P(messages) != IS_ARRAY) { PHALCON_INIT_NVAR(messages); array_init(messages); } if (!phalcon_array_isset(messages, type)) { PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_update_zval(&messages, type, &a0, PH_COPY | PH_SEPARATE TSRMLS_CC); } phalcon_array_update_append_multi_2(&messages, type, message, 0 TSRMLS_CC); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(this_ptr, "_setsessionmessages", messages); PHALCON_MM_RESTORE(); }
/** * Do a role inherit from another existing role * * @param string $roleName * @param string $roleToInherit */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit){ zval *role_name, *role_to_inherit, *roles_names; zval *exception_message = NULL, *role_inherit_name = NULL; zval *roles_inherits, *empty_arr, *_roleInherits; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &role_name, &role_to_inherit); PHALCON_OBS_VAR(roles_names); phalcon_read_property_this(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); if (!phalcon_array_isset(roles_names, role_name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role '", role_name, "' does not exist in the role list"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } if (Z_TYPE_P(role_to_inherit) == IS_OBJECT) { PHALCON_INIT_VAR(role_inherit_name); phalcon_call_method(role_inherit_name, role_to_inherit, "getname"); } else { PHALCON_CPY_WRT(role_inherit_name, role_to_inherit); } /** * Check if the role to inherit is valid */ if (!phalcon_array_isset(roles_names, role_inherit_name)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role '", role_inherit_name, "' (to inherit) does not exist in the role list"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } if (PHALCON_IS_EQUAL(role_inherit_name, role_name)) { RETURN_MM_FALSE; } PHALCON_OBS_VAR(roles_inherits); phalcon_read_property_this(&roles_inherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); if (!phalcon_array_isset(roles_inherits, role_name)) { PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); phalcon_update_property_array(this_ptr, SL("_roleInherits"), role_name, empty_arr TSRMLS_CC); } PHALCON_OBS_VAR(_roleInherits); phalcon_read_property_this(&_roleInherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); phalcon_array_update_append_multi_2(&_roleInherits, role_name, role_inherit_name, 0); phalcon_update_property_this(this_ptr, SL("_roleInherits"), _roleInherits TSRMLS_CC); RETURN_MM_TRUE; }
/** * Do a role inherit from another existing role * * @param string $roleName * @param string $roleToInherit */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit){ zval *role_name, *role_to_inherit, *roles_names; zval *exception_message = NULL, *role_inherit_name = NULL; zval *roles_inherits, *empty_arr, *_roleInherits; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &role_name, &role_to_inherit) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(roles_names); phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); if (!phalcon_array_isset(roles_names, role_name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role '", role_name, "' does not exist in the role list"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } if (Z_TYPE_P(role_to_inherit) == IS_OBJECT) { PHALCON_INIT_VAR(role_inherit_name); PHALCON_CALL_METHOD(role_inherit_name, role_to_inherit, "getname"); } else { PHALCON_CPY_WRT(role_inherit_name, role_to_inherit); } /** * Check if the role to inherit is valid */ if (!phalcon_array_isset(roles_names, role_inherit_name)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role '", role_inherit_name, "' (to inherit) does not exist in the role list"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } if (PHALCON_IS_EQUAL(role_inherit_name, role_name)) { RETURN_MM_FALSE; } PHALCON_OBS_VAR(roles_inherits); phalcon_read_property(&roles_inherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); if (!phalcon_array_isset(roles_inherits, role_name)) { PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); phalcon_update_property_array(this_ptr, SL("_roleInherits"), role_name, empty_arr TSRMLS_CC); } PHALCON_OBS_VAR(_roleInherits); phalcon_read_property(&_roleInherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); phalcon_array_update_append_multi_2(&_roleInherits, role_name, role_inherit_name, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_roleInherits"), _roleInherits TSRMLS_CC); /** * Re-build the access list with its inherited roles */ PHALCON_CALL_METHOD_NORETURN(this_ptr, "_rebuildaccesslist"); RETURN_MM_TRUE; }
/** * Lists table indexes * * @param string $table * @param string $schema * @return Phalcon\Db\Index[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, describeIndexes){ zval *table = NULL, *schema = NULL, *dialect = NULL, *fetch_assoc = NULL, *sql = NULL; zval *describe = NULL, *indexes = NULL, *index = NULL, *key_name = NULL, *empty_arr = NULL; zval *column_name = NULL, *index_objects = NULL, *index_columns = NULL; zval *name = 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, "z|z", &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!schema) { PHALCON_ALLOC_ZVAL_MM(schema); ZVAL_NULL(schema); } PHALCON_INIT_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describeindexes", table, schema, PH_NO_CHECK); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc, PH_NO_CHECK); PHALCON_INIT_VAR(indexes); array_init(indexes); if (!phalcon_valid_foreach(describe TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(describe); 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(index); PHALCON_INIT_VAR(key_name); phalcon_array_fetch_string(&key_name, index, SL("key_name"), PH_NOISY_CC); eval_int = phalcon_array_isset(indexes, key_name); if (!eval_int) { PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(column_name); phalcon_array_fetch_string(&column_name, index, SL("column_name"), PH_NOISY_CC); phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0 TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(index_objects); array_init(index_objects); if (!phalcon_valid_foreach(indexes TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(indexes); 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_INIT_VAR(name); PHALCON_GET_FOREACH_KEY(name, ah1, hp1); PHALCON_GET_FOREACH_VALUE(index_columns); PHALCON_INIT_VAR(index); object_init_ex(index, phalcon_db_index_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(index, "__construct", name, index_columns, PH_CHECK); phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); goto ph_cycle_start_1; ph_cycle_end_1: RETURN_CTOR(index_objects); }
/** * Lists table indexes * * @param string $table * @param string $schema * @return Phalcon\Db\Index[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ zval *table, *schema = NULL, *dialect, *fetch_assoc, *sql; zval *describe, *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL; zval *sql_index_describe = NULL, *describe_index = NULL; zval *index_column = NULL, *column_name = NULL, *index_objects; zval *index_columns = NULL, *name = NULL; HashTable *ah0, *ah1, *ah2; HashPosition hp0, hp1, hp2; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table, &schema) == FAILURE) { RETURN_MM_NULL(); } if (!schema) { PHALCON_INIT_VAR(schema); } PHALCON_OBS_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SS("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describeindexes", table, schema); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc); PHALCON_INIT_VAR(indexes); array_init(indexes); if (!phalcon_is_iterable(describe, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(index); PHALCON_OBS_NVAR(key_name); phalcon_array_fetch_string(&key_name, index, SL("name"), PH_NOISY_CC); if (!phalcon_array_isset(indexes, key_name)) { PHALCON_INIT_NVAR(empty_arr); array_init(empty_arr); phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(sql_index_describe); PHALCON_CALL_METHOD_PARAMS_1(sql_index_describe, dialect, "describeindex", key_name); PHALCON_INIT_NVAR(describe_index); PHALCON_CALL_METHOD_PARAMS_2(describe_index, this_ptr, "fetchall", sql_index_describe, fetch_assoc); if (!phalcon_is_iterable(describe_index, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(index_column); PHALCON_OBS_NVAR(column_name); phalcon_array_fetch_string(&column_name, index_column, SL("name"), PH_NOISY_CC); phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0 TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(index_objects); array_init(index_objects); if (!phalcon_is_iterable(indexes, &ah2, &hp2, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_FOREACH_KEY(name, ah2, hp2); PHALCON_GET_FOREACH_VALUE(index_columns); PHALCON_INIT_NVAR(index); object_init_ex(index, phalcon_db_index_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(index, "__construct", name, index_columns); phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah2, &hp2); } RETURN_CTOR(index_objects); }
/** * Lists table indexes * *<code> * print_r($connection->describeIndexes('robots_parts')); *</code> * * @param string $table * @param string $schema * @return Phalcon\Db\Index[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo, describeIndexes){ zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *describe; zval *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL, *column_name = NULL; zval *index_objects, *index_columns = NULL, *name = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &table, &schema) == FAILURE) { RETURN_MM_NULL(); } if (!schema) { PHALCON_INIT_VAR(schema); } PHALCON_OBS_VAR(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); /** * We're using FETCH_NUM to fetch the columns */ PHALCON_INIT_VAR(fetch_num); ZVAL_LONG(fetch_num, 3); /** * Get the SQL required to describe indexes from the Dialect */ PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describeindexes", table, schema); /** * Cryptic Guide: 2: table, 3: from, 4: to */ PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_num); PHALCON_INIT_VAR(indexes); array_init(indexes); if (!phalcon_is_iterable(describe, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(index); PHALCON_OBS_NVAR(key_name); phalcon_array_fetch_long(&key_name, index, 2, PH_NOISY_CC); if (!phalcon_array_isset(indexes, key_name)) { PHALCON_INIT_NVAR(empty_arr); array_init(empty_arr); phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_OBS_NVAR(column_name); phalcon_array_fetch_long(&column_name, index, 4, PH_NOISY_CC); phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0 TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(index_objects); array_init(index_objects); if (!phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_KEY(name, ah1, hp1); PHALCON_GET_FOREACH_VALUE(index_columns); /** * Every index is abstracted using a Phalcon\Db\Index instance */ PHALCON_INIT_NVAR(index); object_init_ex(index, phalcon_db_index_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(index, "__construct", name, index_columns); phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); } RETURN_CTOR(index_objects); }