[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/db/ -> log_wrapper_migrator_output_handler.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\db;
  15  
  16  use phpbb\user;
  17  
  18  class log_wrapper_migrator_output_handler implements migrator_output_handler_interface
  19  {
  20      /**
  21       * User object.
  22       *
  23       * @var user
  24       */
  25      protected $user;
  26  
  27      /**
  28       * A migrator output handler
  29       *
  30       * @var migrator_output_handler_interface
  31       */
  32      protected $migrator;
  33  
  34      /**
  35       * Log file handle
  36       * @var resource
  37       */
  38      protected $file_handle = false;
  39  
  40      /**
  41       * Constructor
  42       *
  43       * @param user $user    User object
  44       * @param migrator_output_handler_interface $migrator Migrator output handler
  45       * @param string $log_file    File to log to
  46       */
  47  	public function __construct(user $user, migrator_output_handler_interface $migrator, $log_file)
  48      {
  49          $this->user = $user;
  50          $this->migrator = $migrator;
  51          $this->file_open($log_file);
  52      }
  53  
  54      /**
  55       * Open file for logging
  56       *
  57       * @param string $file File to open
  58       */
  59  	protected function file_open($file)
  60      {
  61          if (phpbb_is_writable(dirname($file)))
  62          {
  63              $this->file_handle = fopen($file, 'w');
  64          }
  65          else
  66          {
  67              throw new \RuntimeException('Unable to write to migrator log file');
  68          }
  69      }
  70  
  71      /**
  72       * {@inheritdoc}
  73       */
  74  	public function write($message, $verbosity)
  75      {
  76          $this->migrator->write($message, $verbosity);
  77  
  78          if ($this->file_handle !== false)
  79          {
  80              $translated_message = call_user_func_array(array($this->user, 'lang'), $message) . "\n";
  81  
  82              if ($verbosity <= migrator_output_handler_interface::VERBOSITY_NORMAL)
  83              {
  84                  $translated_message = '[INFO] ' . $translated_message;
  85              }
  86              else
  87              {
  88                  $translated_message = '[DEBUG] ' . $translated_message;
  89              }
  90  
  91              fwrite($this->file_handle, $translated_message);
  92              fflush($this->file_handle);
  93          }
  94      }
  95  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1