Skip to content

Commit c95abc9

Browse files
committed
options
1 parent d9b80dc commit c95abc9

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use \InitPHP\Logger\FileLogger;
3333

3434
$logFile = __DIR__ . '/logfile.log';
3535

36-
$logger = new Logger(new FileLogger($logFile));
36+
$logger = new Logger(new FileLogger(['path' => $logFile]));
3737
```
3838

3939
### PdoLogger
@@ -46,7 +46,7 @@ use \InitPHP\Logger\PDOLogger;
4646
$table = 'logs';
4747
$pdo = new \PDO('mysql:dbname=project;host=localhost', 'root', '');
4848

49-
$logger = new Logger(new PDOLogger($pdo, $table));
49+
$logger = new Logger(new PDOLogger(['pdo' => $pdo, 'table' => $table]));
5050

5151
$logger->error('User {user} caused an error.', array('user' => 'muhametsafak'));
5252
// INSERT INTO logs (level, message, date) VALUES ('ERROR', 'User muhametsafak caused an error.', '2022-03-11 13:05:45')
@@ -75,7 +75,7 @@ $logFile = __DIR__ . '/logfile.log';
7575
$table = 'logs';
7676
$pdo = new \PDO('mysql:dbname=project;host=localhost', 'root', '');
7777

78-
$logger = new Logger(new FileLogger($logFile), new PDOLogger($pdo, $table));
78+
$logger = new Logger(new FileLogger(['path' => $logFile]), new PDOLogger(['pdo' => $pdo, 'table' => $table]));
7979
```
8080

8181
## Methods

src/FileLogger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class FileLogger extends \Psr\Log\AbstractLogger implements \Psr\Log\LoggerInter
3030
protected $path;
3131

3232
/**
33-
* @param string $path
33+
* @param array $options
3434
*/
35-
public function __construct($path)
35+
public function __construct(array $options = [])
3636
{
37-
$this->path = $this->interpolate($path, array(
37+
$this->path = $this->interpolate($options['path'], array(
3838
'year' => date('Y'),
3939
'month' => date('m'),
4040
'day' => date('d'),

src/PDOLogger.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ class PDOLogger extends \Psr\Log\AbstractLogger implements \Psr\Log\LoggerInterf
3030
/** @var string */
3131
protected $table;
3232

33-
public function __construct($pdo, $table)
33+
/**
34+
* @param array $options
35+
*/
36+
public function __construct(array $options = [])
3437
{
35-
if(!($pdo instanceof PDO)){
38+
if(!($options['pdo'] instanceof PDO)){
3639
throw new \InvalidArgumentException('It must be a PDO object.');
3740
}
38-
if(!is_string($table)){
41+
if(!is_string($options['table'])){
3942
throw new \InvalidArgumentException('The name of the table where the logs will be kept must be specified as a string.');
4043
}
41-
$this->pdo = $pdo;
42-
$this->table = $table;
44+
$this->pdo = $options['pdo'];
45+
$this->table = $options['table'];
4346
}
4447

4548
public function __destruct()

0 commit comments

Comments
 (0)