<?php
/**
* PdoMysqlLoggerStrategy 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\Exception\InvalidArgumentException;
use Ite\Logger\PdoMysqlLogger;
use Psr\Log\LoggerInterface;
/**
* PdoMysqlLoggerStrategy
*
* @version 1.2
*
* @author Kiril Savchev <k.savchev@gmail.com>
*/
class PdoMysqlLoggerStrategy extends AbstractDatabaseLoggerStrategy {
public function prepareLogger(LoggerInterface $logger, array $options) {
if (!($logger instanceof PdoMysqlLogger)) {
throw new InvalidArgumentException("Invalid logger type");
}
// Add database connection configs (replace them with your values):
$config = ['username' => 'root', 'password' => '1', 'name' => 'world', 'host' => 'localhost'];
if (!empty($options['query'])) {
foreach ($options['query'] as $key => $val) {
if (array_key_exists($key, $config)) {
$config[$key] = $val;
}
}
}
$logger->setDbConfig($config);
parent::prepareLogger($logger, $options);
}
}
|