diff --git a/CHANGELOG b/CHANGELOG index 9772d0a2e66..73e847a8beb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -185,7 +185,11 @@ - Phalcon\Logger\Adapter::commit() now clears the queue (#1742) - Phalcon\Logger\Adapter now implements Phalcon\Logger\AdapterInterface (#1852) - Phalcon\Logger\Formatter now implements Phalcon\Logger\FormatterInterface (#1852) - - Phalcon\Logger\Adapter is now PSR-3 compliant (#1873) + - Phalcon\Logger\Adapter and Phalcon\Logger\AdapterInterface are now PSR-3 compliant (#1873, #1888) + - Added Phalcon\Logger\Adapter::critical() method (#1888) + - For PHP 5.3.9+ when phalcon.register_psr3_classes php.ini option is set, Phalcon\Logger\Adapter implements Psr\Log\LoggerInterface (#1888) + - When phalcon.register_psr3_classes php.ini option is set, Phalcon\Logger\Adapter and derived classes throw Psr\Log\InvalidArgumentException + instead of Phalcon\Logger\Exception when the arguments are not valid (#1888) - Phalcon\Mvc: - Phalcon\Mvc\Application::handle() now checks whether the class exists before include()'ing its file (#812, #818) - Phalcon\Mvc\Model\Criteria::fromInput() now sets _modelName (#866, #873) @@ -271,6 +275,11 @@ - Optimized Phalcon\Validation\Message\Group by using native iterators (#1657) - Optimized Phalcon\Validation\Message\Group by using object handlers (#1765) - Phalcon\Validation\Validator now implements Phalcon\Validation\ValidatorInterface (#1852) + - Psr\Log: + - when phalcon.register_psr3_classes php.ini option is set, Psr\Log\LoggerAwareInterface, Psr\Log\LoggerInterface, + Psr\Log\AbstractLogger, Psr\Log\InvalidArgumentException, Psr\Log\LogLevel, Psr\Log\NullLogger, + Psr\Log\LoggerAwareTrait (PHP 5.4+), Psr\Log\LoggerTrait (PHP 5.4+) are registered as internal interfaces/classes/traits + by Phalcon (#1888) - Unit tests: - Travis CI imporvements (#819, #846, #949) - Use markTestSkipped() instead of echo (#862) diff --git a/ext/config.m4 b/ext/config.m4 index 40c5982f946..d19c961f500 100644 --- a/ext/config.m4 +++ b/ext/config.m4 @@ -348,7 +348,15 @@ image/adapter.c \ image/adapterinterface.c \ image/exception.c \ image/adapter/gd.c \ -image/adapter/imagick.c" +image/adapter/imagick.c \ +psr/log/abstractlogger.c \ +psr/log/invalidargumentexception.c \ +psr/log/loggerawareinterface.c \ +psr/log/loggerawaretrait.c \ +psr/log/loggerinterface.c \ +psr/log/loggertrait.c \ +psr/log/loglevel.c \ +psr/log/nulllogger.c" PHP_NEW_EXTENSION(phalcon, $phalcon_sources, $ext_shared) PHP_ADD_EXTENSION_DEP([phalcon], [spl]) diff --git a/ext/config.w32 b/ext/config.w32 index 6c9835900f6..8e69e9cd1f2 100644 --- a/ext/config.w32 +++ b/ext/config.w32 @@ -77,4 +77,5 @@ if (PHP_PHALCON != "no") { ADD_SOURCES("ext/phalcon/validation", "validatorinterface.c exception.c message.c validator.c", "phalcon") ADD_SOURCES("ext/phalcon/validation/message", "group.c", "phalcon") ADD_SOURCES("ext/phalcon/validation/validator", "email.c presenceof.c confirmation.c regex.c exclusionin.c identical.c between.c inclusionin.c stringlength.c url.c", "phalcon") + ADD_SOURCES("ext/phalcon/psr/log", "abstractlogger.c invalidargumentexception.c loggerawareinterface.c loggerawaretrait.c loggerinterface.c loggertrait.c loglevel.c nulllogger.c") } diff --git a/ext/logger/adapter.c b/ext/logger/adapter.c index 4be9f6b977a..22f56a072ae 100644 --- a/ext/logger/adapter.c +++ b/ext/logger/adapter.c @@ -22,6 +22,8 @@ #include "logger/formatterinterface.h" #include "logger/item.h" #include "logger.h" +#include "psr/log/loggerinterface.h" +#include "psr/log/invalidargumentexception.h" #include "kernel/main.h" #include "kernel/memory.h" @@ -45,12 +47,13 @@ PHP_METHOD(Phalcon_Logger_Adapter, begin); PHP_METHOD(Phalcon_Logger_Adapter, commit); PHP_METHOD(Phalcon_Logger_Adapter, rollback); PHP_METHOD(Phalcon_Logger_Adapter, emergency); -PHP_METHOD(Phalcon_Logger_Adapter, debug); +PHP_METHOD(Phalcon_Logger_Adapter, alert); +PHP_METHOD(Phalcon_Logger_Adapter, critical); PHP_METHOD(Phalcon_Logger_Adapter, error); -PHP_METHOD(Phalcon_Logger_Adapter, info); -PHP_METHOD(Phalcon_Logger_Adapter, notice); PHP_METHOD(Phalcon_Logger_Adapter, warning); -PHP_METHOD(Phalcon_Logger_Adapter, alert); +PHP_METHOD(Phalcon_Logger_Adapter, notice); +PHP_METHOD(Phalcon_Logger_Adapter, info); +PHP_METHOD(Phalcon_Logger_Adapter, debug); PHP_METHOD(Phalcon_Logger_Adapter, log); static const zend_function_entry phalcon_logger_adapter_method_entry[] = { @@ -61,15 +64,16 @@ static const zend_function_entry phalcon_logger_adapter_method_entry[] = { PHP_ME(Phalcon_Logger_Adapter, begin, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, commit, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, rollback, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Logger_Adapter, emergency, arginfo_phalcon_logger_adapterinterface_emergency, ZEND_ACC_PUBLIC) PHP_MALIAS(Phalcon_Logger_Adapter, emergence, emergency, arginfo_phalcon_logger_adapterinterface_emergency, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) + PHP_ME(Phalcon_Logger_Adapter, log, arginfo_phalcon_logger_adapterinterface_log, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, debug, arginfo_phalcon_logger_adapterinterface_debug, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Logger_Adapter, error, arginfo_phalcon_logger_adapterinterface_error, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, info, arginfo_phalcon_logger_adapterinterface_info, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, notice, arginfo_phalcon_logger_adapterinterface_notice, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, warning, arginfo_phalcon_logger_adapterinterface_warning, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter, error, arginfo_phalcon_logger_adapterinterface_error, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter, critical, arginfo_phalcon_logger_adapterinterface_critical, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Logger_Adapter, alert, arginfo_phalcon_logger_adapterinterface_alert, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Logger_Adapter, log, arginfo_phalcon_logger_adapterinterface_log, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Logger_Adapter, emergency, arginfo_phalcon_logger_adapterinterface_emergency, ZEND_ACC_PUBLIC) ZEND_FENTRY(logInternal, NULL, arginfo_phalcon_logger_adapter_loginternal, ZEND_ACC_PROTECTED | ZEND_ACC_ABSTRACT) PHP_FE_END }; @@ -86,8 +90,21 @@ PHALCON_INIT_CLASS(Phalcon_Logger_Adapter){ zend_declare_property_null(phalcon_logger_adapter_ce, SL("_formatter"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_long(phalcon_logger_adapter_ce, SL("_logLevel"), PHALCON_LOGGER_SPECIAL, ZEND_ACC_PROTECTED TSRMLS_CC); + /* Prior to PHP 5.3.9, a class could not implement two interfaces + * that specified a method with the same name, since it would cause + * ambiguity. More recent versions of PHP allow this as long as + * the duplicate methods have the same signature. + */ +#if PHP_VERSION_ID >= 50309 + if (PHALCON_GLOBAL(register_psr3_classes)) { + zend_class_implements(phalcon_logger_adapter_ce TSRMLS_CC, 2, phalcon_logger_adapterinterface_ce, psr_log_loggerinterface_ce); + } + else { + zend_class_implements(phalcon_logger_adapter_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + } +#else zend_class_implements(phalcon_logger_adapter_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); - +#endif return SUCCESS; } @@ -176,9 +193,10 @@ PHP_METHOD(Phalcon_Logger_Adapter, getLogLevel){ PHP_METHOD(Phalcon_Logger_Adapter, setFormatter){ zval *formatter; + zend_class_entry *exception = PHALCON_GLOBAL(register_psr3_classes) ? psr_log_invalidargumentexception_ce : phalcon_logger_exception_ce; phalcon_fetch_params(0, 1, 0, &formatter); - PHALCON_VERIFY_INTERFACE_EX(formatter, phalcon_logger_formatterinterface_ce, phalcon_logger_exception_ce, 0); + PHALCON_VERIFY_INTERFACE_EX(formatter, phalcon_logger_formatterinterface_ce, exception, 0); phalcon_update_property_this(this_ptr, SL("_formatter"), formatter TSRMLS_CC); RETURN_THISW(); @@ -216,24 +234,22 @@ PHP_METHOD(Phalcon_Logger_Adapter, commit){ zval *transaction, *queue, *message_str = NULL; zval *type = NULL, *time = NULL, *context = NULL; - PHALCON_MM_GROW(); - transaction = phalcon_fetch_nproperty_this(this_ptr, SL("_transaction"), PH_NOISY_CC); if (!zend_is_true(transaction)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "There is no active transaction"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "There is no active transaction"); return; } phalcon_update_property_bool(this_ptr, SL("_transaction"), 0 TSRMLS_CC); - /** - * Check if the queue has something to log - */ + /* Check if the queue has something to log */ queue = phalcon_fetch_nproperty_this(this_ptr, SL("_queue"), PH_NOISY_CC); if (Z_TYPE_P(queue) == IS_ARRAY) { HashPosition hp; zval **message; + PHALCON_MM_GROW(); + for ( zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(queue), &hp); zend_hash_get_current_data_ex(Z_ARRVAL_P(queue), (void**)&message, &hp) == SUCCESS; @@ -259,9 +275,11 @@ PHP_METHOD(Phalcon_Logger_Adapter, commit){ array_init(queue); phalcon_update_property_this(getThis(), SL("_queue"), queue TSRMLS_CC); } + + PHALCON_MM_RESTORE(); } - RETURN_THIS(); + RETURN_THISW(); } /** @@ -317,7 +335,7 @@ static void phalcon_logger_adapter_log_helper(INTERNAL_FUNCTION_PARAMETERS, int * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, emergency){ @@ -329,7 +347,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, emergency){ * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, debug){ @@ -341,7 +359,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, debug){ * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, error){ @@ -353,7 +371,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, error){ * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, info){ @@ -365,7 +383,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, info){ * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, notice){ @@ -377,7 +395,7 @@ PHP_METHOD(Phalcon_Logger_Adapter, notice){ * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, warning){ @@ -389,13 +407,25 @@ PHP_METHOD(Phalcon_Logger_Adapter, warning){ * * @param string $message * @param array $context - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHP_METHOD(Phalcon_Logger_Adapter, alert){ phalcon_logger_adapter_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHALCON_LOGGER_ALERT); } +/** + * Sends/Writes a critical message to the log + * + * @param string $message + * @param array $context + * @return Phalcon\Logger\AdapterInterface + */ +PHP_METHOD(Phalcon_Logger_Adapter, critical){ + + phalcon_logger_adapter_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHALCON_LOGGER_CRITICAL); +} + /** * Logs messages to the internal logger. Appends messages to the log * diff --git a/ext/logger/adapter/file.c b/ext/logger/adapter/file.c index 5081d70c19b..8f3a45e5d2c 100644 --- a/ext/logger/adapter/file.c +++ b/ext/logger/adapter/file.c @@ -22,6 +22,7 @@ #include "logger/adapterinterface.h" #include "logger/exception.h" #include "logger/formatter/line.h" +#include "psr/log/invalidargumentexception.h" #include "kernel/main.h" #include "kernel/memory.h" @@ -93,26 +94,25 @@ PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_File){ */ PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ - zval *name, *options = NULL, *mode = NULL, *handler, *exception_message; + zval **name, **options = NULL, *mode = NULL, *handler; + zend_class_entry *exception = PHALCON_GLOBAL(register_psr3_classes) ? psr_log_invalidargumentexception_ce : phalcon_logger_exception_ce; + + phalcon_fetch_params_ex(1, 1, &name, &options); + PHALCON_ENSURE_IS_STRING(name); PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); - if (!options) { - options = PHALCON_GLOBAL(z_null); + options = &PHALCON_GLOBAL(z_null); } - if (phalcon_array_isset_string(options, SS("mode"))) { - - PHALCON_OBS_VAR(mode); - phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY); + if (phalcon_array_isset_string_fetch(&mode, *options, SS("mode"))) { if (phalcon_memnstr_str(mode, SL("r"))) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Logger must be opened in append or write mode"); + PHALCON_THROW_EXCEPTION_STR(exception, "Logger must be opened in append or write mode"); return; } } else { - PHALCON_INIT_NVAR(mode); + PHALCON_INIT_VAR(mode); ZVAL_STRING(mode, "ab", 1); } @@ -120,17 +120,15 @@ PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ * We use 'fopen' to respect to open-basedir directive */ PHALCON_OBS_VAR(handler); - PHALCON_CALL_FUNCTION(&handler, "fopen", name, mode); - if (!zend_is_true(handler)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Can't open log file at '", name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_logger_exception_ce, exception_message); - return; + PHALCON_CALL_FUNCTION(&handler, "fopen", *name, mode); + if (Z_TYPE_P(handler) != IS_RESOURCE) { + zend_throw_exception_ex(exception, 0 TSRMLS_CC, "Cannot open log file '%s'", Z_STRVAL_PP(name)); + } + else { + phalcon_update_property_this(this_ptr, SL("_path"), *name TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_options"), *options TSRMLS_CC); + phalcon_update_property_this(this_ptr, SL("_fileHandler"), handler TSRMLS_CC); } - - phalcon_update_property_this(this_ptr, SL("_path"), name TSRMLS_CC); - phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC); - phalcon_update_property_this(this_ptr, SL("_fileHandler"), handler TSRMLS_CC); PHALCON_MM_RESTORE(); } @@ -176,9 +174,8 @@ PHP_METHOD(Phalcon_Logger_Adapter_File, logInternal){ phalcon_fetch_params(1, 4, 0, &message, &type, &time, &context); - PHALCON_OBS_VAR(file_handler); - phalcon_read_property_this(&file_handler, this_ptr, SL("_fileHandler"), PH_NOISY_CC); - if (!zend_is_true(file_handler)) { + file_handler = phalcon_fetch_nproperty_this(this_ptr, SL("_fileHandler"), PH_NOISY_CC); + if (Z_TYPE_P(file_handler) != IS_RESOURCE) { PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); return; } @@ -225,13 +222,14 @@ PHP_METHOD(Phalcon_Logger_Adapter_File, getPath) { PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){ zval *path, *options, *mode = NULL, *file_handler; + zend_class_entry *exception = PHALCON_GLOBAL(register_psr3_classes) ? psr_log_invalidargumentexception_ce : phalcon_logger_exception_ce; PHALCON_MM_GROW(); PHALCON_OBS_VAR(path); phalcon_read_property_this(&path, this_ptr, SL("_path"), PH_NOISY_CC); if (Z_TYPE_P(path) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Invalid data passed to Phalcon\\Logger\\Adapter\\File::__wakeup()"); + PHALCON_THROW_EXCEPTION_STR(exception, "Invalid data passed to Phalcon\\Logger\\Adapter\\File::__wakeup()"); return; } @@ -241,7 +239,7 @@ PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){ PHALCON_OBS_VAR(mode); phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY); if (Z_TYPE_P(mode) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Invalid data passed to Phalcon\\Logger\\Adapter\\File::__wakeup()"); + PHALCON_THROW_EXCEPTION_STR(exception, "Invalid data passed to Phalcon\\Logger\\Adapter\\File::__wakeup()"); return; } } else { diff --git a/ext/logger/adapter/stream.c b/ext/logger/adapter/stream.c index a35873e7b7d..d9f5c955b25 100644 --- a/ext/logger/adapter/stream.c +++ b/ext/logger/adapter/stream.c @@ -22,6 +22,7 @@ #include "logger/adapterinterface.h" #include "logger/exception.h" #include "logger/formatter/line.h" +#include "psr/log/invalidargumentexception.h" #include "kernel/main.h" #include "kernel/memory.h" @@ -86,26 +87,25 @@ PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Stream){ */ PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct){ - zval *name, *options = NULL, *mode = NULL, *stream, *exception_message; + zval **name, **options = NULL, *mode = NULL, *stream; + zend_class_entry *exception = PHALCON_GLOBAL(register_psr3_classes) ? psr_log_invalidargumentexception_ce : phalcon_logger_exception_ce; - PHALCON_MM_GROW(); + phalcon_fetch_params_ex(1, 1, &name, &options); + PHALCON_ENSURE_IS_STRING(name); - phalcon_fetch_params(1, 1, 1, &name, &options); + PHALCON_MM_GROW(); if (!options) { - options = PHALCON_GLOBAL(z_null); + options = &PHALCON_GLOBAL(z_null); } - if (phalcon_array_isset_string(options, SS("mode"))) { - - PHALCON_OBS_VAR(mode); - phalcon_array_fetch_string(&mode, options, SL("mode"), PH_NOISY); + if (phalcon_array_isset_string_fetch(&mode, *options, SS("mode"))) { if (phalcon_memnstr_str(mode, SL("r"))) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Stream must be opened in append or write mode"); + PHALCON_THROW_EXCEPTION_STR(exception, "Stream must be opened in append or write mode"); return; } } else { - PHALCON_INIT_NVAR(mode); + PHALCON_INIT_VAR(mode); ZVAL_STRING(mode, "ab", 1); } @@ -113,15 +113,13 @@ PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct){ * We use 'fopen' to respect to open-basedir directive */ PHALCON_OBS_VAR(stream); - PHALCON_CALL_FUNCTION(&stream, "fopen", name, mode); + PHALCON_CALL_FUNCTION(&stream, "fopen", *name, mode); if (Z_TYPE_P(stream) != IS_RESOURCE) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Can't open stream '", name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_logger_exception_ce, exception_message); - return; + zend_throw_exception_ex(exception, 0 TSRMLS_CC, "Cannot open stream '%s'", Z_STRVAL_PP(name)); + } + else { + phalcon_update_property_this(this_ptr, SL("_stream"), stream TSRMLS_CC); } - - phalcon_update_property_this(this_ptr, SL("_stream"), stream TSRMLS_CC); PHALCON_MM_RESTORE(); } @@ -166,9 +164,8 @@ PHP_METHOD(Phalcon_Logger_Adapter_Stream, logInternal){ phalcon_fetch_params(1, 4, 0, &message, &type, &time, &context); - PHALCON_OBS_VAR(stream); - phalcon_read_property_this(&stream, this_ptr, SL("_stream"), PH_NOISY_CC); - if (!zend_is_true(stream)) { + stream = phalcon_fetch_nproperty_this(this_ptr, SL("_stream"), PH_NOISY_CC); + if (Z_TYPE_P(stream) != IS_RESOURCE) { PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); return; } diff --git a/ext/logger/adapterinterface.c b/ext/logger/adapterinterface.c index 2755f0d2266..2d23dcf9d58 100644 --- a/ext/logger/adapterinterface.c +++ b/ext/logger/adapterinterface.c @@ -27,16 +27,17 @@ static const zend_function_entry phalcon_logger_adapterinterface_method_entry[] PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, getFormatter, NULL) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, setLogLevel, arginfo_phalcon_logger_adapterinterface_setloglevel) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, getLogLevel, NULL) - PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, log, arginfo_phalcon_logger_adapterinterface_log) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, begin, NULL) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, commit, NULL) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, rollback, NULL) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, close, NULL) + PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, log, arginfo_phalcon_logger_adapterinterface_log) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, debug, arginfo_phalcon_logger_adapterinterface_debug) - PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, error, arginfo_phalcon_logger_adapterinterface_error) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, info, arginfo_phalcon_logger_adapterinterface_info) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, notice, arginfo_phalcon_logger_adapterinterface_notice) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, warning, arginfo_phalcon_logger_adapterinterface_warning) + PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, error, arginfo_phalcon_logger_adapterinterface_error) + PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, critical, arginfo_phalcon_logger_adapterinterface_critical) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, alert, arginfo_phalcon_logger_adapterinterface_alert) PHP_ABSTRACT_ME(Phalcon_Logger_AdapterInterface, emergency, arginfo_phalcon_logger_adapterinterface_emergency) PHP_FE_END @@ -85,9 +86,10 @@ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, getLogLevel); /** * Sends/Writes messages to the file log * + * @param int|string $type * @param string $message - * @param int $type - * @return Phalcon\Logger\Adapter + * @param array $context + * @return Phalcon\Logger\AdapterInterface */ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, log); @@ -123,26 +125,17 @@ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, close); * Sends/Writes a debug message to the log * * @param string $message - * @param ing $type - * @return Phalcon\Logger\Adapter + * @param array $context + * @return Phalcon\Logger\AdapterInterface */ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, debug); -/** - * Sends/Writes an error message to the log - * - * @param string $message - * @param ing $type - * @return Phalcon\Logger\Adapter - */ -PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, error); - /** * Sends/Writes an info message to the log * * @param string $message - * @param ing $type - * @return Phalcon\Logger\Adapter + * @param array $context + * @return Phalcon\Logger\AdapterInterface */ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, info); @@ -150,8 +143,7 @@ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, info); * Sends/Writes a notice message to the log * * @param string $message - * @param ing $type - * @return Phalcon\Logger\Adapter + * @return Phalcon\Logger\AdapterInterface */ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, notice); @@ -159,16 +151,43 @@ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, notice); * Sends/Writes a warning message to the log * * @param string $message - * @param ing $type - * @return Phalcon\Logger\Adapter + * @param array $context + * @return Phalcon\Logger\AdapterInterface */ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, warning); +/** + * Sends/Writes an error message to the log + * + * @param string $message + * @param array $context + * @return Phalcon\Logger\AdapterInterface + */ +PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, error); + +/** + * Sends/Writes a critical message to the log + * + * @param string $message + * @param array $context + * @return Phalcon\Logger\AdapterInterface + */ +PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, critical); + /** * Sends/Writes an alert message to the log * * @param string $message - * @param ing $type - * @return Phalcon\Logger\Adapter + * @param array $context + * @return Phalcon\Logger\AdapterInterface */ PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, alert); + +/** + * Sends/Writes an emergency message to the log + * + * @param string $message + * @param array $context + * @return Phalcon\Logger\AdapterInterface + */ +PHALCON_DOC_METHOD(Phalcon_Logger_AdapterInterface, emergency); diff --git a/ext/logger/adapterinterface.h b/ext/logger/adapterinterface.h index ddb86015819..31e4163f3d1 100644 --- a/ext/logger/adapterinterface.h +++ b/ext/logger/adapterinterface.h @@ -65,6 +65,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapterinterface_warning, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, context, 1) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapterinterface_critical, 0, 0, 1) + ZEND_ARG_INFO(0, message) + ZEND_ARG_ARRAY_INFO(0, context, 1) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_logger_adapterinterface_alert, 0, 0, 1) ZEND_ARG_INFO(0, message) ZEND_ARG_ARRAY_INFO(0, context, 1) diff --git a/ext/logger/multiple.c b/ext/logger/multiple.c index c7bf2fca81e..8cd4a47717f 100644 --- a/ext/logger/multiple.c +++ b/ext/logger/multiple.c @@ -21,6 +21,7 @@ #include "logger/adapterinterface.h" #include "logger/exception.h" #include "logger.h" +#include "psr/log/invalidargumentexception.h" #include "kernel/main.h" #include "kernel/memory.h" @@ -90,10 +91,11 @@ PHALCON_INIT_CLASS(Phalcon_Logger_Multiple){ PHP_METHOD(Phalcon_Logger_Multiple, push){ zval *logger; + zend_class_entry *exception = PHALCON_GLOBAL(register_psr3_classes) ? psr_log_invalidargumentexception_ce : phalcon_logger_exception_ce; phalcon_fetch_params(0, 1, 0, &logger); - PHALCON_VERIFY_INTERFACE_EX(logger, phalcon_logger_adapterinterface_ce, phalcon_logger_exception_ce, 0) + PHALCON_VERIFY_INTERFACE_EX(logger, phalcon_logger_adapterinterface_ce, exception, 0) phalcon_update_property_array_append(this_ptr, SL("_loggers"), logger TSRMLS_CC); } diff --git a/ext/phalcon.c b/ext/phalcon.c index 309aabfcf53..e54e3c6ab57 100644 --- a/ext/phalcon.c +++ b/ext/phalcon.c @@ -182,19 +182,21 @@ static void phalcon_verify_permanent_zvals(int strict TSRMLS_DC) PHP_INI_BEGIN() /* Enables/Disables globally the internal events */ - STD_PHP_INI_BOOLEAN("phalcon.orm.events", "1", PHP_INI_ALL, OnUpdateBool, orm.events, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.orm.events", "1", PHP_INI_ALL, OnUpdateBool, orm.events, zend_phalcon_globals, phalcon_globals) /* Enables/Disables virtual foreign keys */ - STD_PHP_INI_BOOLEAN("phalcon.orm.virtual_foreign_keys", "1", PHP_INI_ALL, OnUpdateBool, orm.virtual_foreign_keys, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.orm.virtual_foreign_keys", "1", PHP_INI_ALL, OnUpdateBool, orm.virtual_foreign_keys, zend_phalcon_globals, phalcon_globals) /* Enables/Disables column renaming */ - STD_PHP_INI_BOOLEAN("phalcon.orm.column_renaming", "1", PHP_INI_ALL, OnUpdateBool, orm.column_renaming, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.orm.column_renaming", "1", PHP_INI_ALL, OnUpdateBool, orm.column_renaming, zend_phalcon_globals, phalcon_globals) /* Enables/Disables automatic NOT NULL validation */ - STD_PHP_INI_BOOLEAN("phalcon.orm.not_null_validations", "1", PHP_INI_ALL, OnUpdateBool, orm.not_null_validations, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.orm.not_null_validations", "1", PHP_INI_ALL, OnUpdateBool, orm.not_null_validations, zend_phalcon_globals, phalcon_globals) /* Enables/Disables throwing an exception if save fails */ - STD_PHP_INI_BOOLEAN("phalcon.orm.exception_on_failed_save", "0", PHP_INI_ALL, OnUpdateBool, orm.exception_on_failed_save, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.orm.exception_on_failed_save", "0", PHP_INI_ALL, OnUpdateBool, orm.exception_on_failed_save, zend_phalcon_globals, phalcon_globals) /* Enables/Disables literals in PHQL */ - STD_PHP_INI_BOOLEAN("phalcon.orm.enable_literals", "1", PHP_INI_ALL, OnUpdateBool, orm.enable_literals, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.orm.enable_literals", "1", PHP_INI_ALL, OnUpdateBool, orm.enable_literals, zend_phalcon_globals, phalcon_globals) /* Not used? */ - STD_PHP_INI_BOOLEAN("phalcon.db.escape_identifiers", "1", PHP_INI_ALL, OnUpdateBool, db.escape_identifiers, zend_phalcon_globals, phalcon_globals) + STD_PHP_INI_BOOLEAN("phalcon.db.escape_identifiers", "1", PHP_INI_ALL, OnUpdateBool, db.escape_identifiers, zend_phalcon_globals, phalcon_globals) + /* Whether to register PSR-3 classes */ + STD_PHP_INI_BOOLEAN("phalcon.register_psr3_classes", "0", PHP_INI_SYSTEM, OnUpdateBool, register_psr3_classes, zend_phalcon_globals, phalcon_globals) PHP_INI_END() static PHP_MINIT_FUNCTION(phalcon) @@ -316,7 +318,19 @@ static PHP_MINIT_FUNCTION(phalcon) PHALCON_INIT(Phalcon_Translate_AdapterInterface); PHALCON_INIT(Phalcon_Validation_ValidatorInterface); - /* 3. Register everything else */ + /* 3. Register PSR-3 classes */ + if (PHALCON_GLOBAL(register_psr3_classes)) { + PHALCON_INIT(Psr_Log_LoggerAwareInterface); + PHALCON_INIT(Psr_Log_LoggerInterface); + PHALCON_INIT(Psr_Log_InvalidArgumentException); + PHALCON_INIT(Psr_Log_LogLevel); + PHALCON_INIT(Psr_Log_AbstractLogger); + PHALCON_INIT(Psr_Log_NullLogger); + PHALCON_INIT(Psr_Log_LoggerAwareTrait); + PHALCON_INIT(Psr_Log_LoggerTrait); + } + + /* 4. Register everything else */ PHALCON_INIT(Phalcon_Db_Adapter); PHALCON_INIT(Phalcon_DI_Injectable); PHALCON_INIT(Phalcon_DI); @@ -608,6 +622,8 @@ static PHP_GINIT_FUNCTION(phalcon) phalcon_globals->function_cache = pemalloc(sizeof(HashTable), 1); zend_hash_init(phalcon_globals->function_cache, 128, NULL, NULL, 1); + phalcon_globals->register_psr3_classes = 0; + /* 'Allocator sizeof operand mismatch' warning can be safely ignored */ ALLOC_PERMANENT_ZVAL(phalcon_globals->z_null); INIT_ZVAL(*phalcon_globals->z_null); diff --git a/ext/phalcon.h b/ext/phalcon.h index acdb4b8aead..d967f0815f2 100644 --- a/ext/phalcon.h +++ b/ext/phalcon.h @@ -311,6 +311,15 @@ #include "paginator/adapter/querybuilder.h" #include "paginator/exception.h" +#include "psr/log/abstractlogger.h" +#include "psr/log/invalidargumentexception.h" +#include "psr/log/loggerawareinterface.h" +#include "psr/log/loggerawaretrait.h" +#include "psr/log/loggerinterface.h" +#include "psr/log/loggertrait.h" +#include "psr/log/loglevel.h" +#include "psr/log/nulllogger.h" + #include "queue/beanstalk.h" #include "queue/beanstalk/job.h" diff --git a/ext/php_phalcon.h b/ext/php_phalcon.h index 25e727462b5..7faf854b4b6 100644 --- a/ext/php_phalcon.h +++ b/ext/php_phalcon.h @@ -105,6 +105,8 @@ ZEND_BEGIN_MODULE_GLOBALS(phalcon) /** Max recursion control */ unsigned int recursive_lock; + zend_bool register_psr3_classes; + /** DB */ phalcon_db_options db; diff --git a/ext/psr/log/abstractlogger.c b/ext/psr/log/abstractlogger.c new file mode 100644 index 00000000000..000226abbd1 --- /dev/null +++ b/ext/psr/log/abstractlogger.c @@ -0,0 +1,124 @@ +#include "psr/log/abstractlogger.h" +#include "psr/log/loggerinterface.h" +#include "psr/log/loglevel.h" + +zend_class_entry *psr_log_abstractlogger_ce; + +static void psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAMETERS, const char *lvl) +{ + zval *level, *message, *context = NULL; + zval *retval = NULL; + zval **params[3] = { &level, &message, &context }; + zval function_name = zval_used_for_init; + zend_fcall_info fci; + zend_fcall_info_cache fcic; + zend_class_entry *ce; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &message, &context)) { + RETURN_NULL(); + } + + ce = Z_OBJCE_P(getThis()); + + if (!context) { + MAKE_STD_ZVAL(context); + array_init(context); + Z_SET_REFCOUNT_P(context, 0); + } + + MAKE_STD_ZVAL(level); + ZVAL_STRING(level, lvl, 1); + Z_SET_REFCOUNT_P(level, 0); + + fci.size = sizeof(fci); + fci.function_table = &ce->function_table; + fci.object_ptr = getThis(); + fci.function_name = &function_name; + fci.retval_ptr_ptr = &retval; + fci.param_count = 3; + fci.params = params; + fci.no_separation = 1; + fci.symbol_table = NULL; + + fcic.initialized = 1; + fcic.object_ptr = getThis(); + fcic.calling_scope = ce; + fcic.called_scope = ce; + + if (zend_hash_quick_find(fci.function_table, ZEND_STRS("log"), zend_inline_hash_func(ZEND_STRS("log")), (void**)&fcic.function_handler) == FAILURE) { + fcic.initialized = 0; + ZVAL_STRING(&function_name, "log", 0); + } + + zend_call_function(&fci, &fcic TSRMLS_CC); + + if (retval) { + zval_ptr_dtor(&retval); + } +} + +PHP_FUNCTION(Psr_Log_Emergency) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_EMERGENCY); +} + +PHP_FUNCTION(Psr_Log_Alert) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_ALERT); +} + +PHP_FUNCTION(Psr_Log_Critical) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_CRITICAL); +} + +PHP_FUNCTION(Psr_Log_Error) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_ERROR); +} + +PHP_FUNCTION(Psr_Log_Warning) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_WARNING); +} + +PHP_FUNCTION(Psr_Log_Notice) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_NOTICE); +} + +PHP_FUNCTION(Psr_Log_Info) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_INFO); +} + +PHP_FUNCTION(Psr_Log_Debug) +{ + psr_log_abstractlogger_log_helper(INTERNAL_FUNCTION_PARAM_PASSTHRU, PSR_LOG_LOGLEVEL_DEBUG); +} + +static const zend_function_entry fe_psr_log_abstractlogger[] = { + PHP_ME_MAPPING(emergency, Psr_Log_Emergency, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(alert, Psr_Log_Alert, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(critical, Psr_Log_Critical, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(error, Psr_Log_Error, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(warning, Psr_Log_Warning, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(notice, Psr_Log_Notice, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(info, Psr_Log_Info, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(debug, Psr_Log_Debug, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +PHALCON_INIT_CLASS(Psr_Log_AbstractLogger) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\AbstractLogger", fe_psr_log_abstractlogger); + + psr_log_abstractlogger_ce = zend_register_internal_class(&ce TSRMLS_CC); + if (EXPECTED(psr_log_abstractlogger_ce != NULL)) { + zend_class_implements(psr_log_abstractlogger_ce TSRMLS_CC, 1, psr_log_loggerinterface_ce); + return SUCCESS; + } + + return FAILURE; +} diff --git a/ext/psr/log/abstractlogger.h b/ext/psr/log/abstractlogger.h new file mode 100644 index 00000000000..dc09f2aa53f --- /dev/null +++ b/ext/psr/log/abstractlogger.h @@ -0,0 +1,19 @@ +#ifndef PSR_LOG_ABSTRACTLOGGER_H +#define PSR_LOG_ABSTRACTLOGGER_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_abstractlogger_ce; + +PHALCON_INIT_CLASS(Psr_Log_AbstractLogger); + +PHP_FUNCTION(Psr_Log_Emergency); +PHP_FUNCTION(Psr_Log_Alert); +PHP_FUNCTION(Psr_Log_Critical); +PHP_FUNCTION(Psr_Log_Error); +PHP_FUNCTION(Psr_Log_Warning); +PHP_FUNCTION(Psr_Log_Notice); +PHP_FUNCTION(Psr_Log_Info); +PHP_FUNCTION(Psr_Log_Debug); + +#endif /* PSR_LOG_ABSTRACTLOGGER_H */ diff --git a/ext/psr/log/invalidargumentexception.c b/ext/psr/log/invalidargumentexception.c new file mode 100644 index 00000000000..8d1be3d1ab9 --- /dev/null +++ b/ext/psr/log/invalidargumentexception.c @@ -0,0 +1,15 @@ +#include "psr/log/invalidargumentexception.h" + +#include +#include + +zend_class_entry *psr_log_invalidargumentexception_ce; + +PHALCON_INIT_CLASS(Psr_Log_InvalidArgumentException) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\InvalidArgumentException", NULL); + + psr_log_invalidargumentexception_ce = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException, NULL TSRMLS_CC); + return (EXPECTED(psr_log_invalidargumentexception_ce != NULL)) ? SUCCESS : FAILURE; +} diff --git a/ext/psr/log/invalidargumentexception.h b/ext/psr/log/invalidargumentexception.h new file mode 100644 index 00000000000..cb648f5a47b --- /dev/null +++ b/ext/psr/log/invalidargumentexception.h @@ -0,0 +1,10 @@ +#ifndef PSR_LOG_INVALIDARGUMENTEXCEPTION_H +#define PSR_LOG_INVALIDARGUMENTEXCEPTION_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_invalidargumentexception_ce; + +PHALCON_INIT_CLASS(Psr_Log_InvalidArgumentException); + +#endif /* PSR_LOG_INVALIDARGUMENTEXCEPTION_H */ diff --git a/ext/psr/log/loggerawareinterface.c b/ext/psr/log/loggerawareinterface.c new file mode 100644 index 00000000000..ef38140cd3d --- /dev/null +++ b/ext/psr/log/loggerawareinterface.c @@ -0,0 +1,17 @@ +#include "psr/log/loggerawareinterface.h" + +zend_class_entry *psr_log_loggerawareinterface_ce; + +static const zend_function_entry fe_psr_log_loggerawareinterface[] = { + PHP_ABSTRACT_ME(Psr_Log_LoggerAwareInterface, setLogger, arginfo_psr_log_loggerawareinterface_setlogger) + PHP_FE_END +}; + +PHALCON_INIT_CLASS(Psr_Log_LoggerAwareInterface) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\LoggerAwareInterface", fe_psr_log_loggerawareinterface); + + psr_log_loggerawareinterface_ce = zend_register_internal_interface(&ce TSRMLS_CC); + return (EXPECTED(psr_log_loggerawareinterface_ce != NULL)) ? SUCCESS : FAILURE; +} diff --git a/ext/psr/log/loggerawareinterface.h b/ext/psr/log/loggerawareinterface.h new file mode 100644 index 00000000000..09a0c62b3e6 --- /dev/null +++ b/ext/psr/log/loggerawareinterface.h @@ -0,0 +1,14 @@ +#ifndef PSR_LOG_LOGGERAWAREINTERFACE_H +#define PSR_LOG_LOGGERAWAREINTERFACE_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_loggerawareinterface_ce; + +PHALCON_INIT_CLASS(Psr_Log_LoggerAwareInterface); + +ZEND_BEGIN_ARG_INFO_EX(arginfo_psr_log_loggerawareinterface_setlogger, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, logger, Psr\\Log\\LoggerInterface, 0) +ZEND_END_ARG_INFO() + +#endif /* PSR_LOG_LOGGERAWAREINTERFACE_H */ diff --git a/ext/psr/log/loggerawaretrait.c b/ext/psr/log/loggerawaretrait.c new file mode 100644 index 00000000000..7cd332c5cd0 --- /dev/null +++ b/ext/psr/log/loggerawaretrait.c @@ -0,0 +1,48 @@ +#include "psr/log/loggerawaretrait.h" +#include "psr/log/loggerawareinterface.h" + +zend_class_entry *psr_log_loggerawaretrait_ce; + +#if PHP_VERSION_ID >= 50400 + +static PHP_METHOD(Psr_Log_LoggerAwareTrait, setLogger) +{ + zval **logger; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &logger)) { + RETURN_NULL(); + } + + zend_update_property(psr_log_loggerawaretrait_ce, getThis(), ZEND_STRL("logger"), *logger TSRMLS_CC); +} + +static const zend_function_entry fe_psr_log_loggerawaretrait[] = { + PHP_ME(Psr_Log_LoggerAwareTrait, setLogger, arginfo_psr_log_loggerawareinterface_setlogger, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +PHALCON_INIT_CLASS(Psr_Log_LoggerAwareTrait) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\LoggerAwareTrait", fe_psr_log_loggerawaretrait); + + psr_log_loggerawaretrait_ce = zend_register_internal_class(&ce TSRMLS_CC); + if (EXPECTED(psr_log_loggerawaretrait_ce != NULL)) { + psr_log_loggerawaretrait_ce->ce_flags |= ZEND_ACC_TRAIT; + + zend_declare_property_null(psr_log_loggerawaretrait_ce, ZEND_STRL("logger"), ZEND_ACC_PROTECTED TSRMLS_CC); + return SUCCESS; + } + + return FAILURE; +} + +#else + +PHALCON_INIT_CLASS(Psr_Log_LoggerAwareTrait) +{ + psr_log_loggerawaretrait_ce = NULL; + return SUCCESS; +} + +#endif diff --git a/ext/psr/log/loggerawaretrait.h b/ext/psr/log/loggerawaretrait.h new file mode 100644 index 00000000000..eb208e969e5 --- /dev/null +++ b/ext/psr/log/loggerawaretrait.h @@ -0,0 +1,10 @@ +#ifndef PSR_LOG_LOGGERAWARETRAIT_H +#define PSR_LOG_LOGGERAWARETRAIT_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_loggerawaretrait_ce; + +PHALCON_INIT_CLASS(Psr_Log_LoggerAwareTrait); + +#endif /* PSR_LOG_LOGGERAWARETRAIT_H */ diff --git a/ext/psr/log/loggerinterface.c b/ext/psr/log/loggerinterface.c new file mode 100644 index 00000000000..2e18f25a6d6 --- /dev/null +++ b/ext/psr/log/loggerinterface.c @@ -0,0 +1,25 @@ +#include "psr/log/loggerinterface.h" + +zend_class_entry *psr_log_loggerinterface_ce; + +static const zend_function_entry fe_psr_log_loggerinterface[] = { + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, emergency, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, alert, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, critical, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, error, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, warning, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, notice, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, info, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, debug, arginfo_psr_log_loggerinterface_logspecialized) + PHP_ABSTRACT_ME(Psr_Log_LoggerInterface, log, arginfo_psr_log_loggerinterface_log) + PHP_FE_END +}; + +PHALCON_INIT_CLASS(Psr_Log_LoggerInterface) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\LoggerInterface", fe_psr_log_loggerinterface); + + psr_log_loggerinterface_ce = zend_register_internal_interface(&ce TSRMLS_CC); + return (EXPECTED(psr_log_loggerinterface_ce != NULL)) ? SUCCESS : FAILURE; +} diff --git a/ext/psr/log/loggerinterface.h b/ext/psr/log/loggerinterface.h new file mode 100644 index 00000000000..904eac2a732 --- /dev/null +++ b/ext/psr/log/loggerinterface.h @@ -0,0 +1,21 @@ +#ifndef PSR_LOG_LOGGERINTERFACE_H +#define PSR_LOG_LOGGERINTERFACE_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_loggerinterface_ce; + +PHALCON_INIT_CLASS(Psr_Log_LoggerInterface); + +ZEND_BEGIN_ARG_INFO_EX(arginfo_psr_log_loggerinterface_log, 0, 0, 2) + ZEND_ARG_INFO(0, level) + ZEND_ARG_INFO(0, message) + ZEND_ARG_ARRAY_INFO(0, context, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_psr_log_loggerinterface_logspecialized, 0, 0, 1) + ZEND_ARG_INFO(0, message) + ZEND_ARG_ARRAY_INFO(0, context, 0) +ZEND_END_ARG_INFO() + +#endif /* PSR_LOG_LOGGERINTERFACE_H */ diff --git a/ext/psr/log/loggertrait.c b/ext/psr/log/loggertrait.c new file mode 100644 index 00000000000..ae9deec92a3 --- /dev/null +++ b/ext/psr/log/loggertrait.c @@ -0,0 +1,44 @@ +#include "psr/log/loggertrait.h" +#include "psr/log/abstractlogger.h" +#include "psr/log/loggerinterface.h" + +zend_class_entry *psr_log_loggertrait_ce; + +#if PHP_VERSION_ID >= 50400 + +static const zend_function_entry fe_psr_log_loggertrait[] = { + PHP_ME_MAPPING(emergency, Psr_Log_Emergency, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(alert, Psr_Log_Alert, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(critical, Psr_Log_Critical, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(error, Psr_Log_Error, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(warning, Psr_Log_Warning, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(notice, Psr_Log_Notice, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(info, Psr_Log_Info, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ME_MAPPING(debug, Psr_Log_Debug, arginfo_psr_log_loggerinterface_logspecialized, ZEND_ACC_PUBLIC) + PHP_ABSTRACT_ME(Psr_Log_LoggerTrait, log, arginfo_psr_log_loggerinterface_log) + PHP_FE_END +}; + +PHALCON_INIT_CLASS(Psr_Log_LoggerTrait) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\LoggerTrait", fe_psr_log_loggertrait); + + psr_log_loggertrait_ce = zend_register_internal_class(&ce TSRMLS_CC); + if (EXPECTED(psr_log_loggertrait_ce != NULL)) { + psr_log_loggertrait_ce->ce_flags |= ZEND_ACC_TRAIT; + return SUCCESS; + } + + return FAILURE; +} + +#else + +PHALCON_INIT_CLASS(Psr_Log_LoggerTrait) +{ + psr_log_loggertrait_ce = NULL; + return SUCCESS; +} + +#endif diff --git a/ext/psr/log/loggertrait.h b/ext/psr/log/loggertrait.h new file mode 100644 index 00000000000..c07e6c0733a --- /dev/null +++ b/ext/psr/log/loggertrait.h @@ -0,0 +1,10 @@ +#ifndef PSR_LOG_LOGGERTRAIT_H +#define PSR_LOG_LOGGERTRAIT_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_loggertrait_ce; + +PHALCON_INIT_CLASS(Psr_Log_LoggerTrait); + +#endif /* PSR_LOG_LOGGERTRAIT_H */ diff --git a/ext/psr/log/loglevel.c b/ext/psr/log/loglevel.c new file mode 100644 index 00000000000..caf197ec4e5 --- /dev/null +++ b/ext/psr/log/loglevel.c @@ -0,0 +1,25 @@ +#include "psr/log/loglevel.h" + +zend_class_entry *psr_log_loglevel_ce; + +PHALCON_INIT_CLASS(Psr_Log_LogLevel) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\LogLevel", NULL); + + psr_log_loglevel_ce = zend_register_internal_class(&ce TSRMLS_CC); + if (EXPECTED(psr_log_loglevel_ce != NULL)) { + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("EMERGENCY"), ZEND_STRS(PSR_LOG_LOGLEVEL_EMERGENCY) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("ALERT"), ZEND_STRS(PSR_LOG_LOGLEVEL_ALERT) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("CRITICAL"), ZEND_STRS(PSR_LOG_LOGLEVEL_CRITICAL) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("ERROR"), ZEND_STRS(PSR_LOG_LOGLEVEL_ERROR) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("WARNING"), ZEND_STRS(PSR_LOG_LOGLEVEL_WARNING) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("NOTICE"), ZEND_STRS(PSR_LOG_LOGLEVEL_NOTICE) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("INFO"), ZEND_STRS(PSR_LOG_LOGLEVEL_INFO) TSRMLS_CC); + zend_declare_class_constant_stringl(psr_log_loglevel_ce, ZEND_STRS("DEBUG"), ZEND_STRS(PSR_LOG_LOGLEVEL_DEBUG) TSRMLS_CC); + + return SUCCESS; + } + + return FAILURE; +} diff --git a/ext/psr/log/loglevel.h b/ext/psr/log/loglevel.h new file mode 100644 index 00000000000..a48a1dbf56c --- /dev/null +++ b/ext/psr/log/loglevel.h @@ -0,0 +1,19 @@ +#ifndef PSR_LOG_LOGLEVEL_H +#define PSR_LOG_LOGLEVEL_H + +#include "php_phalcon.h" + +#define PSR_LOG_LOGLEVEL_EMERGENCY "emergency" +#define PSR_LOG_LOGLEVEL_ALERT "alert" +#define PSR_LOG_LOGLEVEL_CRITICAL "critical" +#define PSR_LOG_LOGLEVEL_ERROR "error" +#define PSR_LOG_LOGLEVEL_WARNING "warning" +#define PSR_LOG_LOGLEVEL_NOTICE "notice" +#define PSR_LOG_LOGLEVEL_INFO "info" +#define PSR_LOG_LOGLEVEL_DEBUG "debug" + +extern zend_class_entry *psr_log_loglevel_ce; + +PHALCON_INIT_CLASS(Psr_Log_LogLevel); + +#endif /* PSR_LOG_LOGLEVEL_H */ diff --git a/ext/psr/log/nulllogger.c b/ext/psr/log/nulllogger.c new file mode 100644 index 00000000000..94c7a68cad5 --- /dev/null +++ b/ext/psr/log/nulllogger.c @@ -0,0 +1,28 @@ +#include "psr/log/nulllogger.h" +#include "psr/log/abstractlogger.h" +#include "psr/log/loggerinterface.h" + +zend_class_entry *psr_log_nulllogger_ce; + +static PHP_METHOD(Psr_Log_NullLogger, log) +{ + zval *level, *message, *context = NULL; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z!", &level, &message, &context)) { + RETURN_NULL(); + } +} + +static const zend_function_entry fe_psr_log_nulllogger[] = { + PHP_ME(Psr_Log_NullLogger, log, arginfo_psr_log_loggerinterface_log, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + +PHALCON_INIT_CLASS(Psr_Log_NullLogger) +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "Psr\\Log\\NullLogger", fe_psr_log_nulllogger); + + psr_log_nulllogger_ce = zend_register_internal_class_ex(&ce, psr_log_abstractlogger_ce, NULL TSRMLS_CC); + return (EXPECTED(psr_log_nulllogger_ce != NULL)) ? SUCCESS : FAILURE; +} diff --git a/ext/psr/log/nulllogger.h b/ext/psr/log/nulllogger.h new file mode 100644 index 00000000000..fed79d303b1 --- /dev/null +++ b/ext/psr/log/nulllogger.h @@ -0,0 +1,10 @@ +#ifndef PSR_LOG_NULLLOGGER_H +#define PSR_LOG_NULLLOGGER_H + +#include "php_phalcon.h" + +extern zend_class_entry *psr_log_nulllogger_ce; + +PHALCON_INIT_CLASS(Psr_Log_NullLogger); + +#endif /* PSR_LOG_NULLLOGGER_H */ diff --git a/ext/tests/psr-3.phpt b/ext/tests/psr-3.phpt index 8d1f5de1e0b..c6a9e8df9d0 100644 --- a/ext/tests/psr-3.phpt +++ b/ext/tests/psr-3.phpt @@ -2,6 +2,8 @@ Make Phalcon\Logger compatible with PSR-3 --SKIPIF-- +--INI-- +phalcon.register_psr3_classes = 1 --FILE-- log('warning', 'This is a warning message'); $logger->log(\Phalcon\Logger::ERROR, 'This is an error message'); $logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar')); + +assert(interface_exists('Psr\Log\LoggerAwareInterface', false)); +assert(interface_exists('Psr\Log\LoggerInterface', false)); + +assert(class_exists('Psr\Log\AbstractLogger', false)); +assert(class_exists('Psr\Log\InvalidArgumentException', false)); +assert(class_exists('Psr\Log\LogLevel', false)); +assert(class_exists('Psr\Log\NullLogger', false)); + +if (PHP_VERSION_ID >= 50400) { + assert(trait_exists('Psr\Log\LoggerAwareTrait', false)); + assert(trait_exists('Psr\Log\LoggerTrait', false)); +} + ?> --EXPECTF-- [%s, %d %s %d %d:%d:%d %s][DEBUG] This is a debug message