Ejemplo n.º 1
0
/**
 * Decrement of a given key, by number $value
 * 
 * @param  string $keyName
 * @param  long $value
 * @return mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Apc, decrement){

	zval *key_name, *value = NULL, prefix = {}, prefixed_key = {}, cached_content = {};

	phalcon_fetch_params(0, 1, 1, &key_name, &value);

	if (!value || Z_TYPE_P(value) == IS_NULL) {
		value = &PHALCON_GLOBAL(z_one);
	} else {
		PHALCON_ENSURE_IS_LONG(value);
	}

	phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY);

	PHALCON_CONCAT_SVV(&prefixed_key, "_PHCA", &prefix, key_name);
	phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key);

	if (SUCCESS == phalcon_function_exists_ex(SL("apc_dec"))) {
		PHALCON_RETURN_CALL_FUNCTIONW("apc_dec", &prefixed_key, value);
	} else {
		PHALCON_CALL_FUNCTIONW(&cached_content, "apc_fetch", &prefixed_key);

		if (Z_TYPE(cached_content) == IS_LONG) {
			phalcon_sub_function(return_value, &cached_content, value);
			PHALCON_CALL_METHODW(NULL, getThis(), "save", key_name, return_value);
		} else {
			RETURN_FALSE;
		}
	}
}
Ejemplo n.º 2
0
/**
 * Serializes data before storing them
 *
 * @param mixed $data
 * @return string
 */
PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, beforeStore)
{
	zval *data;

	phalcon_fetch_params(0, 1, 0, &data);
	
	PHALCON_RETURN_CALL_FUNCTIONW("igbinary_serialize", data);
}
Ejemplo n.º 3
0
/**
 * Moves the temporary file to a destination within the application
 *
 * @param string $destination
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request_File, moveTo){

	zval *destination, *temp_file;

	phalcon_fetch_params(0, 1, 0, &destination);
	
	temp_file = phalcon_fetch_nproperty_this(this_ptr, SL("_tmp"), PH_NOISY TSRMLS_CC);
	PHALCON_RETURN_CALL_FUNCTIONW("move_uploaded_file", temp_file, destination);
}
Ejemplo n.º 4
0
/**
 * Interpolates context values into the message placeholders
 *
 * @see http://www.php-fig.org/psr/psr-3/ Section 1.2 Message
 * @param string $message
 * @param array $context
 */
PHP_METHOD(Phalcon_Logger_Formatter, interpolate)
{
    zval **message, **context;

    phalcon_fetch_params_ex(2, 0, &message, &context);

    if (Z_TYPE_PP(context) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_PP(context)) > 0) {
        HashTable *ht = Z_ARRVAL_PP(context);
        HashPosition hp;
        zval *replace, **val;

        PHALCON_ALLOC_GHOST_ZVAL(replace);
        array_init_size(replace, zend_hash_num_elements(ht));

        for (
            zend_hash_internal_pointer_reset_ex(ht, &hp);
            zend_hash_get_current_data_ex(ht, (void**)&val, &hp) == SUCCESS;
            zend_hash_move_forward_ex(ht, &hp)
        ) {
            char *str_index, *idx;
            uint str_length;
            ulong num_index;
            int type = zend_hash_get_current_key_ex(ht, &str_index, &str_length, &num_index, 0, &hp);

            if (HASH_KEY_IS_STRING == type) {
                str_length       += 2;
                idx               = emalloc(str_length);
                idx[0]            = '{';
                idx[str_length-2] = '}';
                idx[str_length-1] = '\0';
                memcpy(idx + 1, str_index, str_length - 3);
            }
            else if (HASH_KEY_IS_LONG == type) {
                str_length = spprintf(&idx, 0, "{%ld}", num_index);
            }
            else { /* Better safe than sorry */
                continue;
            }

            Z_ADDREF_PP(val);
            zend_hash_add(Z_ARRVAL_P(replace), idx, str_length, (void*)val, sizeof(zval*), NULL);
            efree(idx);
        }

        PHALCON_RETURN_CALL_FUNCTIONW("strtr", *message, replace);
        return;
    }

    RETURN_ZVAL(*message, 1, 0);
}
Ejemplo n.º 5
0
/**
 * Utility to normalize a string's encoding to UTF-32.
 *
 * @param string $str
 * @return string
 */
