Your IP : 3.138.156.155


Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/local/components/online_paid/fsk/
Upload File :
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/local/components/online_paid/fsk/LogController.php

<?php

namespace OnlinePaid;

use CComponentUtil;

/**
 * Class LogController
 * @package OnlinePaid
 */
class LogController
{
    /**
     * Выводить в STDOUT сообщения
     * @var bool
     */
    private $show;

    /**
     * true = выводить в HTML, false=выводить в plain text
     * @var bool
     */
    private $showhtml;

    /**
     * записывать в plain в logfile
     * @var bool
     */
    private $write;

    /**
     * this .parameters.php
     * @var array|bool
     */
    private $config = array();

    /**
     * LogController constructor.
     * @param bool $show
     * @param bool $showhtml
     * @param bool $write
     */
    public function __construct($show = false, $showhtml = false, $write = true)
    {
        $this->config = CComponentUtil::GetComponentProps('online_paid:fsk')['PARAMETERS']['LOG'];

        $this->show = $show;
        $this->showhtml = $showhtml;

        try {
            $this->write = $write;
            $this->flog = fopen($_SERVER['DOCUMENT_ROOT'] . $this->config['file'], 'a');
        } catch (\Exception $e) {
            trigger_error('Cant open logfile=' . $_SERVER['DOCUMENT_ROOT'] . $this->config['file'] . ' message=' . $e->getMessage(), E_USER_WARNING);
        }
    }

    /**
     * @param $log
     */
    public function log($log)
    {
        $log_filename = $_SERVER['DOCUMENT_ROOT'] . $this->config['file'];
        $file = $log_filename;
        $fp = fopen($file, "a");
        fwrite($fp, $log);
        fclose($fp);
    }
}