PHP Classes
elePHPant
Icontem

File: docs/files/Stream/Strategy/AbstractEmailLoggerStrategy.php.txt

Recommend this page to a friend!
  Classes of Kiril Savchev  >  ITE Logger  >  docs/files/Stream/Strategy/AbstractEmailLoggerStrategy.php.txt  >  Download  
File: docs/files/Stream/Strategy/AbstractEmailLoggerStrategy.php.txt
Role: Documentation
Content type: text/plain
Description: Documentation
Class: ITE Logger
Log messages to different storage PSR-3 compliant
Author: By
Last change:
Date: 3 years ago
Size: 2,089 bytes
 

 

Contents

Class file image Download
<?php

/**
 * AbstractEmailLoggerStrategy file
 *
 * Copyright (c) 2016, Kiril Savchev
 * All rights reserved.
 *
 * @category Libs
 * @package Logger
 *
 * @author Kiril Savchev <k.savchev@gmail.com>
 *
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3 License
 * @link http://ifthenelse.info
 */
namespace Ite\Logger\Stream\Strategy;

use Ite\Logger\AbstractEmailLogger;
use Ite\Logger\Exception\InvalidArgumentException;
use Psr\Log\LoggerInterface;

/**
 * AbstractEmailLoggerStrategy
 *
 * Simple strategy for descendants of AbstractEmailLogger
 *
 * @uses psr\log
 *
 * @version 1.0
 *
 * @author Kiril Savchev <k.savchev@gmail.com>
 */
class AbstractEmailLoggerStrategy implements StreamLoggerStrategyInterface {

        /**
         * Prepare the logger before using
         *
         * @param LoggerInterface $logger
         * @param array $options
         * @throw \Ite\Logger\Exception\InvalidArgumentException If logger is not the desired class instance
         */
        public function prepareLogger(LoggerInterface $logger, array $options) {
                if (!($logger instanceof AbstractEmailLogger)) {
                        throw new InvalidArgumentException("Invalid logger type");
                }
                $query = $options['query'];
                $level = $options['path'];
                $config = [];
                if (array_key_exists('to', $query)) {
                        $logger->setDefaultTo($query['to']);
                        $config['to'] = $query['to'];
                }
                if (array_key_exists('from', $query)) {
                        $config['from'] = $query['from'];
                }
                if (array_key_exists('headers', $query)) {
                        $config['headers'] = $query['headers'];
                }
                if (array_key_exists('subject', $query)) {
                        $config['subject'] = $query['subject'];
                }
                if ($config) {
                        $logger->setConfig([$level => $config]);
                }
        }

}