Skip to content

Commit

Permalink
Removed unused variables, added Logger\Syslog and Logger\Stream adapt…
Browse files Browse the repository at this point in the history
…ers, added missing methods in Phalcon\Crypt
  • Loading branch information
phalcon committed Apr 25, 2014
1 parent d136573 commit 45ec54e
Show file tree
Hide file tree
Showing 43 changed files with 936 additions and 186 deletions.
24 changes: 24 additions & 0 deletions ext/kernel/operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ void zephir_negate(zval *z TSRMLS_DC) {
}
}

void zephir_convert_to_object(zval *op) {
convert_to_object(op);
}

/**
* Cast variables converting they to other types
*/
Expand Down Expand Up @@ -388,6 +392,16 @@ void zephir_cast(zval *result, zval *var, zend_uint type){
long zephir_get_intval_ex(const zval *op) {

switch (Z_TYPE_P(op)) {
case IS_ARRAY:
return zend_hash_num_elements(Z_ARRVAL_P(op)) ? 1 : 0;
break;

#if PHP_VERSION_ID > 50400
case IS_CALLABLE:
#endif
case IS_RESOURCE:
case IS_OBJECT:
return 1;

case IS_LONG:
return Z_LVAL_P(op);
Expand All @@ -401,6 +415,7 @@ long zephir_get_intval_ex(const zval *op) {
case IS_STRING: {
long long_value = 0;
double double_value = 0;

ASSUME(Z_STRVAL_P(op) != NULL);
zend_uchar type = is_numeric_string(Z_STRVAL_P(op), Z_STRLEN_P(op), &long_value, &double_value, 0);
if (type == IS_LONG) {
Expand All @@ -426,6 +441,15 @@ double zephir_get_doubleval_ex(const zval *op) {
double double_value = 0;

switch (Z_TYPE_P(op)) {
case IS_ARRAY:
return zend_hash_num_elements(Z_ARRVAL_P(op)) ? (double) 1 : 0;
break;
#if PHP_VERSION_ID > 50400
case IS_CALLABLE:
#endif
case IS_RESOURCE:
case IS_OBJECT:
return (double) 1;
case IS_LONG:
return (double) Z_LVAL_P(op);
case IS_BOOL:
Expand Down
1 change: 1 addition & 0 deletions ext/kernel/operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ int zephir_compare_strict_long(zval *op1, long op2 TSRMLS_DC);
int zephir_compare_strict_bool(zval *op1, zend_bool op2 TSRMLS_DC);

void zephir_cast(zval *result, zval *var, zend_uint type);
void zephir_convert_to_object(zval *op);
long zephir_get_intval_ex(const zval *op);
double zephir_get_doubleval_ex(const zval *op);
zend_bool zephir_get_boolval_ex(const zval *op);
Expand Down
4 changes: 2 additions & 2 deletions ext/phalcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ zend_class_entry *phalcon_annotations_adapter_ce;
zend_class_entry *phalcon_db_adapter_pdo_ce;
zend_class_entry *phalcon_db_dialect_ce;
zend_class_entry *phalcon_mvc_model_metadata_ce;
zend_class_entry *phalcon_logger_adapter_ce;
zend_class_entry *phalcon_mvc_model_exception_ce;
zend_class_entry *phalcon_assets_resource_ce;
zend_class_entry *phalcon_config_ce;
Expand All @@ -116,7 +117,6 @@ zend_class_entry *phalcon_session_adapter_ce;
zend_class_entry *phalcon_acl_adapter_ce;
zend_class_entry *phalcon_cache_frontend_data_ce;
zend_class_entry *phalcon_di_factorydefault_ce;
zend_class_entry *phalcon_logger_adapter_ce;
zend_class_entry *phalcon_logger_formatter_ce;
zend_class_entry *phalcon_mvc_model_transaction_exception_ce;
zend_class_entry *phalcon_mvc_router_ce;
Expand Down Expand Up @@ -590,6 +590,7 @@ static PHP_MINIT_FUNCTION(phalcon)
ZEPHIR_INIT(Phalcon_Db_Adapter_Pdo);
ZEPHIR_INIT(Phalcon_Db_Dialect);
ZEPHIR_INIT(Phalcon_Mvc_Model_MetaData);
ZEPHIR_INIT(Phalcon_Logger_Adapter);
ZEPHIR_INIT(Phalcon_Mvc_Model_Exception);
ZEPHIR_INIT(Phalcon_Assets_Resource);
ZEPHIR_INIT(Phalcon_Config);
Expand All @@ -604,7 +605,6 @@ static PHP_MINIT_FUNCTION(phalcon)
ZEPHIR_INIT(Phalcon_Acl_Adapter);
ZEPHIR_INIT(Phalcon_Cache_Frontend_Data);
ZEPHIR_INIT(Phalcon_Di_FactoryDefault);
ZEPHIR_INIT(Phalcon_Logger_Adapter);
ZEPHIR_INIT(Phalcon_Logger_Formatter);
ZEPHIR_INIT(Phalcon_Mvc_Model_Transaction_Exception);
ZEPHIR_INIT(Phalcon_Mvc_Router);
Expand Down
22 changes: 11 additions & 11 deletions ext/phalcon/cache/backend/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, get) {
ZEPHIR_OBS_VAR(cacheDir);
_1 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string_fetch(&cacheDir, _1, SS("cacheDir"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 90);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 89);
return;
}
ZEPHIR_INIT_VAR(cacheFile);
Expand Down Expand Up @@ -178,7 +178,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, get) {
ZEPHIR_CONCAT_SVS(_5, "Cache file ", cacheFile, " could not be opened");
ZEPHIR_CALL_METHOD(NULL, _4, "__construct", NULL, _5);
zephir_check_call_status();
zephir_throw_exception_debug(_4, "phalcon/cache/backend/file.zep", 126 TSRMLS_CC);
zephir_throw_exception_debug(_4, "phalcon/cache/backend/file.zep", 125 TSRMLS_CC);
ZEPHIR_MM_RESTORE();
return;
}
Expand Down Expand Up @@ -234,15 +234,15 @@ PHP_METHOD(Phalcon_Cache_Backend_File, save) {
ZEPHIR_CONCAT_VV(lastKey, _0, keyName);
}
if (!(zephir_is_true(lastKey))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "The cache must be started first", "phalcon/cache/backend/file.zep", 160);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "The cache must be started first", "phalcon/cache/backend/file.zep", 159);
return;
}
ZEPHIR_OBS_VAR(frontend);
zephir_read_property_this(&frontend, this_ptr, SL("_frontend"), PH_NOISY_CC);
ZEPHIR_OBS_VAR(cacheDir);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string_fetch(&cacheDir, _0, SS("cacheDir"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 166);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 165);
return;
}
ZEPHIR_INIT_VAR(cacheFile);
Expand All @@ -269,7 +269,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, save) {
ZEPHIR_CONCAT_SVS(_2, "Cache file ", cacheFile, " could not be written");
ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, _2);
zephir_check_call_status();
zephir_throw_exception_debug(_1, "phalcon/cache/backend/file.zep", 189 TSRMLS_CC);
zephir_throw_exception_debug(_1, "phalcon/cache/backend/file.zep", 188 TSRMLS_CC);
ZEPHIR_MM_RESTORE();
return;
}
Expand Down Expand Up @@ -307,7 +307,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, delete) {
ZEPHIR_OBS_VAR(cacheDir);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string_fetch(&cacheDir, _0, SS("cacheDir"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 216);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 215);
return;
}
_1 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
Expand Down Expand Up @@ -347,7 +347,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, queryKeys) {
ZEPHIR_OBS_VAR(cacheDir);
_0 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC);
if (!(zephir_array_isset_string_fetch(&cacheDir, _0, SS("cacheDir"), 0 TSRMLS_CC))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 238);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Unexpected inconsistency in options", "phalcon/cache/backend/file.zep", 237);
return;
}
ZEPHIR_INIT_VAR(ret);
Expand Down Expand Up @@ -500,7 +500,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, increment) {
ZEPHIR_CONCAT_SVS(_6, "Cache file ", cacheFile, " could not be opened");
ZEPHIR_CALL_METHOD(NULL, _5, "__construct", NULL, _6);
zephir_check_call_status();
zephir_throw_exception_debug(_5, "phalcon/cache/backend/file.zep", 347 TSRMLS_CC);
zephir_throw_exception_debug(_5, "phalcon/cache/backend/file.zep", 346 TSRMLS_CC);
ZEPHIR_MM_RESTORE();
return;
}
Expand All @@ -510,7 +510,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, increment) {
ZEPHIR_INIT_VAR(_7);
zephir_file_put_contents(_7, cacheFile, result TSRMLS_CC);
if (ZEPHIR_IS_FALSE(_7)) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Cache directory can't be written", "phalcon/cache/backend/file.zep", 354);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Cache directory can't be written", "phalcon/cache/backend/file.zep", 353);
return;
}
RETURN_CCTOR(result);
Expand Down Expand Up @@ -580,7 +580,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, decrement) {
ZEPHIR_CONCAT_SVS(_7, "Cache file ", cacheFile, " could not be opened");
ZEPHIR_CALL_METHOD(NULL, _6, "__construct", NULL, _7);
zephir_check_call_status();
zephir_throw_exception_debug(_6, "phalcon/cache/backend/file.zep", 407 TSRMLS_CC);
zephir_throw_exception_debug(_6, "phalcon/cache/backend/file.zep", 405 TSRMLS_CC);
ZEPHIR_MM_RESTORE();
return;
}
Expand All @@ -590,7 +590,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, decrement) {
ZEPHIR_INIT_VAR(_8);
zephir_file_put_contents(_8, cacheFile, result TSRMLS_CC);
if (ZEPHIR_IS_FALSE(_8)) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Cache directory can't be written", "phalcon/cache/backend/file.zep", 414);
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_cache_exception_ce, "Cache directory can't be written", "phalcon/cache/backend/file.zep", 412);
return;
}
RETURN_CCTOR(result);
Expand Down
81 changes: 79 additions & 2 deletions ext/phalcon/crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#include "ext/spl/spl_exceptions.h"
#include "kernel/exception.h"
#include "kernel/memory.h"
#include "kernel/operators.h"
#include "kernel/fcall.h"
#include "kernel/string.h"
#include "kernel/concat.h"


