/** * Phalcon\Acl\Adapter\Memory constructor */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){ zval *a0 = NULL, *a1 = NULL, *a2 = NULL; PHALCON_MM_GROW(); phalcon_update_property_empty_array(phalcon_acl_adapter_memory_ce, this_ptr, SL("_rolesNames") TSRMLS_CC); phalcon_update_property_empty_array(phalcon_acl_adapter_memory_ce, this_ptr, SL("_roles") TSRMLS_CC); phalcon_update_property_empty_array(phalcon_acl_adapter_memory_ce, this_ptr, SL("_resources") TSRMLS_CC); phalcon_update_property_empty_array(phalcon_acl_adapter_memory_ce, this_ptr, SL("_access") TSRMLS_CC); phalcon_update_property_empty_array(phalcon_acl_adapter_memory_ce, this_ptr, SL("_roleInherits") TSRMLS_CC); PHALCON_INIT_VAR(a0); array_init_size(a0, 1); add_assoc_bool_ex(a0, SS("*"), 1); zend_update_property(phalcon_acl_adapter_memory_ce, this_ptr, SL("_resourcesNames"), a0 TSRMLS_CC); PHALCON_INIT_VAR(a1); array_init_size(a1, 1); PHALCON_INIT_VAR(a2); array_init_size(a2, 1); add_assoc_bool_ex(a2, SS("*"), 1); phalcon_array_update_string(&a1, SL("*"), &a2, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_update_property(phalcon_acl_adapter_memory_ce, this_ptr, SL("_accessList"), a1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/* {{{ static zval* array_to_hash */ static zval *array_to_hash(zval *array) { zval *hash, **entry; char *name_lc; /* * Well, this just transposes the array, popularly known as flipping it, or * giving it the finger. */ MAKE_STD_ZVAL(hash); array_init(hash); for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array)); zend_hash_get_current_data(Z_ARRVAL_P(array), (void**)&entry) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_P(array))) { if (Z_TYPE_PP(entry) == IS_STRING) { /* * I hate case-insensitivity. Die, die, die. */ name_lc = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); zend_str_tolower(name_lc, Z_STRLEN_PP(entry)); add_assoc_bool_ex(hash, name_lc, Z_STRLEN_PP(entry)+1, 1); efree(name_lc); } } return hash; }
PHP_COUCHBASE_LOCAL void pcbc_ht_hkstoreb(zval *assoc, pcbc_ht_key *hk, zend_bool value) { const char *zh_key; int zh_nkey; ISARRAY_SANITY(assoc); HK_STRING(hk, zh_key, zh_nkey); add_assoc_bool_ex(assoc, zh_key, zh_nkey, value); }
static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS, const zend_string *domain, uint32_t option, int mode, zval *idna_info) { UErrorCode status = U_ZERO_ERROR; UIDNA *uts46; int32_t len; zend_string *buffer; UIDNAInfo info = UIDNA_INFO_INITIALIZER; uts46 = uidna_openUTS46(option, &status); if (php_intl_idn_check_status(status, "failed to open UIDNA instance") == FAILURE) { RETURN_FALSE; } if (mode == INTL_IDN_TO_ASCII) { const int32_t buffer_capac = 255; buffer = zend_string_alloc(buffer_capac, 0); len = uidna_nameToASCII_UTF8(uts46, ZSTR_VAL(domain), ZSTR_LEN(domain), ZSTR_VAL(buffer), buffer_capac, &info, &status); if (len >= buffer_capac || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) { uidna_close(uts46); zend_string_efree(buffer); RETURN_FALSE; } } else { const int32_t buffer_capac = 252*4; buffer = zend_string_alloc(buffer_capac, 0); len = uidna_nameToUnicodeUTF8(uts46, ZSTR_VAL(domain), ZSTR_LEN(domain), ZSTR_VAL(buffer), buffer_capac, &info, &status); if (len >= buffer_capac || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) { uidna_close(uts46); zend_string_efree(buffer); RETURN_FALSE; } } ZSTR_VAL(buffer)[len] = '\0'; ZSTR_LEN(buffer) = len; if (info.errors == 0) { RETVAL_STR_COPY(buffer); } else { RETVAL_FALSE; } if (idna_info) { add_assoc_str_ex(idna_info, "result", sizeof("result")-1, zend_string_copy(buffer)); add_assoc_bool_ex(idna_info, "isTransitionalDifferent", sizeof("isTransitionalDifferent")-1, info.isTransitionalDifferent); add_assoc_long_ex(idna_info, "errors", sizeof("errors")-1, (zend_long)info.errors); } zend_string_release(buffer); uidna_close(uts46); }
/* {{{ proto array Riak\MapReduce\Phase\MapPhase->toArray() Convert this phase into an array */ PHP_METHOD(Riak_MapReduce_Phase_MapPhase, toArray) { zval *zarray, *zfuncarray, *zfunc, *zarg, zname; zend_bool keep; MAKE_STD_ZVAL(zarray); array_init(zarray); MAKE_STD_ZVAL(zfuncarray); zfunc = zend_read_property(riak_mr_mapphase_ce, getThis(), "function", sizeof("function")-1, 1 TSRMLS_CC); ZVAL_STRING(&zname, "toArray", 0); call_user_function(NULL, &zfunc, &zname, zfuncarray, 0, NULL TSRMLS_CC); keep = Z_BVAL_P(zend_read_property(riak_mr_mapphase_ce, getThis(), "keep", sizeof("keep")-1, 1 TSRMLS_CC)); if (keep) { add_assoc_bool_ex(zfuncarray, "keep", sizeof("keep"), 1); } add_assoc_zval_ex(zarray, "map", sizeof("map"), zfuncarray); zarg = zend_read_property(riak_mr_mapphase_ce, getThis(), "arg", sizeof("arg")-1, 1 TSRMLS_CC); if (Z_TYPE_P(zarg) != IS_NULL) { add_assoc_zval_ex(zarray, "arg", sizeof("arg"), zarg); zval_addref_p(zarg); } RETURN_ZVAL(zarray, 0, 1); }
static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS, const char *domain, int32_t domain_len, uint32_t option, int mode, zval *idna_info) { UErrorCode status = U_ZERO_ERROR; UIDNA *uts46; int32_t len; int32_t buffer_capac = 255; /* no domain name may exceed this */ zend_string *buffer = zend_string_alloc(buffer_capac, 0); UIDNAInfo info = UIDNA_INFO_INITIALIZER; int buffer_used = 0; uts46 = uidna_openUTS46(option, &status); if (php_intl_idn_check_status(status, "failed to open UIDNA instance", mode) == FAILURE) { zend_string_free(buffer); RETURN_FALSE; } if (mode == INTL_IDN_TO_ASCII) { len = uidna_nameToASCII_UTF8(uts46, domain, domain_len, ZSTR_VAL(buffer), buffer_capac, &info, &status); } else { len = uidna_nameToUnicodeUTF8(uts46, domain, domain_len, ZSTR_VAL(buffer), buffer_capac, &info, &status); } if (php_intl_idn_check_status(status, "failed to convert name", mode) == FAILURE) { uidna_close(uts46); zend_string_free(buffer); RETURN_FALSE; } if (len >= 255) { php_error_docref(NULL, E_ERROR, "ICU returned an unexpected length"); } ZSTR_VAL(buffer)[len] = '\0'; ZSTR_LEN(buffer) = len; if (info.errors == 0) { RETVAL_STR(buffer); buffer_used = 1; } else { RETVAL_FALSE; } if (idna_info) { if (buffer_used) { /* used in return_value then */ zval_addref_p(return_value); add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, return_value); } else { zval zv; ZVAL_NEW_STR(&zv, buffer); buffer_used = 1; add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, &zv); } add_assoc_bool_ex(idna_info, "isTransitionalDifferent", sizeof("isTransitionalDifferent")-1, info.isTransitionalDifferent); add_assoc_long_ex(idna_info, "errors", sizeof("errors")-1, (zend_long)info.errors); } if (!buffer_used) { zend_string_free(buffer); } uidna_close(uts46); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> * * @param string $table * @param string $schema * @return Phalcon\Db\Column[] */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeColumns){ zval *table = NULL, *schema = NULL, *columns = NULL, *sql = NULL, *fetch_assoc = NULL; zval *describe = NULL, *old_column = NULL, *field = NULL, *definition = NULL; zval *column_type = NULL; zval *status = NULL, *matches = NULL, *pattern = NULL, *attribute = NULL, *column_name = NULL; zval *column = NULL, *dialect = NULL; zval *r0 = NULL, *r1 = NULL; zval *status2 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; 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(columns); array_init(columns); PHALCON_ALLOC_ZVAL_MM(dialect); phalcon_read_property(&dialect, this_ptr, SL("_dialect"), PH_NOISY_CC); PHALCON_INIT_VAR(sql); PHALCON_CALL_METHOD_PARAMS_2(sql, dialect, "describecolumns", table, schema, PH_NO_CHECK); PHALCON_INIT_VAR(fetch_assoc); phalcon_get_class_constant(fetch_assoc, phalcon_db_ce, SL("FETCH_ASSOC") TSRMLS_CC); PHALCON_INIT_VAR(describe); PHALCON_CALL_METHOD_PARAMS_2(describe, this_ptr, "fetchall", sql, fetch_assoc, PH_NO_CHECK); PHALCON_INIT_VAR(old_column); ZVAL_NULL(old_column); 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(field); PHALCON_INIT_VAR(definition); array_init(definition); add_assoc_long_ex(definition, SS("bindType"), 2); PHALCON_INIT_VAR(column_type); phalcon_array_fetch_string(&column_type, field, SL("type"), PH_NOISY_CC); PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("int") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 0); add_assoc_bool_ex(definition, SS("isNumeric"), 1); add_assoc_long_ex(definition, SS("size"), 32); // default 4byte add_assoc_long_ex(definition, SS("bindType"), 1); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("varchar") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 255, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("date") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE TSRMLS_CC); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); PHALCON_INIT_VAR(status2); phalcon_fast_strpos_str(status, column_type, SL("numeric") TSRMLS_CC); phalcon_fast_strpos_str(status2, column_type, SL("decimal") TSRMLS_CC); if ( (PHALCON_IS_NOT_FALSE(status)) || (PHALCON_IS_NOT_FALSE(status2)) ) { add_assoc_long_ex(definition, SS("type"), 3); add_assoc_bool_ex(definition, SS("isNumeric"), 1); add_assoc_long_ex(definition, SS("size"), 32); // default 4byte add_assoc_long_ex(definition, SS("bindType"), 32); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("char") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 5); phalcon_array_update_string_long(&definition, SL("size"), 255, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("timestamp") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 4); phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("text") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 6); phalcon_array_update_string_long(&definition, SL("size"), 2147483647, PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("float") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { add_assoc_long_ex(definition, SS("type"), 7); add_assoc_bool_ex(definition, SS("isNumeric"), 1); add_assoc_long_ex(definition, SS("size"), 64); // default 4byte add_assoc_long_ex(definition, SS("bindType"), 32); } else { add_assoc_long_ex(definition, SS("type"), 5); PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("uuid") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_long(&definition, SL("size"), 36, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_long(&definition, SL("size"), 255, PH_SEPARATE TSRMLS_CC); } } } } } } } } } PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("(") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { PHALCON_INIT_VAR(matches); array_init(matches); PHALCON_INIT_VAR(pattern); ZVAL_STRING(pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); Z_SET_ISREF_P(matches); PHALCON_INIT_VAR(r0); PHALCON_CALL_FUNC_PARAMS_3(r0, "preg_match", pattern, column_type, matches); Z_UNSET_ISREF_P(matches); if (zend_is_true(r0)) { eval_int = phalcon_array_isset_long(matches, 1); if (eval_int) { PHALCON_INIT_VAR(r1); phalcon_array_fetch_long(&r1, matches, 1, PH_NOISY_CC); phalcon_array_update_string(&definition, SL("size"), &r1, PH_COPY | PH_SEPARATE TSRMLS_CC); } } } PHALCON_INIT_VAR(status); phalcon_fast_strpos_str(status, column_type, SL("unsigned") TSRMLS_CC); if (PHALCON_IS_NOT_FALSE(status)) { phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE TSRMLS_CC); } if (Z_TYPE_P(old_column) == IS_NULL) { phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string(&definition, SL("after"), &old_column, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("pk"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "1")) { phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE TSRMLS_CC); }else { phalcon_array_update_string_bool(&definition, SL("primary"), 0, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(attribute); phalcon_array_fetch_string(&attribute, field, SL("notnull"), PH_NOISY_CC); if (PHALCON_COMPARE_STRING(attribute, "1")) { phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r0); phalcon_fast_strpos_str(r0, column_type, SL("integer") TSRMLS_CC); PHALCON_INIT_VAR(r1); phalcon_array_fetch_string(&r1, definition, SL("primary"), PH_NOISY_CC); if ((PHALCON_IS_NOT_FALSE(r0)) && (PHALCON_IS_NOT_FALSE(r1))) { phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(column_name); phalcon_array_fetch_string(&column_name, field, SL("name"), PH_NOISY_CC); PHALCON_INIT_VAR(column); object_init_ex(column, phalcon_db_column_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(column, "__construct", column_name, definition, PH_CHECK); phalcon_array_append(&columns, column, PH_SEPARATE TSRMLS_CC); PHALCON_CPY_WRT(old_column, column_name); zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: RETURN_CTOR(columns);}