Passed
Push — master ( 368ea8...00a7e0 )
by Kris
02:37 queued 01:05
created

LogParserFactory::getParser()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 9.6111
cc 5
nc 5
nop 3
1
<?php declare(strict_types=1);
2
3
/** 
4
 *  ___                      _
5
 * | _ \ __ _  _ _  ___ ___ | | ___  __ _
6
 * |  _// _` || '_|(_-</ -_)| |/ _ \/ _` |
7
 * |_|  \__,_||_|  /__/\___||_|\___/\__, |
8
 *                                  |___/
9
 * 
10
 * (c) Kristuff <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 *
15
 * @version    0.2.0
16
 * @copyright  2017-2020 Kristuff
17
 */
18
19
namespace Kristuff\Parselog;
20
21
use Kristuff\Parselog\Core\LogEntryFactoryInterface;
22
use Kristuff\Parselog\Software\SoftwareLogParser;
23
24
/**
25
 * 
26
 */
27
class LogParserFactory 
28
{
29
    const TYPE_APACHE_ACCESS    = 'apache_access';
30
    const TYPE_APACHE_ERROR     = 'apache_error';
31
    const TYPE_SYSLOG           = 'syslog';
32
    const TYPE_FAIL2BAN         = 'fail2ban';
33
34
    /** 
35
     * Gets a new LogParser instance based on given logType
36
     * 
37
     * @access public
38
     * @static
39
     * @param string                    $logType        The internal log type
40
     * @param string                    $format         The log format. Default is null
41
     * @param LogEntryFactoryInterface  $factory        The custom log entry factory. Default is null (use default factory)       
42
     * 
43
     * @return \Kristuff\Parselog\LogParser|null        
44
     */
45
    public static function getParser(string $logType, string $format = null, LogEntryFactoryInterface $factory = null): ?SoftwareLogParser 
46
    {
47
        switch ($logType){
48
49
            case self::TYPE_APACHE_ACCESS: 
50
                return new \Kristuff\Parselog\Software\ApacheAccessLogParser($format, $factory); 
51
52
            case self::TYPE_APACHE_ERROR: 
53
                return new \Kristuff\Parselog\Software\ApacheErrorLogParser($format, $factory); 
54
55
            case self::TYPE_SYSLOG: 
56
                return new \Kristuff\Parselog\Software\SyslogParser($format, $factory); 
57
58
            case self::TYPE_FAIL2BAN:
59
                return new \Kristuff\Parselog\Software\Fail2BanLogParser($format, $factory); 
60
61
        }
62
        return null;
63
    }
64
65
}