1 | <?php |
||
23 | class Detector |
||
24 | { |
||
25 | /** |
||
26 | * @var StorageInterface |
||
27 | */ |
||
28 | private $dataProvider; |
||
29 | |||
30 | /** |
||
31 | * Get storage provider |
||
32 | * @return StorageInterface |
||
33 | */ |
||
34 | public function getDataProvider(): StorageInterface |
||
38 | |||
39 | /** |
||
40 | * Get result object |
||
41 | * @return Result Result object |
||
42 | */ |
||
43 | public function getResultObject(): Result |
||
47 | |||
48 | /** |
||
49 | * @var Result Result object |
||
50 | */ |
||
51 | private $resultObject; |
||
52 | |||
53 | /** |
||
54 | * Set data provider |
||
55 | * @param StorageInterface $dataProvider |
||
56 | */ |
||
57 | public function setDataProvider(StorageInterface $dataProvider) |
||
61 | |||
62 | /** |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function getUserAgent() |
||
69 | |||
70 | private $ua; |
||
71 | |||
72 | /** |
||
73 | * @var array |
||
74 | */ |
||
75 | private $detectors; |
||
76 | |||
77 | /** |
||
78 | * Detector constructor. |
||
79 | * @param string $dataProvider |
||
80 | * @param string $format |
||
81 | */ |
||
82 | public function __construct(string $dataProvider = '\\EndorphinStudio\\Detector\\Storage\\YamlStorage', string $format = 'yaml') |
||
100 | |||
101 | /** |
||
102 | * Analyse User Agent String |
||
103 | * @param string $ua |
||
104 | * @return Result |
||
105 | */ |
||
106 | public function analyse(string $ua = 'ua'): Result |
||
107 | { |
||
108 | $request = Request::createFromGlobals(); |
||
109 | $this->ua = $ua === 'ua' ? $request->server->get('HTTP_USER_AGENT') : $ua; |
||
110 | $this->resultObject = new Result($this->ua); |
||
111 | foreach ($this->detectors as $detectionType => $detector) { |
||
112 | $detector->detect($ua); |
||
113 | } |
||
114 | return $this->resultObject; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Get list of patterns from config |
||
119 | * @param $list |
||
120 | * @param $type |
||
121 | * @return array |
||
122 | */ |
||
123 | public function getPatternList($list, $type) |
||
127 | } |