PHP_METHOD(Phalcon_Escaper, normalizeEncoding){

	zval *str, encoding = {}, charset = {};

	phalcon_fetch_params(0, 1, 0, &str);

	/**
	 * mbstring is required here
	 */
	if (phalcon_function_exists_ex(SL("mb_convert_encoding")) == FAILURE) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "Extension 'mbstring' is required");
		return;
	}

	PHALCON_CALL_METHODW(&encoding, getThis(), "detectencoding", getThis());

	ZVAL_STRING(&charset, "UTF-32");

	/**
	 * Convert to UTF-32 (4 byte characters, regardless of actual number of bytes in
	 * the character).
	 */
	PHALCON_RETURN_CALL_FUNCTIONW("mb_convert_encoding", str, &charset, &encoding);
}
Ejemplo n.º 6
0
/**
 * Detect the character encoding of a string to be handled by an encoder
 * Special-handling for chr(172) and chr(128) to chr(159) which fail to be detected by mb_detect_encoding()
 *
 * @param string $str
 * @param string $charset
 * @return string
 */
PHP_METHOD(Phalcon_Escaper, detectEncoding){

	zval *str, charset = {}, strict_check = {}, detected = {};

	phalcon_fetch_params(0, 1, 0, &str);

	/**
	 * Check if charset is ASCII or ISO-8859-1
	 */
	phalcon_is_basic_charset(&charset, str);
	if (Z_TYPE(charset) == IS_STRING) {
		RETURN_CTORW(&charset);
	}

	/**
	 * We require mbstring extension here
	 */
	if (phalcon_function_exists_ex(SL("mb_detect_encoding")) == FAILURE) {
		RETURN_NULL();
	}

	/**
	 * Strict encoding detection with fallback to non-strict detection.
	 */
	ZVAL_TRUE(&strict_check);
	ZVAL_STRING(&charset, "UTF-32");

	/**
	 * Check for UTF-32 encoding
	 */
	PHALCON_CALL_FUNCTIONW(&detected, "mb_detect_encoding", str, &charset, &strict_check);
	if (zend_is_true(&detected)) {
		RETURN_CTORW(&charset);
	}

	ZVAL_STRING(&charset, "UTF-16");

	/**
	 * Check for UTF-16 encoding
	 */
	PHALCON_CALL_FUNCTIONW(&detected, "mb_detect_encoding", str, &charset, &strict_check);
	if (zend_is_true(&detected)) {
		RETURN_CTORW(&charset);
	}

	ZVAL_STRING(&charset, "UTF-8");

	/**
	 * Check for UTF-8 encoding
	 */
	PHALCON_CALL_FUNCTIONW(&detected, "mb_detect_encoding", str, &charset, &strict_check);
	if (zend_is_true(&detected)) {
		RETURN_CTORW(&charset);
	}

	ZVAL_STRING(&charset, "ISO-8859-1");

	/**
	 * Check for ISO-8859-1 encoding
	 */
	PHALCON_CALL_FUNCTIONW(&detected, "mb_detect_encoding", str, &charset, &strict_check);
	if (zend_is_true(&detected)) {
		RETURN_CTORW(&charset);
	}

	ZVAL_STRING(&charset, "ASCII");

	/**
	 * Check for ASCII encoding
	 */
	PHALCON_CALL_FUNCTIONW(&detected, "mb_detect_encoding", str, &charset, &strict_check);
	if (zend_is_true(&detected)) {
		RETURN_CTORW(&charset);
	}

	/**
	 * Fallback to global detection
	 */
	PHALCON_RETURN_CALL_FUNCTIONW("mb_detect_encoding", str);
}
Ejemplo n.º 7
0
/**
 * Closes the logger
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Logger_Adapter_Stream, close)
{
	zval *stream = phalcon_read_property(getThis(), SL("_stream"), PH_NOISY);
	PHALCON_RETURN_CALL_FUNCTIONW("fclose", stream);
}
Ejemplo n.º 8
0
/**
 * Returns a list of available modes
 *
 * @return array
 */
PHP_METHOD(Phalcon_Crypt, getAvailableModes){

	PHALCON_RETURN_CALL_FUNCTIONW("mcrypt_list_modes");
}
Ejemplo n.º 9
0
/**
 * Returns a list of available cyphers
 *
 * @return array
 */
PHP_METHOD(Phalcon_Crypt, getAvailableCiphers){

	PHALCON_RETURN_CALL_FUNCTIONW("mcrypt_list_algorithms");
}
Ejemplo n.º 10
0
/**
 * Returns a list of available modes
 *
 * @return array
 */
PHP_METHOD(Phalcon_Crypt, getAvailableMethods){

	PHALCON_RETURN_CALL_FUNCTIONW("openssl_get_cipher_methods");
}