/*
Expand Down Expand Up @@ -199,7 +202,8 @@ PHP_METHOD(Phalcon_Crypt, getKey) {
*/
PHP_METHOD(Phalcon_Crypt, encrypt) {

zval *text_param = NULL, *key = NULL;
int ZEPHIR_LAST_CALL_STATUS;
zval *text_param = NULL, *key = NULL, *encryptKey = NULL, *ivSize = NULL, *iv = NULL, *cipher, *mode, _0, *_1 = NULL;
zval *text = NULL;

ZEPHIR_MM_GROW();
Expand All @@ -221,6 +225,38 @@ PHP_METHOD(Phalcon_Crypt, encrypt) {
}


if (!((zephir_function_exists_ex(SS("mcrypt_get_iv_size") TSRMLS_CC) == SUCCESS))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "mcrypt extension is required", "phalcon/crypt.zep", 131);
return;
}
if (Z_TYPE_P(key) == IS_NULL) {
ZEPHIR_OBS_VAR(encryptKey);
zephir_read_property_this(&encryptKey, this_ptr, SL("_key"), PH_NOISY_CC);
} else {
ZEPHIR_CPY_WRT(encryptKey, key);
}
if (ZEPHIR_IS_EMPTY(encryptKey)) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Encryption key cannot be empty", "phalcon/crypt.zep", 141);
return;
}
ZEPHIR_OBS_VAR(cipher);
zephir_read_property_this(&cipher, this_ptr, SL("_cipher"), PH_NOISY_CC);
ZEPHIR_OBS_VAR(mode);
zephir_read_property_this(&mode, this_ptr, SL("_mode"), PH_NOISY_CC);
ZEPHIR_CALL_FUNCTION(&ivSize, "mcrypt_get_iv_size", NULL, cipher, mode);
zephir_check_call_status();
if (ZEPHIR_LT_LONG(ivSize, zephir_fast_strlen_ev(encryptKey))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm", "phalcon/crypt.zep", 148);
return;
}
ZEPHIR_SINIT_VAR(_0);
ZVAL_LONG(&_0, 2);
ZEPHIR_CALL_FUNCTION(&iv, "mcrypt_create_iv", NULL, ivSize, &_0);
zephir_check_call_status();
ZEPHIR_CALL_FUNCTION(&_1, "mcrypt_encrypt", NULL, cipher, encryptKey, text, mode, iv);
zephir_check_call_status();
ZEPHIR_CONCAT_VV(return_value, iv, _1);
RETURN_MM();

}

Expand All @@ -237,7 +273,9 @@ PHP_METHOD(Phalcon_Crypt, encrypt) {
*/
PHP_METHOD(Phalcon_Crypt, decrypt) {

zval *text_param = NULL, *key = NULL;
zephir_nts_static zephir_fcall_cache_entry *_1 = NULL;
int ZEPHIR_LAST_CALL_STATUS;
zval *text_param = NULL, *key = NULL, *decryptKey = NULL, *ivSize = NULL, *cipher, *mode, *keySize, *_0 = NULL, _2, *_3 = NULL;
zval *text = NULL;

ZEPHIR_MM_GROW();
Expand All @@ -259,6 +297,45 @@ PHP_METHOD(Phalcon_Crypt, decrypt) {
}


if (!((zephir_function_exists_ex(SS("mcrypt_get_iv_size") TSRMLS_CC) == SUCCESS))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "mcrypt extension is required", "phalcon/crypt.zep", 171);
return;
}
if (Z_TYPE_P(key) == IS_NULL) {
ZEPHIR_OBS_VAR(decryptKey);
zephir_read_property_this(&decryptKey, this_ptr, SL("_key"), PH_NOISY_CC);
} else {
ZEPHIR_CPY_WRT(decryptKey, key);
}
if (ZEPHIR_IS_EMPTY(decryptKey)) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Decryption key cannot be empty", "phalcon/crypt.zep", 181);
return;
}
ZEPHIR_OBS_VAR(cipher);
zephir_read_property_this(&cipher, this_ptr, SL("_cipher"), PH_NOISY_CC);
ZEPHIR_OBS_VAR(mode);
zephir_read_property_this(&mode, this_ptr, SL("_mode"), PH_NOISY_CC);
ZEPHIR_CALL_FUNCTION(&ivSize, "mcrypt_get_iv_size", NULL, cipher, mode);
zephir_check_call_status();
ZEPHIR_INIT_VAR(keySize);
ZVAL_LONG(keySize, zephir_fast_strlen_ev(decryptKey));
if (ZEPHIR_GT(keySize, ivSize)) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm", "phalcon/crypt.zep", 190);
return;
}
if (ZEPHIR_GT_LONG(keySize, zephir_fast_strlen_ev(text))) {
ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_crypt_exception_ce, "Size of IV is larger than text to decrypt", "phalcon/crypt.zep", 194);
return;
}
ZEPHIR_CALL_FUNCTION(&_0, "substr", &_1, text, ivSize);
zephir_check_call_status();
ZEPHIR_SINIT_VAR(_2);
ZVAL_LONG(&_2, 0);
ZEPHIR_CALL_FUNCTION(&_3, "substr", &_1, text, &_2, ivSize);
zephir_check_call_status();
ZEPHIR_RETURN_CALL_FUNCTION("mcrypt_decrypt", NULL, cipher, decryptKey, _0, mode, _3);
zephir_check_call_status();
RETURN_MM();

}

