Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / simple_sitemap / src / Logger.php
1 <?php
2
3 namespace Drupal\simple_sitemap;
4
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6 use Drupal\Core\Session\AccountProxyInterface;
7 use Psr\Log\LoggerInterface;
8
9 /**
10  * Class Logger
11  * @package Drupal\simple_sitemap
12  */
13 class Logger {
14
15   use StringTranslationTrait;
16
17   /*
18    * Can be debug/info/notice/warning/error.
19    */
20   const LOG_SEVERITY_LEVEL_DEFAULT = 'notice';
21
22   /*
23    * Can be status/warning/error.
24    */
25   const DISPLAY_MESSAGE_TYPE_DEFAULT = 'status';
26
27   /**
28    * @var \Psr\Log\LoggerInterface
29    */
30   protected $logger;
31
32   /**
33    * @var \Drupal\Core\Session\AccountProxyInterface
34    */
35   protected $currentUser;
36
37   /**
38    * @var string
39    */
40   protected $message = '';
41
42   /**
43    * @var array
44    */
45   protected $substitutions = [];
46
47   /**
48    * Logger constructor.
49    *
50    * @param $logger
51    * @param $current_user
52    */
53   public function __construct(
54     LoggerInterface $logger,
55     AccountProxyInterface $current_user
56   ) {
57     $this->logger = $logger;
58     $this->currentUser = $current_user;
59   }
60
61   /**
62    * @param $message
63    * @param array $substitutions
64    * @return $this
65    */
66   public function m($message, $substitutions = []) {
67     $this->message = $message;
68     $this->substitutions = $substitutions;
69     return $this;
70   }
71
72   /**
73    * @param string $logSeverityLevel
74    * @return $this
75    */
76   public function log($logSeverityLevel = self::LOG_SEVERITY_LEVEL_DEFAULT) {
77     $this->logger->$logSeverityLevel(strtr($this->message, $this->substitutions));
78     return $this;
79   }
80
81   /**
82    * @param string $displayMessageType
83    * @param string $permission
84    * @return $this
85    */
86   public function display($displayMessageType = self::DISPLAY_MESSAGE_TYPE_DEFAULT, $permission = '') {
87     if (empty($permission) || $this->currentUser->hasPermission($permission)) {
88       drupal_set_message($this->t($this->message, $this->substitutions), $displayMessageType);
89     }
90     return $this;
91   }
92 }