flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-wpdesk-fs-table-rate
/
src
/
Logger
/
ShippingMethodLogger.php
flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-wpdesk-fs-table-rate
/
src
/
Logger
Last commit date
view
1 week ago
ArrayLogger.php
1 week ago
Assets.php
1 week ago
CanFormatForLog.php
1 week ago
NoticeLogger.php
1 week ago
ShippingMethodLogger.php
1 week ago
ShippingMethodLogger.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Shipping method logger. |
| 5 | * |
| 6 | * @package WPDesk\FS\TableRate\Logger |
| 7 | */ |
| 8 | namespace FSVendor\WPDesk\FS\TableRate\Logger; |
| 9 | |
| 10 | use FSVendor\Psr\Log\LoggerInterface; |
| 11 | use FSVendor\Psr\Log\LoggerTrait; |
| 12 | /** |
| 13 | * Can log shipping method messages. |
| 14 | */ |
| 15 | class ShippingMethodLogger implements LoggerInterface |
| 16 | { |
| 17 | use LoggerTrait; |
| 18 | /** |
| 19 | * @var LoggerInterface |
| 20 | */ |
| 21 | private $fs_logger; |
| 22 | /** |
| 23 | * @var LoggerInterface |
| 24 | */ |
| 25 | private $notice_logger; |
| 26 | /** |
| 27 | * ShippingMethodLogger constructor. |
| 28 | * |
| 29 | * @param LoggerInterface $fs_logger |
| 30 | * @param NoticeLogger $notice_logger |
| 31 | */ |
| 32 | public function __construct(LoggerInterface $fs_logger, LoggerInterface $notice_logger) |
| 33 | { |
| 34 | $this->fs_logger = $fs_logger; |
| 35 | $this->notice_logger = $notice_logger; |
| 36 | } |
| 37 | /** |
| 38 | * @param mixed $level . |
| 39 | * @param string $message . |
| 40 | * @param array $context . |
| 41 | */ |
| 42 | public function log($level, $message, array $context = array()): void |
| 43 | { |
| 44 | $this->fs_logger->log($level, $message, $context); |
| 45 | $this->notice_logger->log($level, $message, $context); |
| 46 | } |
| 47 | /** |
| 48 | * Log entries from array logger. |
| 49 | * |
| 50 | * @param ArrayLogger $array_logger |
| 51 | * @param array $context |
| 52 | */ |
| 53 | public function log_from_array_logger(ArrayLogger $array_logger, array $context = array()) |
| 54 | { |
| 55 | foreach ($array_logger->get_messages() as $message) { |
| 56 | $this->log($message['level'], $message['message'], array_merge($message['context'], $context)); |
| 57 | } |
| 58 | } |
| 59 | /** |
| 60 | * Show notice if enabled. |
| 61 | */ |
| 62 | public function show_notice_if_enabled() |
| 63 | { |
| 64 | $this->notice_logger->show_notice_if_enabled(); |
| 65 | } |
| 66 | /** |
| 67 | * @return array |
| 68 | */ |
| 69 | public function get_configuration_section_context() |
| 70 | { |
| 71 | return array('section' => __('shipping method configuration', 'flexible-shipping')); |
| 72 | } |
| 73 | /** |
| 74 | * @return array |
| 75 | */ |
| 76 | public function get_input_data_context() |
| 77 | { |
| 78 | return array('section' => __('input data', 'flexible-shipping')); |
| 79 | } |
| 80 | /** |
| 81 | * @return array |
| 82 | */ |
| 83 | public function get_rule_context($rule_triggered) |
| 84 | { |
| 85 | return array('section' => sprintf(__('rules (%1$s)', 'flexible-shipping'), $rule_triggered ? __('triggered', 'flexible-shipping') : __('not triggered', 'flexible-shipping'))); |
| 86 | } |
| 87 | /** |
| 88 | * @return array |
| 89 | */ |
| 90 | public function get_results_context() |
| 91 | { |
| 92 | return array('section' => __('the result of shipping method\'s usage', 'flexible-shipping')); |
| 93 | } |
| 94 | } |
| 95 |