Expand Down
14 changes: 11 additions & 3 deletions ext/phalcon/db/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include "kernel/array.h"
#include "kernel/concat.h"
#include "kernel/fcall.h"
#include "ext/spl/spl_exceptions.h"
#include "kernel/exception.h"
#include "kernel/operators.h"
#include "kernel/hash.h"
#include "kernel/string.h"
#include "ext/spl/spl_exceptions.h"


/*
Expand Down Expand Up @@ -162,10 +162,18 @@ PHP_METHOD(Phalcon_Db_Adapter, __construct) {

int ZEPHIR_LAST_CALL_STATUS;
zend_class_entry *_2;
zval *descriptor, *dialectClass, *_0, *_1;
zval *descriptor_param = NULL, *dialectClass, *_0, *_1;
zval *descriptor = NULL;

ZEPHIR_MM_GROW();
zephir_fetch_params(1, 1, 0, &descriptor);
zephir_fetch_params(1, 1, 0, &descriptor_param);

if (unlikely(Z_TYPE_P(descriptor_param) != IS_ARRAY)) {
zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'descriptor' must be an array") TSRMLS_CC);
RETURN_MM_NULL();
}

descriptor = descriptor_param;



Expand Down
Loading

0 comments on commit 45ec54e

Please sign in to comment.