1<?php
2
3/*
4 * This file is part of MailSo.
5 *
6 * (c) 2014 Usenko Timur
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace MailSo\Log\Drivers;
13
14/**
15 * @category MailSo
16 * @package Log
17 * @subpackage Drivers
18 */
19class File extends \MailSo\Log\Driver
20{
21	/**
22	 * @var string
23	 */
24	private $sLoggerFileName;
25
26	/**
27	 * @access protected
28	 *
29	 * @param string $sLoggerFileName
30	 * @param string $sNewLine = "\r\n"
31	 */
32	protected function __construct($sLoggerFileName, $sNewLine = "\r\n")
33	{
34		parent::__construct();
35
36		$this->sLoggerFileName = $sLoggerFileName;
37		$this->sNewLine = $sNewLine;
38	}
39
40	/**
41	 * @param string $sLoggerFileName
42	 */
43	public function SetLoggerFileName($sLoggerFileName)
44	{
45		$this->sLoggerFileName = $sLoggerFileName;
46	}
47
48	/**
49	 * @param string $sLoggerFileName
50	 * @param string $sNewLine = "\r\n"
51	 *
52	 * @return \MailSo\Log\Drivers\File
53	 */
54	public static function NewInstance($sLoggerFileName, $sNewLine = "\r\n")
55	{
56		return new self($sLoggerFileName, $sNewLine);
57	}
58
59	/**
60	 * @param string|array $mDesc
61	 *
62	 * @return bool
63	 */
64	protected function writeImplementation($mDesc)
65	{
66		return $this->writeToLogFile($mDesc);
67	}
68
69	/**
70	 * @return bool
71	 */
72	protected function clearImplementation()
73	{
74		return \unlink($this->sLoggerFileName);
75	}
76
77	/**
78	 * @param string|array $mDesc
79	 *
80	 * @return bool
81	 */
82	private function writeToLogFile($mDesc)
83	{
84		if (\is_array($mDesc))
85		{
86			$mDesc = \implode($this->sNewLine, $mDesc);
87		}
88
89		return \error_log($mDesc.$this->sNewLine, 3, $this->sLoggerFileName);
90	}
91}
92