From 45ec54e9b589df032fcad90dc68ad868fbfe5186 Mon Sep 17 00:00:00 2001 From: phalcon Date: Fri, 25 Apr 2014 09:43:22 -0500 Subject: [PATCH] Removed unused variables, added Logger\Syslog and Logger\Stream adapters, added missing methods in Phalcon\Crypt --- ext/kernel/operators.c | 24 +++ ext/kernel/operators.h | 1 + ext/phalcon.c | 4 +- ext/phalcon/cache/backend/file.c | 22 +-- ext/phalcon/crypt.c | 81 ++++++++- ext/phalcon/db/adapter.c | 14 +- ext/phalcon/db/adapter/pdo.c | 34 ++-- ext/phalcon/db/adapter/pdo/mysql.c | 56 +++--- ext/phalcon/di/service.c | 44 +++-- ext/phalcon/http/request.c | 41 +++-- ext/phalcon/http/request.h | 6 +- ext/phalcon/logger/adapter/stream.c | 170 +++++++++++++++++- ext/phalcon/logger/adapter/stream.h | 23 +++ ext/phalcon/logger/adapter/syslog.c | 166 ++++++++++++++++- ext/phalcon/logger/adapter/syslog.h | 23 +++ ext/phalcon/tag.c | 4 +- ext/phalcon/tag/select.c | 4 +- optimizers/PhalconCssminOptimizer.php | 2 +- optimizers/PhalconEscapeCssOptimizer.php | 2 +- optimizers/PhalconEscapeJsOptimizer.php | 2 +- optimizers/PhalconFilterAlphanumOptimizer.php | 2 +- optimizers/PhalconFixPathOptimizer.php | 2 +- optimizers/PhalconGetUriOptimizer.php | 2 +- optimizers/PhalconJsminOptimizer.php | 2 +- ...alconPossibleAutoloadFilepathOptimizer.php | 2 +- .../PhalconPrepareVirtualPathOptimizer.php | 2 +- optimizers/PhalconReplacePathsOptimizer.php | 2 +- .../PhannotParseAnnotationsOptimizer.php | 2 +- optimizers/PhqlParsePhqlOptimizer.php | 2 +- optimizers/PhvoltParseViewOptimizer.php | 2 +- phalcon/cache/backend/file.zep | 8 +- phalcon/cache/backend/memory.zep | 4 +- phalcon/crypt.zep | 55 ++++++ phalcon/db/adapter.zep | 2 +- phalcon/db/adapter/pdo.zep | 15 +- phalcon/db/adapter/pdo/mysql.zep | 32 ++-- phalcon/debug.zep | 16 +- phalcon/di/service.zep | 22 ++- phalcon/events/manager.zep | 2 +- phalcon/http/request.zep | 6 +- phalcon/logger/adapter/stream.zep | 100 ++++++++++- phalcon/logger/adapter/syslog.zep | 95 +++++++++- phalcon/logger/formatter.zep | 22 +-- 43 files changed, 936 insertions(+), 186 deletions(-) diff --git a/ext/kernel/operators.c b/ext/kernel/operators.c index 29201294846..b052d5c698c 100644 --- a/ext/kernel/operators.c +++ b/ext/kernel/operators.c @@ -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 */ @@ -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); @@ -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) { @@ -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: diff --git a/ext/kernel/operators.h b/ext/kernel/operators.h index f5f3faa15ac..ee9a10f4f00 100644 --- a/ext/kernel/operators.h +++ b/ext/kernel/operators.h @@ -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); diff --git a/ext/phalcon.c b/ext/phalcon.c index a25ba94a64a..cb7115ec484 100644 --- a/ext/phalcon.c +++ b/ext/phalcon.c @@ -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; @@ -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; @@ -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); @@ -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); diff --git a/ext/phalcon/cache/backend/file.c b/ext/phalcon/cache/backend/file.c index a62b90ef55b..9bd58055b57 100644 --- a/ext/phalcon/cache/backend/file.c +++ b/ext/phalcon/cache/backend/file.c @@ -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); @@ -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; } @@ -234,7 +234,7 @@ 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); @@ -242,7 +242,7 @@ PHP_METHOD(Phalcon_Cache_Backend_File, save) { 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); @@ -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; } @@ -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); @@ -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); @@ -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; } @@ -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); @@ -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; } @@ -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); diff --git a/ext/phalcon/crypt.c b/ext/phalcon/crypt.c index 75e9227f4a9..b12812b9e6b 100644 --- a/ext/phalcon/crypt.c +++ b/ext/phalcon/crypt.c @@ -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" /* @@ -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(); @@ -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(); } @@ -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(); @@ -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(); } diff --git a/ext/phalcon/db/adapter.c b/ext/phalcon/db/adapter.c index 492b7100108..a83e5b75da3 100644 --- a/ext/phalcon/db/adapter.c +++ b/ext/phalcon/db/adapter.c @@ -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" /* @@ -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; diff --git a/ext/phalcon/db/adapter/pdo.c b/ext/phalcon/db/adapter/pdo.c index 68a88345f96..4325529c6a6 100644 --- a/ext/phalcon/db/adapter/pdo.c +++ b/ext/phalcon/db/adapter/pdo.c @@ -12,8 +12,9 @@ #include #include "kernel/main.h" -#include "kernel/exception.h" #include "kernel/fcall.h" +#include "ext/spl/spl_exceptions.h" +#include "kernel/exception.h" #include "kernel/memory.h" #include "kernel/operators.h" #include "kernel/object.h" @@ -22,7 +23,6 @@ #include "kernel/concat.h" #include "kernel/string.h" #include "ext/pdo/php_pdo_driver.h" -#include "ext/spl/spl_exceptions.h" /* @@ -89,17 +89,21 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, __construct) { zephir_nts_static zephir_fcall_cache_entry *_0 = NULL; int ZEPHIR_LAST_CALL_STATUS; - zval *descriptor; + zval *descriptor_param = NULL; + 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; - if (Z_TYPE_P(descriptor) != IS_ARRAY) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "The descriptor must be an array", "phalcon/db/adapter/pdo.zep", 66); - return; - } ZEPHIR_CALL_METHOD(NULL, this_ptr, "connect", NULL, descriptor); zephir_check_call_status(); ZEPHIR_CALL_PARENT(NULL, phalcon_db_adapter_pdo_ce, this_ptr, "__construct", &_0, descriptor); @@ -190,10 +194,10 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect) { } ZEPHIR_INIT_VAR(_4); ZVAL_LONG(_4, 2); - zephir_array_update_long(&options, 3, &_4, PH_COPY | PH_SEPARATE, "phalcon/db/adapter/pdo.zep", 141); + zephir_array_update_long(&options, 3, &_4, PH_COPY | PH_SEPARATE, "phalcon/db/adapter/pdo.zep", 136); if (zephir_array_isset_string_fetch(&persistent, descriptor, SS("persistent"), 1 TSRMLS_CC)) { if (zephir_is_true(persistent)) { - zephir_array_update_long(&options, 12, &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE, "phalcon/db/adapter/pdo.zep", 148); + zephir_array_update_long(&options, 12, &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE, "phalcon/db/adapter/pdo.zep", 143); } } ZEPHIR_INIT_LNVAR(_3); @@ -280,7 +284,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared) { return; } if (Z_TYPE_P(placeholders) != IS_ARRAY) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "Placeholders must be an array", "phalcon/db/adapter/pdo.zep", 194); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "Placeholders must be an array", "phalcon/db/adapter/pdo.zep", 189); return; } zephir_is_iterable(placeholders, &_1, &_0, 0, 0); @@ -297,14 +301,14 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared) { if (Z_TYPE_P(wildcard) == IS_STRING) { ZEPHIR_CPY_WRT(parameter, wildcard); } else { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "Invalid bind parameter (1)", "phalcon/db/adapter/pdo.zep", 205); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "Invalid bind parameter (1)", "phalcon/db/adapter/pdo.zep", 200); return; } } if (Z_TYPE_P(dataTypes) == IS_ARRAY) { ZEPHIR_OBS_NVAR(type); if (!(zephir_array_isset_fetch(&type, dataTypes, wildcard, 0 TSRMLS_CC))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "Invalid bind type parameter (2)", "phalcon/db/adapter/pdo.zep", 212); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "Invalid bind type parameter (2)", "phalcon/db/adapter/pdo.zep", 207); return; } if (ZEPHIR_IS_LONG(type, 32)) { @@ -766,7 +770,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback) { ZEPHIR_OBS_VAR(transactionLevel); zephir_read_property_this(&transactionLevel, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (!(zephir_is_true(transactionLevel))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "There is no active transaction", "phalcon/db/adapter/pdo.zep", 536); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "There is no active transaction", "phalcon/db/adapter/pdo.zep", 531); return; } if (ZEPHIR_IS_LONG(transactionLevel, 1)) { @@ -845,7 +849,7 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit) { ZEPHIR_OBS_VAR(transactionLevel); zephir_read_property_this(&transactionLevel, this_ptr, SL("_transactionLevel"), PH_NOISY_CC); if (!(zephir_is_true(transactionLevel))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "There is no active transaction", "phalcon/db/adapter/pdo.zep", 615); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "There is no active transaction", "phalcon/db/adapter/pdo.zep", 610); return; } if (ZEPHIR_IS_LONG(transactionLevel, 1)) { diff --git a/ext/phalcon/db/adapter/pdo/mysql.c b/ext/phalcon/db/adapter/pdo/mysql.c index 9f87fdbfdd1..650c0bb0594 100644 --- a/ext/phalcon/db/adapter/pdo/mysql.c +++ b/ext/phalcon/db/adapter/pdo/mysql.c @@ -119,12 +119,12 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier) { */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns) { - zephir_fcall_cache_entry *_14 = NULL; - zephir_nts_static zephir_fcall_cache_entry *_9 = NULL; + zephir_fcall_cache_entry *_13 = NULL; + zephir_nts_static zephir_fcall_cache_entry *_8 = NULL; HashTable *_3; HashPosition _2; int ZEPHIR_LAST_CALL_STATUS; - zval *table_param = NULL, *schema_param = NULL, *describe = NULL, *columns, *columnType = NULL, *field = NULL, *definition = NULL, *oldColumn = NULL, *dialect, *sizePattern, *matches = NULL, *matchOne = NULL, *columnName, *_0 = NULL, *_1 = NULL, **_4, *_5 = NULL, *_6 = NULL, _7 = zval_used_for_init, *_8 = NULL, *_10, *_11, *_12, *_13 = NULL; + zval *table_param = NULL, *schema_param = NULL, *describe = NULL, *columns, *columnType = NULL, *field = NULL, *definition = NULL, *oldColumn = NULL, *dialect, *sizePattern, *matches = NULL, *matchOne = NULL, *columnName, *_0 = NULL, *_1 = NULL, **_4, *_5 = NULL, *_6 = NULL, *_7 = NULL, *_9, *_10, *_11, *_12 = NULL; zval *table = NULL, *schema = NULL; ZEPHIR_MM_GROW(); @@ -165,13 +165,13 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns) { ZEPHIR_OBS_NVAR(columnType); zephir_array_fetch_long(&columnType, field, 1, PH_NOISY TSRMLS_CC); while (1) { - if (zephir_memnstr_str(columnType, SL("enum"), "phalcon/db/adapter/pdo/mysql.zep", 123)) { + if (zephir_memnstr_str(columnType, SL("enum"), "phalcon/db/adapter/pdo/mysql.zep", 125)) { ZEPHIR_INIT_NVAR(_1); ZVAL_LONG(_1, 2); zephir_array_update_string(&definition, SL("type"), &_1, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("int"), "phalcon/db/adapter/pdo/mysql.zep", 131)) { + if (zephir_memnstr_str(columnType, SL("int"), "phalcon/db/adapter/pdo/mysql.zep", 133)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 0); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); @@ -181,19 +181,19 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns) { zephir_array_update_string(&definition, SL("bindType"), &_6, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("varchar"), "phalcon/db/adapter/pdo/mysql.zep", 141)) { + if (zephir_memnstr_str(columnType, SL("varchar"), "phalcon/db/adapter/pdo/mysql.zep", 143)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 2); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("datetime"), "phalcon/db/adapter/pdo/mysql.zep", 149)) { + if (zephir_memnstr_str(columnType, SL("datetime"), "phalcon/db/adapter/pdo/mysql.zep", 151)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 4); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("decimal"), "phalcon/db/adapter/pdo/mysql.zep", 157)) { + if (zephir_memnstr_str(columnType, SL("decimal"), "phalcon/db/adapter/pdo/mysql.zep", 159)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 3); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); @@ -203,29 +203,25 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns) { zephir_array_update_string(&definition, SL("bindType"), &_6, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("char"), "phalcon/db/adapter/pdo/mysql.zep", 167)) { + if (zephir_memnstr_str(columnType, SL("char"), "phalcon/db/adapter/pdo/mysql.zep", 169)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 5); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("date"), "phalcon/db/adapter/pdo/mysql.zep", 175)) { + if (zephir_memnstr_str(columnType, SL("date"), "phalcon/db/adapter/pdo/mysql.zep", 177)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 1); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("text"), "phalcon/db/adapter/pdo/mysql.zep", 183)) { + if (zephir_memnstr_str(columnType, SL("text"), "phalcon/db/adapter/pdo/mysql.zep", 185)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 6); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); break; } - ZEPHIR_SINIT_NVAR(_7); - ZVAL_STRING(&_7, "float", 0); - ZEPHIR_INIT_NVAR(_5); - zephir_fast_strpos(_5, columnType, &_7, 0 ); - if (zephir_is_true(_5)) { + if (zephir_memnstr_str(columnType, SL("float"), "phalcon/db/adapter/pdo/mysql.zep", 193)) { ZEPHIR_INIT_NVAR(_5); ZVAL_LONG(_5, 7); zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); @@ -240,21 +236,21 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns) { zephir_array_update_string(&definition, SL("type"), &_5, PH_COPY | PH_SEPARATE); break; } - if (zephir_memnstr_str(columnType, SL("("), "phalcon/db/adapter/pdo/mysql.zep", 208)) { + if (zephir_memnstr_str(columnType, SL("("), "phalcon/db/adapter/pdo/mysql.zep", 210)) { ZEPHIR_INIT_NVAR(matches); ZVAL_NULL(matches); Z_SET_ISREF_P(matches); - ZEPHIR_CALL_FUNCTION(&_8, "preg_match", &_9, sizePattern, columnType, matches); + ZEPHIR_CALL_FUNCTION(&_7, "preg_match", &_8, sizePattern, columnType, matches); Z_UNSET_ISREF_P(matches); zephir_check_call_status(); - if (zephir_is_true(_8)) { + if (zephir_is_true(_7)) { ZEPHIR_OBS_NVAR(matchOne); if (zephir_array_isset_long_fetch(&matchOne, matches, 1, 0 TSRMLS_CC)) { zephir_array_update_string(&definition, SL("size"), &matchOne, PH_COPY | PH_SEPARATE); } } } - if (zephir_memnstr_str(columnType, SL("unsigned"), "phalcon/db/adapter/pdo/mysql.zep", 220)) { + if (zephir_memnstr_str(columnType, SL("unsigned"), "phalcon/db/adapter/pdo/mysql.zep", 222)) { zephir_array_update_string(&definition, SL("unsigned"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } if (!(zephir_is_true(oldColumn))) { @@ -262,24 +258,24 @@ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns) { } else { zephir_array_update_string(&definition, SL("after"), &oldColumn, PH_COPY | PH_SEPARATE); } - zephir_array_fetch_long(&_10, field, 3, PH_NOISY | PH_READONLY TSRMLS_CC); - if (ZEPHIR_IS_STRING(_10, "PRI")) { + zephir_array_fetch_long(&_9, field, 3, PH_NOISY | PH_READONLY TSRMLS_CC); + if (ZEPHIR_IS_STRING(_9, "PRI")) { zephir_array_update_string(&definition, SL("primary"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } - zephir_array_fetch_long(&_11, field, 2, PH_NOISY | PH_READONLY TSRMLS_CC); - if (ZEPHIR_IS_STRING(_11, "NO")) { + zephir_array_fetch_long(&_10, field, 2, PH_NOISY | PH_READONLY TSRMLS_CC); + if (ZEPHIR_IS_STRING(_10, "NO")) { zephir_array_update_string(&definition, SL("notNull"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } - zephir_array_fetch_long(&_12, field, 5, PH_NOISY | PH_READONLY TSRMLS_CC); - if (ZEPHIR_IS_STRING(_12, "auto_increment")) { + zephir_array_fetch_long(&_11, field, 5, PH_NOISY | PH_READONLY TSRMLS_CC); + if (ZEPHIR_IS_STRING(_11, "auto_increment")) { zephir_array_update_string(&definition, SL("autoIncrement"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } zephir_array_fetch_long(&columnName, field, 0, PH_NOISY | PH_READONLY TSRMLS_CC); - ZEPHIR_INIT_LNVAR(_13); - object_init_ex(_13, phalcon_db_column_ce); - ZEPHIR_CALL_METHOD(NULL, _13, "__construct", &_14, columnName, definition); + ZEPHIR_INIT_LNVAR(_12); + object_init_ex(_12, phalcon_db_column_ce); + ZEPHIR_CALL_METHOD(NULL, _12, "__construct", &_13, columnName, definition); zephir_check_call_status(); - zephir_array_append(&columns, _13, PH_SEPARATE); + zephir_array_append(&columns, _12, PH_SEPARATE); ZEPHIR_CPY_WRT(oldColumn, columnName); } RETURN_CCTOR(columns); diff --git a/ext/phalcon/di/service.c b/ext/phalcon/di/service.c index b685a39086b..ffeb5c590d1 100644 --- a/ext/phalcon/di/service.c +++ b/ext/phalcon/di/service.c @@ -302,7 +302,7 @@ PHP_METHOD(Phalcon_Di_Service, resolve) { ZEPHIR_CONCAT_SVS(_4, "Service '", _3, "' cannot be resolved"); ZEPHIR_CALL_METHOD(NULL, _2, "__construct", NULL, _4); zephir_check_call_status(); - zephir_throw_exception_debug(_2, "phalcon/di/service.zep", 197 TSRMLS_CC); + zephir_throw_exception_debug(_2, "phalcon/di/service.zep", 199 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } @@ -322,32 +322,36 @@ PHP_METHOD(Phalcon_Di_Service, resolve) { */ PHP_METHOD(Phalcon_Di_Service, setParameter) { - zval *position_param = NULL, *parameter, *definition, *arguments; + zval *parameter = NULL; + zval *position_param = NULL, *parameter_param = NULL, *definition, *arguments; int position; ZEPHIR_MM_GROW(); - zephir_fetch_params(1, 2, 0, &position_param, ¶meter); + zephir_fetch_params(1, 2, 0, &position_param, ¶meter_param); position = zephir_get_intval(position_param); + if (unlikely(Z_TYPE_P(parameter_param) != IS_ARRAY)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'parameter' must be an array") TSRMLS_CC); + RETURN_MM_NULL(); + } + + parameter = parameter_param; + ZEPHIR_OBS_VAR(definition); zephir_read_property_this(&definition, this_ptr, SL("_definition"), PH_NOISY_CC); if (Z_TYPE_P(definition) != IS_ARRAY) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "Definition must be an array to update its parameters", "phalcon/di/service.zep", 223); - return; - } - if (Z_TYPE_P(parameter) != IS_ARRAY) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The parameter must be an array", "phalcon/di/service.zep", 227); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "Definition must be an array to update its parameters", "phalcon/di/service.zep", 225); return; } ZEPHIR_OBS_VAR(arguments); if (zephir_array_isset_string_fetch(&arguments, definition, SS("arguments"), 0 TSRMLS_CC)) { - zephir_array_update_long(&arguments, position, ¶meter, PH_COPY | PH_SEPARATE, "phalcon/di/service.zep", 234); + zephir_array_update_long(&arguments, position, ¶meter, PH_COPY | PH_SEPARATE, "phalcon/di/service.zep", 232); } else { ZEPHIR_INIT_BNVAR(arguments); array_init_size(arguments, 2); - zephir_array_update_long(&arguments, position, ¶meter, PH_COPY, "phalcon/di/service.zep", 236); + zephir_array_update_long(&arguments, position, ¶meter, PH_COPY, "phalcon/di/service.zep", 234); } zephir_array_update_string(&definition, SL("arguments"), &arguments, PH_COPY | PH_SEPARATE); zephir_update_property_this(this_ptr, SL("_definition"), definition TSRMLS_CC); @@ -375,7 +379,7 @@ PHP_METHOD(Phalcon_Di_Service, getParameter) { ZEPHIR_OBS_VAR(definition); zephir_read_property_this(&definition, this_ptr, SL("_definition"), PH_NOISY_CC); if (Z_TYPE_P(definition) != IS_ARRAY) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "Definition must be an array to obtain its parameters", "phalcon/di/service.zep", 264); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "Definition must be an array to obtain its parameters", "phalcon/di/service.zep", 262); return; } if (zephir_array_isset_string_fetch(&arguments, definition, SS("arguments"), 1 TSRMLS_CC)) { @@ -396,26 +400,34 @@ PHP_METHOD(Phalcon_Di_Service, getParameter) { PHP_METHOD(Phalcon_Di_Service, __set_state) { int ZEPHIR_LAST_CALL_STATUS; - zval *attributes, *name, *definition, *shared; + zval *attributes_param = NULL, *name, *definition, *shared; + zval *attributes = NULL; ZEPHIR_MM_GROW(); - zephir_fetch_params(1, 1, 0, &attributes); + zephir_fetch_params(1, 1, 0, &attributes_param); + + if (unlikely(Z_TYPE_P(attributes_param) != IS_ARRAY)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'attributes' must be an array") TSRMLS_CC); + RETURN_MM_NULL(); + } + + attributes = attributes_param; ZEPHIR_OBS_VAR(name); if (!(zephir_array_isset_string_fetch(&name, attributes, SS("_name"), 0 TSRMLS_CC))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The attribute '_name' is required", "phalcon/di/service.zep", 290); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The attribute '_name' is required", "phalcon/di/service.zep", 288); return; } ZEPHIR_OBS_VAR(definition); if (!(zephir_array_isset_string_fetch(&definition, attributes, SS("_definition"), 0 TSRMLS_CC))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The attribute '_name' is required", "phalcon/di/service.zep", 294); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The attribute '_name' is required", "phalcon/di/service.zep", 292); return; } ZEPHIR_OBS_VAR(shared); if (!(zephir_array_isset_string_fetch(&shared, attributes, SS("_shared"), 0 TSRMLS_CC))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The attribute '_shared' is required", "phalcon/di/service.zep", 298); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_di_exception_ce, "The attribute '_shared' is required", "phalcon/di/service.zep", 296); return; } object_init_ex(return_value, phalcon_di_service_ce); diff --git a/ext/phalcon/http/request.c b/ext/phalcon/http/request.c index 48680b5cf15..091c44acad7 100644 --- a/ext/phalcon/http/request.c +++ b/ext/phalcon/http/request.c @@ -613,6 +613,7 @@ PHP_METHOD(Phalcon_Http_Request, getScheme) { */ PHP_METHOD(Phalcon_Http_Request, isAjax) { + zephir_nts_static zephir_fcall_cache_entry *_2 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL, *_1; @@ -620,7 +621,7 @@ PHP_METHOD(Phalcon_Http_Request, isAjax) { ZEPHIR_INIT_VAR(_1); ZVAL_STRING(_1, "HTTP_X_REQUESTED_WITH", 0); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getheader", NULL, _1); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getheader", &_2, _1); zephir_check_temp_parameter(_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "XMLHttpRequest")); @@ -903,28 +904,29 @@ PHP_METHOD(Phalcon_Http_Request, getUserAgent) { */ PHP_METHOD(Phalcon_Http_Request, isMethod) { - HashTable *_1; - HashPosition _0; + HashTable *_2; + HashPosition _1; + zephir_nts_static zephir_fcall_cache_entry *_0 = NULL; int ZEPHIR_LAST_CALL_STATUS; - zval *methods, *httpMethod = NULL, *method = NULL, **_2; + zval *methods, *httpMethod = NULL, *method = NULL, **_3; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &methods); - ZEPHIR_CALL_METHOD(&httpMethod, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&httpMethod, this_ptr, "getmethod", &_0); zephir_check_call_status(); if (Z_TYPE_P(methods) == IS_STRING) { RETURN_MM_BOOL(ZEPHIR_IS_EQUAL(methods, httpMethod)); } else { if (Z_TYPE_P(methods) == IS_ARRAY) { - zephir_is_iterable(methods, &_1, &_0, 0, 0); + zephir_is_iterable(methods, &_2, &_1, 0, 0); for ( - ; zephir_hash_get_current_data_ex(_1, (void**) &_2, &_0) == SUCCESS - ; zephir_hash_move_forward_ex(_1, &_0) + ; zephir_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS + ; zephir_hash_move_forward_ex(_2, &_1) ) { - ZEPHIR_GET_HVALUE(method, _2); + ZEPHIR_GET_HVALUE(method, _3); if (ZEPHIR_IS_EQUAL(method, httpMethod)) { RETURN_MM_BOOL(1); } @@ -942,12 +944,13 @@ PHP_METHOD(Phalcon_Http_Request, isMethod) { */ PHP_METHOD(Phalcon_Http_Request, isPost) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "POST")); @@ -961,12 +964,13 @@ PHP_METHOD(Phalcon_Http_Request, isPost) { */ PHP_METHOD(Phalcon_Http_Request, isGet) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "GET")); @@ -979,12 +983,13 @@ PHP_METHOD(Phalcon_Http_Request, isGet) { */ PHP_METHOD(Phalcon_Http_Request, isPut) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "PUT")); @@ -997,12 +1002,13 @@ PHP_METHOD(Phalcon_Http_Request, isPut) { */ PHP_METHOD(Phalcon_Http_Request, isPatch) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "PATCH")); @@ -1015,12 +1021,13 @@ PHP_METHOD(Phalcon_Http_Request, isPatch) { */ PHP_METHOD(Phalcon_Http_Request, isHead) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "HEAD")); @@ -1033,12 +1040,13 @@ PHP_METHOD(Phalcon_Http_Request, isHead) { */ PHP_METHOD(Phalcon_Http_Request, isDelete) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "DELETE")); @@ -1051,12 +1059,13 @@ PHP_METHOD(Phalcon_Http_Request, isDelete) { */ PHP_METHOD(Phalcon_Http_Request, isOptions) { + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *_0 = NULL; ZEPHIR_MM_GROW(); - ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", NULL); + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmethod", &_1); zephir_check_call_status(); RETURN_MM_BOOL(ZEPHIR_IS_STRING(_0, "OPTIONS")); diff --git a/ext/phalcon/http/request.h b/ext/phalcon/http/request.h index 369bb11a3a2..967c13e1f65 100644 --- a/ext/phalcon/http/request.h +++ b/ext/phalcon/http/request.h @@ -137,8 +137,8 @@ ZEPHIR_INIT_FUNCS(phalcon_http_request_method_entry) { PHP_ME(Phalcon_Http_Request, has, arginfo_phalcon_http_request_has, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, hasPost, arginfo_phalcon_http_request_haspost, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, hasQuery, arginfo_phalcon_http_request_hasquery, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Http_Request, hasServer, arginfo_phalcon_http_request_hasserver, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Http_Request, getHeader, arginfo_phalcon_http_request_getheader, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Http_Request, hasServer, arginfo_phalcon_http_request_hasserver, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + PHP_ME(Phalcon_Http_Request, getHeader, arginfo_phalcon_http_request_getheader, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(Phalcon_Http_Request, getScheme, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, isAjax, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, isSoapRequested, NULL, ZEND_ACC_PUBLIC) @@ -149,7 +149,7 @@ ZEPHIR_INIT_FUNCS(phalcon_http_request_method_entry) { PHP_ME(Phalcon_Http_Request, getServerName, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, getHttpHost, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, getClientAddress, arginfo_phalcon_http_request_getclientaddress, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Http_Request, getMethod, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Http_Request, getMethod, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) PHP_ME(Phalcon_Http_Request, getUserAgent, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, isMethod, arginfo_phalcon_http_request_ismethod, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Http_Request, isPost, NULL, ZEND_ACC_PUBLIC) diff --git a/ext/phalcon/logger/adapter/stream.c b/ext/phalcon/logger/adapter/stream.c index da4225878c9..b85162a185f 100644 --- a/ext/phalcon/logger/adapter/stream.c +++ b/ext/phalcon/logger/adapter/stream.c @@ -12,6 +12,16 @@ #include #include "kernel/main.h" +#include "kernel/array.h" +#include "kernel/memory.h" +#include "kernel/string.h" +#include "kernel/exception.h" +#include "kernel/fcall.h" +#include "kernel/operators.h" +#include "kernel/concat.h" +#include "kernel/object.h" +#include "ext/spl/spl_exceptions.h" +#include "kernel/file.h" /* @@ -31,11 +41,169 @@ | Eduar Carvajal | +------------------------------------------------------------------------+ */ +/** + * Phalcon\Logger\Adapter\Stream + * + * Sends logs to a valid PHP stream + * + * + * $logger = new \Phalcon\Logger\Adapter\Stream("php://stderr"); + * $logger->log("This is a message"); + * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->error("This is another error"); + * + */ ZEPHIR_INIT_CLASS(Phalcon_Logger_Adapter_Stream) { - ZEPHIR_REGISTER_CLASS(Phalcon\\Logger\\Adapter, Stream, phalcon, logger_adapter_stream, NULL, 0); + ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Stream, phalcon, logger_adapter_stream, phalcon_logger_adapter_ce, phalcon_logger_adapter_stream_method_entry, 0); + + /** + * File handler resource + * + * @var resource + */ + zend_declare_property_null(phalcon_logger_adapter_stream_ce, SL("_stream"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_logger_adapter_stream_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); return SUCCESS; } +/** + * Phalcon\Logger\Adapter\Stream constructor + * + * @param string name + * @param array options + */ +PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct) { + + int ZEPHIR_LAST_CALL_STATUS; + zephir_nts_static zephir_fcall_cache_entry *_0 = NULL; + zval *name_param = NULL, *options = NULL, *mode, *stream = NULL, *_1; + zval *name = NULL, *_2; + + ZEPHIR_MM_GROW(); + zephir_fetch_params(1, 1, 1, &name_param, &options); + + if (unlikely(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) { + zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC); + RETURN_MM_NULL(); + } + + if (unlikely(Z_TYPE_P(name_param) == IS_STRING)) { + name = name_param; + } else { + ZEPHIR_INIT_VAR(name); + ZVAL_EMPTY_STRING(name); + } + if (!options) { + options = ZEPHIR_GLOBAL(global_null); + } + + + ZEPHIR_OBS_VAR(mode); + if (zephir_array_isset_string_fetch(&mode, options, SS("mode"), 0 TSRMLS_CC)) { + if (zephir_memnstr_str(mode, SL("r"), "phalcon/logger/adapter/stream.zep", 57)) { + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_logger_exception_ce, "Stream must be opened in append or write mode", "phalcon/logger/adapter/stream.zep", 58); + return; + } + } else { + ZEPHIR_INIT_BNVAR(mode); + ZVAL_STRING(mode, "ab", 1); + } + ZEPHIR_CALL_FUNCTION(&stream, "fopen", &_0, name, mode); + zephir_check_call_status(); + if (!(zephir_is_true(stream))) { + ZEPHIR_INIT_VAR(_1); + object_init_ex(_1, phalcon_logger_exception_ce); + ZEPHIR_INIT_VAR(_2); + ZEPHIR_CONCAT_SVS(_2, "Can't open stream '", name, "'"); + ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, _2); + zephir_check_call_status(); + zephir_throw_exception_debug(_1, "phalcon/logger/adapter/stream.zep", 69 TSRMLS_CC); + ZEPHIR_MM_RESTORE(); + return; + } + zephir_update_property_this(this_ptr, SL("_stream"), stream TSRMLS_CC); + ZEPHIR_MM_RESTORE(); + +} + +/** + * Returns the internal formatter + * + * @return Phalcon\Logger\Formatter\Line + */ +PHP_METHOD(Phalcon_Logger_Adapter_Stream, getFormatter) { + + int ZEPHIR_LAST_CALL_STATUS; + zval *formatter; + + ZEPHIR_MM_GROW(); + + ZEPHIR_OBS_VAR(formatter); + zephir_read_property_this(&formatter, this_ptr, SL("_formatter"), PH_NOISY_CC); + if (Z_TYPE_P(formatter) == IS_OBJECT) { + ZEPHIR_INIT_BNVAR(formatter); + object_init_ex(formatter, phalcon_logger_formatter_line_ce); + ZEPHIR_CALL_METHOD(NULL, formatter, "__construct", NULL); + zephir_check_call_status(); + zephir_update_property_this(this_ptr, SL("_formatter"), formatter TSRMLS_CC); + } + RETURN_CCTOR(formatter); + +} + +/** + * Writes the log to the stream itself + * + * @param string message + * @param int type + * @param int time + */ +PHP_METHOD(Phalcon_Logger_Adapter_Stream, logInternal) { + + int type, time, ZEPHIR_LAST_CALL_STATUS; + zval *message, *type_param = NULL, *time_param = NULL, *stream, *_0 = NULL, *_1 = NULL, *_2, *_3; + + ZEPHIR_MM_GROW(); + zephir_fetch_params(1, 3, 0, &message, &type_param, &time_param); + + type = zephir_get_intval(type_param); + time = zephir_get_intval(time_param); + + + ZEPHIR_OBS_VAR(stream); + zephir_read_property_this(&stream, this_ptr, SL("_stream"), PH_NOISY_CC); + if (!(zephir_is_true(stream))) { + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid", "phalcon/logger/adapter/stream.zep", 104); + return; + } + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getformatter", NULL); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(_2); + ZVAL_LONG(_2, type); + ZEPHIR_INIT_VAR(_3); + ZVAL_LONG(_3, time); + ZEPHIR_CALL_METHOD(&_1, _0, "format", NULL, message, _2, _3); + zephir_check_call_status(); + zephir_fwrite(NULL, stream, _1 TSRMLS_CC); + ZEPHIR_MM_RESTORE(); + +} + +/** + * Closes the logger + * + * @return boolean + */ +PHP_METHOD(Phalcon_Logger_Adapter_Stream, close) { + + zval *_0; + + + _0 = zephir_fetch_nproperty_this(this_ptr, SL("_stream"), PH_NOISY_CC); + RETURN_BOOL(zephir_fclose(_0 TSRMLS_CC)); + +} + diff --git a/ext/phalcon/logger/adapter/stream.h b/ext/phalcon/logger/adapter/stream.h index 2b02647dd8c..6b0fe2d2db4 100644 --- a/ext/phalcon/logger/adapter/stream.h +++ b/ext/phalcon/logger/adapter/stream.h @@ -3,3 +3,26 @@ extern zend_class_entry *phalcon_logger_adapter_stream_ce; ZEPHIR_INIT_CLASS(Phalcon_Logger_Adapter_Stream); +PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct); +PHP_METHOD(Phalcon_Logger_Adapter_Stream, getFormatter); +PHP_METHOD(Phalcon_Logger_Adapter_Stream, logInternal); +PHP_METHOD(Phalcon_Logger_Adapter_Stream, close); + +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapter_stream___construct, 0, 0, 1) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapter_stream_loginternal, 0, 0, 3) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, time) +ZEND_END_ARG_INFO() + +ZEPHIR_INIT_FUNCS(phalcon_logger_adapter_stream_method_entry) { + PHP_ME(Phalcon_Logger_Adapter_Stream, __construct, arginfo_phalcon_logger_adapter_stream___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Logger_Adapter_Stream, getFormatter, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter_Stream, logInternal, arginfo_phalcon_logger_adapter_stream_loginternal, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter_Stream, close, NULL, ZEND_ACC_PUBLIC) + PHP_FE_END +}; diff --git a/ext/phalcon/logger/adapter/syslog.c b/ext/phalcon/logger/adapter/syslog.c index 6d810d29d5d..b2637cc5db3 100644 --- a/ext/phalcon/logger/adapter/syslog.c +++ b/ext/phalcon/logger/adapter/syslog.c @@ -12,6 +12,12 @@ #include #include "kernel/main.h" +#include "kernel/operators.h" +#include "kernel/array.h" +#include "kernel/memory.h" +#include "kernel/fcall.h" +#include "kernel/object.h" +#include "kernel/exception.h" /* @@ -31,11 +37,169 @@ | Eduar Carvajal | +------------------------------------------------------------------------+ */ +/** + * Phalcon\Logger\Adapter\Syslog + * + * Sends logs to the system logger + * + * + * $logger = new \Phalcon\Logger\Adapter\Syslog("ident", array( + * 'option' => LOG_NDELAY, + * 'facility' => LOG_MAIL + * )); + * $logger->log("This is a message"); + * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->error("This is another error"); + * + */ ZEPHIR_INIT_CLASS(Phalcon_Logger_Adapter_Syslog) { - ZEPHIR_REGISTER_CLASS(Phalcon\\Logger\\Adapter, Syslog, phalcon, logger_adapter_syslog, NULL, 0); + ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Syslog, phalcon, logger_adapter_syslog, phalcon_logger_adapter_ce, phalcon_logger_adapter_syslog_method_entry, 0); + + zend_declare_property_bool(phalcon_logger_adapter_syslog_ce, SL("_opened"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_logger_adapter_syslog_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); return SUCCESS; } +/** + * Phalcon\Logger\Adapter\Syslog constructor + * + * @param string name + * @param array options + */ +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct) { + + int ZEPHIR_LAST_CALL_STATUS; + zephir_nts_static zephir_fcall_cache_entry *_0 = NULL; + zval *name, *options = NULL, *option = NULL, *facility = NULL; + + ZEPHIR_MM_GROW(); + zephir_fetch_params(1, 1, 1, &name, &options); + + if (!options) { + options = ZEPHIR_GLOBAL(global_null); + } + + + if (zephir_is_true(name)) { + ZEPHIR_OBS_VAR(option); + if (!(zephir_array_isset_string_fetch(&option, options, SS("option"), 0 TSRMLS_CC))) { + ZEPHIR_INIT_NVAR(option); + ZVAL_LONG(option, 4); + } + ZEPHIR_OBS_VAR(facility); + if (!(zephir_array_isset_string_fetch(&facility, options, SS("facility"), 0 TSRMLS_CC))) { + ZEPHIR_INIT_NVAR(facility); + ZVAL_LONG(facility, 8); + } + ZEPHIR_CALL_FUNCTION(NULL, "openlog", &_0, name, option, facility); + zephir_check_call_status(); + zephir_update_property_this(this_ptr, SL("_opened"), (1) ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC); + } + ZEPHIR_MM_RESTORE(); + +} + +/** + * Returns the internal formatter + * + * @return Phalcon\Logger\Formatter\Line + */ +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, getFormatter) { + + int ZEPHIR_LAST_CALL_STATUS; + zval *formatter; + + ZEPHIR_MM_GROW(); + + ZEPHIR_OBS_VAR(formatter); + zephir_read_property_this(&formatter, this_ptr, SL("_formatter"), PH_NOISY_CC); + if (Z_TYPE_P(formatter) != IS_OBJECT) { + ZEPHIR_INIT_BNVAR(formatter); + object_init_ex(formatter, phalcon_logger_formatter_syslog_ce); + if (zephir_has_constructor(formatter TSRMLS_CC)) { + ZEPHIR_CALL_METHOD(NULL, formatter, "__construct", NULL); + zephir_check_call_status(); + } + zephir_update_property_this(this_ptr, SL("_formatter"), formatter TSRMLS_CC); + } + RETURN_CCTOR(formatter); + +} + +/** + * Writes the log to the stream itself + * + * @param string message + * @param int type + * @param int time + */ +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, logInternal) { + + zephir_nts_static zephir_fcall_cache_entry *_7 = NULL; + zend_class_entry *_4; + int type, time, ZEPHIR_LAST_CALL_STATUS; + zval *message, *type_param = NULL, *time_param = NULL, *appliedFormat = NULL, *_0 = NULL, *_1, *_2, *_3, *_5, *_6; + + ZEPHIR_MM_GROW(); + zephir_fetch_params(1, 3, 0, &message, &type_param, &time_param); + + type = zephir_get_intval(type_param); + time = zephir_get_intval(time_param); + + + ZEPHIR_CALL_METHOD(&_0, this_ptr, "getformatter", NULL); + zephir_check_call_status(); + ZEPHIR_INIT_VAR(_1); + ZVAL_LONG(_1, type); + ZEPHIR_INIT_VAR(_2); + ZVAL_LONG(_2, time); + ZEPHIR_CALL_METHOD(&appliedFormat, _0, "format", NULL, message, _1, _2); + zephir_check_call_status(); + if (Z_TYPE_P(appliedFormat) != IS_ARRAY) { + ZEPHIR_INIT_VAR(_3); + _4 = zend_fetch_class(SL("Phalcon\\Logger\\Adapter\\Exception"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + object_init_ex(_3, _4); + if (zephir_has_constructor(_3 TSRMLS_CC)) { + ZEPHIR_INIT_BNVAR(_1); + ZVAL_STRING(_1, "The formatted message is not valid", 0); + ZEPHIR_CALL_METHOD(NULL, _3, "__construct", NULL, _1); + zephir_check_temp_parameter(_1); + zephir_check_call_status(); + } + zephir_throw_exception_debug(_3, "phalcon/logger/adapter/syslog.zep", 97 TSRMLS_CC); + ZEPHIR_MM_RESTORE(); + return; + } + zephir_array_fetch_long(&_5, appliedFormat, 0, PH_NOISY | PH_READONLY TSRMLS_CC); + zephir_array_fetch_long(&_6, appliedFormat, 1, PH_NOISY | PH_READONLY TSRMLS_CC); + ZEPHIR_CALL_FUNCTION(NULL, "syslog", &_7, _5, _6); + zephir_check_call_status(); + ZEPHIR_MM_RESTORE(); + +} + +/** + * Closes the logger + * + * @return boolean + */ +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close) { + + int ZEPHIR_LAST_CALL_STATUS; + zephir_nts_static zephir_fcall_cache_entry *_1 = NULL; + zval *_0; + + ZEPHIR_MM_GROW(); + + _0 = zephir_fetch_nproperty_this(this_ptr, SL("_opened"), PH_NOISY_CC); + if (zephir_is_true(_0)) { + ZEPHIR_CALL_FUNCTION(NULL, "closelog", &_1); + zephir_check_call_status(); + } + ZEPHIR_MM_RESTORE(); + +} + diff --git a/ext/phalcon/logger/adapter/syslog.h b/ext/phalcon/logger/adapter/syslog.h index 4e3c4e37830..6bfd7e5a52f 100644 --- a/ext/phalcon/logger/adapter/syslog.h +++ b/ext/phalcon/logger/adapter/syslog.h @@ -3,3 +3,26 @@ extern zend_class_entry *phalcon_logger_adapter_syslog_ce; ZEPHIR_INIT_CLASS(Phalcon_Logger_Adapter_Syslog); +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct); +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, getFormatter); +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, logInternal); +PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close); + +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapter_syslog___construct, 0, 0, 1) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapter_syslog_loginternal, 0, 0, 3) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, time) +ZEND_END_ARG_INFO() + +ZEPHIR_INIT_FUNCS(phalcon_logger_adapter_syslog_method_entry) { + PHP_ME(Phalcon_Logger_Adapter_Syslog, __construct, arginfo_phalcon_logger_adapter_syslog___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(Phalcon_Logger_Adapter_Syslog, getFormatter, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter_Syslog, logInternal, arginfo_phalcon_logger_adapter_syslog_loginternal, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter_Syslog, close, NULL, ZEND_ACC_PUBLIC) + PHP_FE_END +}; diff --git a/ext/phalcon/tag.c b/ext/phalcon/tag.c index a040b5ad95a..1ae83c840e9 100644 --- a/ext/phalcon/tag.c +++ b/ext/phalcon/tag.c @@ -281,7 +281,7 @@ PHP_METHOD(Phalcon_Tag, getUrlService) { zephir_check_call_status(); } if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"url\" service", "phalcon/tag.zep", 174); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the "url" service", "phalcon/tag.zep", 174); return; } ZEPHIR_INIT_VAR(_2); @@ -319,7 +319,7 @@ PHP_METHOD(Phalcon_Tag, getEscaperService) { zephir_check_call_status(); } if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"escaper\" service", "phalcon/tag.zep", 202); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the "escaper" service", "phalcon/tag.zep", 202); return; } ZEPHIR_INIT_VAR(_2); diff --git a/ext/phalcon/tag/select.c b/ext/phalcon/tag/select.c index 0e0ef030d51..b7d490c9d47 100644 --- a/ext/phalcon/tag/select.c +++ b/ext/phalcon/tag/select.c @@ -171,7 +171,7 @@ PHP_METHOD(Phalcon_Tag_Select, selectField) { if (Z_TYPE_P(options) == IS_OBJECT) { ZEPHIR_OBS_VAR(using); if (!(zephir_array_isset_string_fetch(&using, params, SS("using"), 0 TSRMLS_CC))) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "The \"using\" parameter is required", "phalcon/tag/select.zep", 123); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "The "using" parameter is required", "phalcon/tag/select.zep", 123); return; } else { _5 = Z_TYPE_P(using) != IS_ARRAY; @@ -179,7 +179,7 @@ PHP_METHOD(Phalcon_Tag_Select, selectField) { _5 = Z_TYPE_P(using) != IS_OBJECT; } if (_5) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "The \"using\" parameter should be an Array", "phalcon/tag/select.zep", 126); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_tag_exception_ce, "The "using" parameter should be an Array", "phalcon/tag/select.zep", 126); return; } } diff --git a/optimizers/PhalconCssminOptimizer.php b/optimizers/PhalconCssminOptimizer.php index 41448306a59..33c3282878b 100644 --- a/optimizers/PhalconCssminOptimizer.php +++ b/optimizers/PhalconCssminOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconEscapeCssOptimizer.php b/optimizers/PhalconEscapeCssOptimizer.php index eb63088e9d6..fa213ea51a9 100644 --- a/optimizers/PhalconEscapeCssOptimizer.php +++ b/optimizers/PhalconEscapeCssOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconEscapeJsOptimizer.php b/optimizers/PhalconEscapeJsOptimizer.php index 2aadb201b99..b92f2569e1d 100644 --- a/optimizers/PhalconEscapeJsOptimizer.php +++ b/optimizers/PhalconEscapeJsOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconFilterAlphanumOptimizer.php b/optimizers/PhalconFilterAlphanumOptimizer.php index 35f5c30cc6c..056512cbf3c 100644 --- a/optimizers/PhalconFilterAlphanumOptimizer.php +++ b/optimizers/PhalconFilterAlphanumOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconFixPathOptimizer.php b/optimizers/PhalconFixPathOptimizer.php index c692ea388d0..f907ab64727 100644 --- a/optimizers/PhalconFixPathOptimizer.php +++ b/optimizers/PhalconFixPathOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconGetUriOptimizer.php b/optimizers/PhalconGetUriOptimizer.php index fb08537aa42..d6be98b2c1c 100644 --- a/optimizers/PhalconGetUriOptimizer.php +++ b/optimizers/PhalconGetUriOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconJsminOptimizer.php b/optimizers/PhalconJsminOptimizer.php index 57709c27e74..45f29abb2cf 100644 --- a/optimizers/PhalconJsminOptimizer.php +++ b/optimizers/PhalconJsminOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconPossibleAutoloadFilepathOptimizer.php b/optimizers/PhalconPossibleAutoloadFilepathOptimizer.php index f2dead162e6..f08535ad3f7 100644 --- a/optimizers/PhalconPossibleAutoloadFilepathOptimizer.php +++ b/optimizers/PhalconPossibleAutoloadFilepathOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconPrepareVirtualPathOptimizer.php b/optimizers/PhalconPrepareVirtualPathOptimizer.php index 9de847e94e1..0f02530616e 100644 --- a/optimizers/PhalconPrepareVirtualPathOptimizer.php +++ b/optimizers/PhalconPrepareVirtualPathOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhalconReplacePathsOptimizer.php b/optimizers/PhalconReplacePathsOptimizer.php index 058af292e64..8a630afd903 100644 --- a/optimizers/PhalconReplacePathsOptimizer.php +++ b/optimizers/PhalconReplacePathsOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhannotParseAnnotationsOptimizer.php b/optimizers/PhannotParseAnnotationsOptimizer.php index d4e5de2a524..bc8d3c340c0 100644 --- a/optimizers/PhannotParseAnnotationsOptimizer.php +++ b/optimizers/PhannotParseAnnotationsOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhqlParsePhqlOptimizer.php b/optimizers/PhqlParsePhqlOptimizer.php index acc616db56c..a53846900f1 100644 --- a/optimizers/PhqlParsePhqlOptimizer.php +++ b/optimizers/PhqlParsePhqlOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/optimizers/PhvoltParseViewOptimizer.php b/optimizers/PhvoltParseViewOptimizer.php index 6c5faa90ca0..31a6cd767c7 100644 --- a/optimizers/PhvoltParseViewOptimizer.php +++ b/optimizers/PhvoltParseViewOptimizer.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/phalcon/cache/backend/file.zep b/phalcon/cache/backend/file.zep index f446411a57d..3fbad2df531 100644 --- a/phalcon/cache/backend/file.zep +++ b/phalcon/cache/backend/file.zep @@ -79,8 +79,7 @@ class File extends \Phalcon\Cache\Backend implements \Phalcon\Cache\BackendInter */ public function get(var keyName, lifetime=null) { - var prefixedKey, cacheDir, cacheFile, frontend, - lastLifetime, tmp, ttl, cachedContent; + var prefixedKey, cacheDir, cacheFile, frontend, lastLifetime, ttl, cachedContent; int modifiedTime; let prefixedKey = this->_prefix . keyName; @@ -210,7 +209,7 @@ class File extends \Phalcon\Cache\Backend implements \Phalcon\Cache\BackendInter */ public function delete(var keyName) -> boolean { - var prefixedKey, cacheFile, cacheDir; + var cacheFile, cacheDir; if !fetch cacheDir, this->_options["cacheDir"] { throw new Exception("Unexpected inconsistency in options"); @@ -369,8 +368,7 @@ class File extends \Phalcon\Cache\Backend implements \Phalcon\Cache\BackendInter */ public function decrement(var keyName=null, int value=null) { - var prefixedKey, cacheFile, timestamp, lifetime, ttl, - cachedContent, status, result; + var prefixedKey, cacheFile, timestamp, lifetime, ttl, cachedContent, result; let prefixedKey = this->_prefix . keyName, this->_lastKey = prefixedKey, diff --git a/phalcon/cache/backend/memory.zep b/phalcon/cache/backend/memory.zep index 4c45a3bb4b8..44ddc2f996c 100644 --- a/phalcon/cache/backend/memory.zep +++ b/phalcon/cache/backend/memory.zep @@ -194,7 +194,7 @@ class Memory extends \Phalcon\Cache\Backend implements \Phalcon\Cache\BackendInt */ public function increment(keyName=null, value=null) { - var lastKey, prefix, data, cachedContent, result; + var lastKey, prefix, cachedContent, result; if !keyName { let lastKey = this->_lastKey; @@ -231,7 +231,7 @@ class Memory extends \Phalcon\Cache\Backend implements \Phalcon\Cache\BackendInt */ public function decrement(keyName=null, value=null) { - var lastKey, prefix, data, cachedContent, result; + var lastKey, prefix, cachedContent, result; if !keyName { let lastKey = this->_lastKey; diff --git a/phalcon/crypt.zep b/phalcon/crypt.zep index 7cd32460dfa..d6b3e1c79a7 100644 --- a/phalcon/crypt.zep +++ b/phalcon/crypt.zep @@ -19,6 +19,8 @@ namespace Phalcon; +use Phalcon\Crypt\Exception; + /** * Phalcon\Crypt * @@ -123,7 +125,31 @@ class Crypt implements \Phalcon\CryptInterface */ public function encrypt(string! text, key=null) -> string { + var encryptKey, ivSize, iv, cipher, mode; + + if !function_exists("mcrypt_get_iv_size") { + throw new Exception("mcrypt extension is required"); + } + + if key === null { + let encryptKey = this->_key; + } else { + let encryptKey = key; + } + + if empty encryptKey { + throw new Exception("Encryption key cannot be empty"); + } + let cipher = this->_cipher, mode = this->_mode; + + let ivSize = mcrypt_get_iv_size(cipher, mode); + if strlen(encryptKey) > ivSize { + throw new Exception("Size of key is too large for this algorithm"); + } + + let iv = mcrypt_create_iv(ivSize, MCRYPT_RAND); + return iv . mcrypt_encrypt(cipher, encryptKey, text, mode, iv); } /** @@ -139,7 +165,36 @@ class Crypt implements \Phalcon\CryptInterface */ public function decrypt(string! text, key=null) -> string { + var decryptKey, ivSize, cipher, mode, keySize; + + if !function_exists("mcrypt_get_iv_size") { + throw new Exception("mcrypt extension is required"); + } + + if key === null { + let decryptKey = this->_key; + } else { + let decryptKey = $key; + } + + if empty decryptKey { + throw new Exception("Decryption key cannot be empty"); + } + + let cipher = this->_cipher, mode = this->_mode; + + let ivSize = mcrypt_get_iv_size(cipher, mode); + + let keySize = strlen(decryptKey); + if keySize > ivSize { + throw new Exception("Size of key is too large for this algorithm"); + } + + if keySize > strlen(text) { + throw new Exception("Size of IV is larger than text to decrypt"); + } + return mcrypt_decrypt(cipher, decryptKey, substr(text, ivSize), mode, substr(text, 0, ivSize)); } /** diff --git a/phalcon/db/adapter.zep b/phalcon/db/adapter.zep index 15c4a013cb9..275ce99810f 100644 --- a/phalcon/db/adapter.zep +++ b/phalcon/db/adapter.zep @@ -98,7 +98,7 @@ abstract class Adapter implements \Phalcon\Events\EventsAwareInterface * * @param array descriptor */ - public function __construct(descriptor) + public function __construct(array! descriptor) { var dialectClass; diff --git a/phalcon/db/adapter/pdo.zep b/phalcon/db/adapter/pdo.zep index e65c553918c..0293b099f3f 100644 --- a/phalcon/db/adapter/pdo.zep +++ b/phalcon/db/adapter/pdo.zep @@ -20,6 +20,7 @@ namespace Phalcon\Db\Adapter; use Phalcon\Db\Exception; +use Phalcon\Db\Column; /** * Phalcon\Db\Adapter\Pdo @@ -59,15 +60,9 @@ abstract class Pdo extends \Phalcon\Db\Adapter * * @param array descriptor */ - public function __construct(descriptor) + public function __construct(array! descriptor) { - - if typeof descriptor != "array" { - throw new Exception("The descriptor must be an array"); - } - this->connect(descriptor); - parent::__construct(descriptor); } @@ -215,8 +210,8 @@ abstract class Pdo extends \Phalcon\Db\Adapter /** * The bind type is double so we try to get the double value */ - if type == \Phalcon\Db\Column::BIND_PARAM_DECIMAL { - let castValue = doubleval(value), type = \Phalcon\Db\Column::BIND_SKIP; + if type == Column::BIND_PARAM_DECIMAL { + let castValue = doubleval(value), type = Column::BIND_SKIP; } else { let castValue = value; } @@ -224,7 +219,7 @@ abstract class Pdo extends \Phalcon\Db\Adapter /** * 1024 is ignore the bind type */ - if type == \Phalcon\Db\Column::BIND_SKIP { + if type == Column::BIND_SKIP { statement->bindParam(parameter, castValue); } else { statement->bindParam(parameter, castValue, type); diff --git a/phalcon/db/adapter/pdo/mysql.zep b/phalcon/db/adapter/pdo/mysql.zep index 08d939d8f63..35813a21d17 100644 --- a/phalcon/db/adapter/pdo/mysql.zep +++ b/phalcon/db/adapter/pdo/mysql.zep @@ -19,6 +19,8 @@ namespace Phalcon\Db\Adapter\Pdo; +use Phalcon\Db\Column; + /** * Phalcon\Db\Adapter\Pdo\Mysql * @@ -108,7 +110,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf /** * By default the bind types is two */ - let definition = ["bindType": 2]; + let definition = ["bindType": Column::BIND_PARAM_STR]; /** * By checking every column type we convert it to a Phalcon\Db\Column @@ -121,7 +123,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Enum are treated as char */ if memstr(columnType, "enum") { - let definition["type"] = \Phalcon\Db\Column::BIND_PARAM_STR; + let definition["type"] = Column::BIND_PARAM_STR; break; } @@ -131,7 +133,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf if memstr(columnType, "int") { let definition["type"] = 0, definition["isNumeric"] = true, - definition["bindType"] = \Phalcon\Db\Column::BIND_PARAM_INT; + definition["bindType"] = Column::BIND_PARAM_INT; break; } @@ -139,7 +141,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Varchar are varchars */ if memstr(columnType, "varchar") { - let definition["type"] = \Phalcon\Db\Column::BIND_PARAM_STR; + let definition["type"] = Column::BIND_PARAM_STR; break; } @@ -147,7 +149,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Special type for datetime */ if memstr(columnType, "datetime") { - let definition["type"] = \Phalcon\Db\Column::TYPE_DATETIME; + let definition["type"] = Column::TYPE_DATETIME; break; } @@ -155,9 +157,9 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Decimals are floats */ if memstr(columnType, "decimal") { - let definition["type"] = \Phalcon\Db\Column::TYPE_DECIMAL, + let definition["type"] = Column::TYPE_DECIMAL, definition["isNumeric"] = true, - definition["bindType"] = \Phalcon\Db\Column::BIND_PARAM_DECIMAL; + definition["bindType"] = Column::BIND_PARAM_DECIMAL; break; } @@ -165,7 +167,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Chars are chars */ if memstr(columnType, "char") { - let definition["type"] = \Phalcon\Db\Column::TYPE_CHAR; + let definition["type"] = Column::TYPE_CHAR; break; } @@ -173,7 +175,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Date/Datetime are varchars */ if memstr(columnType, "date") { - let definition["type"] = \Phalcon\Db\Column::TYPE_DATE; + let definition["type"] = Column::TYPE_DATE; break; } @@ -181,24 +183,24 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Text are varchars */ if memstr(columnType, "text") { - let definition["type"] = \Phalcon\Db\Column::TYPE_TEXT; + let definition["type"] = Column::TYPE_TEXT; break; } /** * Float/Smallfloats/Decimals are float */ - if strpos(columnType, "float") { - let definition["type"] = \Phalcon\Db\Column::TYPE_FLOAT, + if memstr(columnType, "float") { + let definition["type"] = Column::TYPE_FLOAT, definition["isNumeric"] = true, - definition["bindType"] = \Phalcon\Db\Column::TYPE_DECIMAL; + definition["bindType"] = Column::TYPE_DECIMAL; break; } /** * By default is string */ - let definition["type"] = \Phalcon\Db\Column::TYPE_VARCHAR; + let definition["type"] = Column::TYPE_VARCHAR; break; } @@ -255,7 +257,7 @@ class Mysql extends \Phalcon\Db\Adapter\Pdo implements \Phalcon\Db\AdapterInterf * Every route is stored as a Phalcon\Db\Column */ let columnName = field[0], - columns[] = new \Phalcon\Db\Column(columnName, definition), + columns[] = new Column(columnName, definition), oldColumn = columnName; } diff --git a/phalcon/debug.zep b/phalcon/debug.zep index 82f970317d8..d207749f14a 100644 --- a/phalcon/debug.zep +++ b/phalcon/debug.zep @@ -177,7 +177,7 @@ class Debug */ protected function _getArrayDump(argument, n = 0) { - var numberArguments, one, dump, varDump, k, v, arguments; + var numberArguments, dump, varDump, k, v; let numberArguments = count(argument); if n < 3 { @@ -230,7 +230,7 @@ class Debug */ protected function _getVarDump(variable) { - var className, dumpedObject, dump, arrayDump; + var className, dumpedObject, dump; if is_scalar(variable) { @@ -371,12 +371,12 @@ class Debug protected function showTraceItem(n, trace) { - var space, twoSpaces, underscore, minus, isPhalconClass, className, pattern, namespaceSeparator, - prepareInternalClass, preparedFunctionName, html, classReflection, prepareUriClass, isInternal, - lowerClassName, type, functionName, functionReflection, traceArgs, arguments, argument, - spanArgument, joinedArguments, one, filez, line, showFiles, lines, numberLines, showFileFragment, seven, - beforeLine, firstLine, afterLine, lastLine, commentPattern, utf8, entCompat, tab, comment, i, linePosition, - currentLine, trimmed, isComment, spacedCurrentLine; + var space, twoSpaces, underscore, minus, className, namespaceSeparator, + prepareInternalClass, preparedFunctionName, html, classReflection, prepareUriClass, + functionName, functionReflection, traceArgs, arguments, argument, + filez, line, showFiles, lines, numberLines, showFileFragment, + beforeLine, firstLine, afterLine, lastLine, commentPattern, utf8, entCompat, tab, + comment, i, linePosition, currentLine; let space = " "; let twoSpaces = " "; diff --git a/phalcon/di/service.zep b/phalcon/di/service.zep index d220b37a02a..f4a1be1cbbe 100644 --- a/phalcon/di/service.zep +++ b/phalcon/di/service.zep @@ -19,6 +19,8 @@ namespace Phalcon\Di; +use Phalcon\Di\Exception; + /** * Phalcon\Di\Service * @@ -194,7 +196,7 @@ class Service implements \Phalcon\Di\ServiceInterface * If the service can't be built, we must throw an exception */ if found === false { - throw new \Phalcon\Di\Exception("Service '" . this->_name . "' cannot be resolved"); + throw new Exception("Service '" . this->_name . "' cannot be resolved"); } /** @@ -214,17 +216,13 @@ class Service implements \Phalcon\Di\ServiceInterface * @param array parameter * @return Phalcon\Di\Service */ - public function setParameter(int position, parameter) -> <\Phalcon\Di\Service> + public function setParameter(int position, array! parameter) -> <\Phalcon\Di\Service> { var definition, arguments; let definition = this->_definition; if typeof definition != "array" { - throw new \Phalcon\Di\Exception("Definition must be an array to update its parameters"); - } - - if typeof parameter != "array" { - throw new \Phalcon\Di\Exception("The parameter must be an array"); + throw new Exception("Definition must be an array to update its parameters"); } /** @@ -261,7 +259,7 @@ class Service implements \Phalcon\Di\ServiceInterface let definition = this->_definition; if typeof definition != "array" { - throw new \Phalcon\Di\Exception("Definition must be an array to obtain its parameters"); + throw new Exception("Definition must be an array to obtain its parameters"); } /** @@ -282,20 +280,20 @@ class Service implements \Phalcon\Di\ServiceInterface * @param array attributes * @return Phalcon\Di\Service */ - public static function __set_state(attributes) -> <\Phalcon\Di\Service> + public static function __set_state(array! attributes) -> <\Phalcon\Di\Service> { var name, definition, shared; if !fetch name, attributes["_name"] { - throw new \Phalcon\Di\Exception("The attribute '_name' is required"); + throw new Exception("The attribute '_name' is required"); } if !fetch definition, attributes["_definition"] { - throw new \Phalcon\Di\Exception("The attribute '_name' is required"); + throw new Exception("The attribute '_name' is required"); } if !fetch shared, attributes["_shared"] { - throw new \Phalcon\Di\Exception("The attribute '_shared' is required"); + throw new Exception("The attribute '_shared' is required"); } return new self(name, definition, shared); diff --git a/phalcon/events/manager.zep b/phalcon/events/manager.zep index ce6b4418d9e..3dc1e8f5344 100644 --- a/phalcon/events/manager.zep +++ b/phalcon/events/manager.zep @@ -494,7 +494,7 @@ class Manager implements \Phalcon\Events\ManagerInterface * @param string type * @return boolean */ - public function hasListeners(string! type) + public function hasListeners(string! type) -> boolean { return isset this->_events[type]; } diff --git a/phalcon/http/request.zep b/phalcon/http/request.zep index 984a87a4bee..c727ad1d038 100644 --- a/phalcon/http/request.zep +++ b/phalcon/http/request.zep @@ -255,7 +255,7 @@ class Request implements \Phalcon\Http\RequestInterface, \Phalcon\Di\InjectionAw * @param string name * @return boolean */ - public function hasServer(string! name) -> boolean + public final function hasServer(string! name) -> boolean { return isset _SERVER[name]; } @@ -266,7 +266,7 @@ class Request implements \Phalcon\Http\RequestInterface, \Phalcon\Di\InjectionAw * @param string header * @return string */ - public function getHeader(string! header) -> string + public final function getHeader(string! header) -> string { var serverValue, headerValue; @@ -502,7 +502,7 @@ class Request implements \Phalcon\Http\RequestInterface, \Phalcon\Di\InjectionAw * * @return string */ - public function getMethod() -> string + public final function getMethod() -> string { var requestMethod; diff --git a/phalcon/logger/adapter/stream.zep b/phalcon/logger/adapter/stream.zep index 74da717268c..e72a177ea59 100644 --- a/phalcon/logger/adapter/stream.zep +++ b/phalcon/logger/adapter/stream.zep @@ -19,4 +19,102 @@ namespace Phalcon\Logger\Adapter; -class Stream { } \ No newline at end of file +use Phalcon\Logger\Exception; + +/** + * Phalcon\Logger\Adapter\Stream + * + * Sends logs to a valid PHP stream + * + * + * $logger = new \Phalcon\Logger\Adapter\Stream("php://stderr"); + * $logger->log("This is a message"); + * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->error("This is another error"); + * + */ +class Stream extends \Phalcon\Logger\Adapter implements \Phalcon\Logger\AdapterInterface +{ + + /** + * File handler resource + * + * @var resource + */ + protected _stream; + + /** + * Phalcon\Logger\Adapter\Stream constructor + * + * @param string name + * @param array options + */ + public function __construct(string! name, options=null) + { + var mode, stream; + + if fetch mode, options["mode"] { + if memstr(mode, "r") { + throw new Exception("Stream must be opened in append or write mode"); + } + } else { + let mode = "ab"; + } + + /** + * We use 'fopen' to respect to open-basedir directive + */ + let stream = fopen(name, mode); + if !stream { + throw new Exception("Can't open stream '" . name . "'"); + } + + let this->_stream = stream; + } + + /** + * Returns the internal formatter + * + * @return Phalcon\Logger\Formatter\Line + */ + public function getFormatter() -> + { + var formatter; + + let formatter = this->_formatter; + if typeof formatter == "object" { + let formatter = new \Phalcon\Logger\Formatter\Line(), this->_formatter = formatter; + } + return formatter; + } + + /** + * Writes the log to the stream itself + * + * @param string message + * @param int type + * @param int time + */ + public function logInternal(message, int type, int time) + { + var stream; + + let stream = this->_stream; + if !stream { + throw new Exception("Cannot send message to the log because it is invalid"); + } + + fwrite(stream, this->getFormatter()->format(message, type, time)); + } + + /** + * Closes the logger + * + * @return boolean + */ + public function close() -> boolean + { + return fclose(this->_stream); + } + +} diff --git a/phalcon/logger/adapter/syslog.zep b/phalcon/logger/adapter/syslog.zep index 811d58f4685..b53a71cd3db 100644 --- a/phalcon/logger/adapter/syslog.zep +++ b/phalcon/logger/adapter/syslog.zep @@ -19,4 +19,97 @@ namespace Phalcon\Logger\Adapter; -class Syslog { } \ No newline at end of file +/** + * Phalcon\Logger\Adapter\Syslog + * + * Sends logs to the system logger + * + * + * $logger = new \Phalcon\Logger\Adapter\Syslog("ident", array( + * 'option' => LOG_NDELAY, + * 'facility' => LOG_MAIL + * )); + * $logger->log("This is a message"); + * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->error("This is another error"); + * + */ +class Syslog extends \Phalcon\Logger\Adapter implements \Phalcon\Logger\AdapterInterface +{ + + protected _opened = false; + + /** + * Phalcon\Logger\Adapter\Syslog constructor + * + * @param string name + * @param array options + */ + public function __construct(name, options=null) + { + var option, facility; + + if name { + + if !fetch option, options["option"] { + let option = LOG_ODELAY; + } + + if !fetch facility, options["facility"] { + let facility = LOG_USER; + } + + openlog(name, option, facility); + let this->_opened = true; + } + + } + + /** + * Returns the internal formatter + * + * @return Phalcon\Logger\Formatter\Line + */ + public function getFormatter() + { + var formatter; + + let formatter = this->_formatter; + if typeof formatter != "object" { + let formatter = new \Phalcon\Logger\Formatter\Syslog(), this->_formatter = formatter; + } + return formatter; + } + + /** + * Writes the log to the stream itself + * + * @param string message + * @param int type + * @param int time + */ + public function logInternal(message, int type, int time) + { + var appliedFormat; + + let appliedFormat = this->getFormatter()->format(message, type, time); + if typeof appliedFormat != "array" { + throw new Exception("The formatted message is not valid"); + } + + syslog(appliedFormat[0], appliedFormat[1]); + } + + /** + * Closes the logger + * + * @return boolean + */ + public function close() + { + if this->_opened { + closelog(); + } + } + +} diff --git a/phalcon/logger/formatter.zep b/phalcon/logger/formatter.zep index fe510b20b3c..d541c8fc374 100644 --- a/phalcon/logger/formatter.zep +++ b/phalcon/logger/formatter.zep @@ -19,6 +19,8 @@ namespace Phalcon\Logger; +use Phalcon\Logger; + /** * Phalcon\Logger\Formatter * @@ -37,34 +39,34 @@ abstract class Formatter { switch type { - case \Phalcon\Logger::DEBUG: + case Logger::DEBUG: return "DEBUG"; - case \Phalcon\Logger::ERROR: + case Logger::ERROR: return "ERROR"; - case \Phalcon\Logger::WARNING: + case Logger::WARNING: return "WARNING"; - case \Phalcon\Logger::CRITICAL: + case Logger::CRITICAL: return "CRITICAL"; - case \Phalcon\Logger::CUSTOM: + case Logger::CUSTOM: return "CUSTOM"; - case \Phalcon\Logger::ALERT: + case Logger::ALERT: return "ALERT"; - case \Phalcon\Logger::NOTICE: + case Logger::NOTICE: return "NOTICE"; - case \Phalcon\Logger::INFO: + case Logger::INFO: return "INFO"; - case \Phalcon\Logger::EMERGENCE: + case Logger::EMERGENCE: return "EMERGENCE"; - case \Phalcon\Logger::SPECIAL: + case Logger::SPECIAL: return "SPECIAL"; default: