Blame view

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