Completed
Push — 3.0.0 ( 5cf6f2...40ecb2 )
by Serhii
02:23
created

DetectorRule::setTargetValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * @author Sergey Nehaenko <[email protected]>
4
 * @license GPL
5
 * @copyright Sergey Nehaenko &copy 2016
6
 * @version 3.0.0
7
 * @project browser-detector
8
 */
9
10
namespace EndorphinStudio\Detector;
11
12
13
class DetectorRule
14
{
15
    /**
16
     * @return string
17
     */
18
    public function getObjectType()
19
    {
20
        return $this->ObjectType;
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function getObjectProperty()
27
    {
28
        return $this->ObjectProperty;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getObjectPropertyValue()
35
    {
36
        return $this->ObjectPropertyValue;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getTargetType()
43
    {
44
        return $this->TargetType;
45
    }
46
47
    /**
48
     * @return boolean
49
     */
50
    public function isTargetValue()
51
    {
52
        return $this->TargetValue;
53
    }
54
55
    /**
56
     * @param string $ObjectType
57
     */
58
    public function setObjectType($ObjectType)
59
    {
60
        $this->ObjectType = $ObjectType;
61
    }
62
63
    /**
64
     * @param boolean $TargetValue
65
     */
66
    public function setTargetValue($TargetValue)
67
    {
68
        $this->TargetValue = $TargetValue;
69
    }
70
71
    /**
72
     * @param string $TargetType
73
     */
74
    public function setTargetType($TargetType)
75
    {
76
        $this->TargetType = $TargetType;
77
    }
78
79
    /**
80
     * @param string $ObjectPropertyValue
81
     */
82
    public function setObjectPropertyValue($ObjectPropertyValue)
83
    {
84
        $this->ObjectPropertyValue = $ObjectPropertyValue;
85
    }
86
87
    /**
88
     * @param string $ObjectProperty
89
     */
90
    public function setObjectProperty($ObjectProperty)
91
    {
92
        $this->ObjectProperty = $ObjectProperty;
93
    }
94
    /** @var string EndorphinStudio\Detector\DetectorResult object name */
95
    private $ObjectType;
96
    /** @var string EndorphinStudio\Detector\DetectorResult property name */
97
    private $ObjectProperty;
98
    /** @var string EndorphinStudio\Detector\DetectorResult property value */
99
    private $ObjectPropertyValue;
100
    /** @var string EndorphinStudio\Detector\DetectorResult property name */
101
    private $TargetType;
102
    /** @var boolean boolean value */
103
    private $TargetValue;
104
105
    public function __construct(\SimpleXMLElement $xmlData)
106
    {
107
        if($xmlData !== null)
108
        {
109
            foreach ($xmlData->children() as $child)
110
            {
111
                $name = $child->getName();
112
                $val = $child->__toString();
113
                $this->$name = $val;
114
            }
115
        }
116
    }
117
118
    /**
119
     * @return array Array of EndorphinStudio\Detector\DetectorRule objects
120
     */
121
    public static function loadRulesFromFile()
122
    {
123
        $path = str_replace('src','data',__DIR__).'/rules/';
124
        $files = scandir($path);
125
        $rules = array();
126
        foreach($files as $file)
127
        {
128
            if($file != '.' && $file != '..')
129
            {
130
                $xmlObj = simplexml_load_file($path.$file);
131
                foreach($xmlObj->children() as $rule)
132
                {
133
                    $rules[] = new self($rule);
134
                }
135
            }
136
        }
137
138
        return $rules;
139
    }
140
}
141