| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of Mustache.php. |
| 5 |
* |
| 6 |
* (c) 2010-2017 Justin Hileman |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Abstract Mustache Cache class. |
| 14 |
* |
| 15 |
* Provides logging support to child implementations. |
| 16 |
* |
| 17 |
* @abstract |
| 18 |
*/ |
| 19 |
abstract class Mustache_Cache_AbstractCache implements Mustache_Cache |
| 20 |
{ |
| 21 |
private $logger = null; |
| 22 |
|
| 23 |
/** |
| 24 |
* Get the current logger instance. |
| 25 |
* |
| 26 |
* @return Mustache_Logger|Psr\Log\LoggerInterface |
| 27 |
*/ |
| 28 |
public function getLogger() |
| 29 |
{ |
| 30 |
return $this->logger; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Set a logger instance. |
| 35 |
* |
| 36 |
* @param Mustache_Logger|Psr\Log\LoggerInterface $logger |
| 37 |
*/ |
| 38 |
public function setLogger($logger = null) |
| 39 |
{ |
| 40 |
if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) { |
| 41 |
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.'); |
| 42 |
} |
| 43 |
|
| 44 |
$this->logger = $logger; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Add a log record if logging is enabled. |
| 49 |
* |
| 50 |
* @param string $level The logging level |
| 51 |
* @param string $message The log message |
| 52 |
* @param array $context The log context |
| 53 |
*/ |
| 54 |
protected function log($level, $message, array $context = array()) |
| 55 |
{ |
| 56 |
if (isset($this->logger)) { |
| 57 |
$this->logger->log($level, $message, $context); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|