|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EndorphinStudio\Detector\Detection; |
|
4
|
|
|
|
|
5
|
|
|
use EndorphinStudio\Detector\Data\Model; |
|
6
|
|
|
|
|
7
|
|
|
class ModelDetector extends AbstractDetection |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var string Key in config (os, device, etc.) |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $configKey = 'model'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Setup result of object |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function setupResultObject() |
|
18
|
|
|
{ |
|
19
|
|
|
$name = $this->additionalInfo['name']; |
|
20
|
|
|
if(!\array_key_exists($name, $this->config)) { |
|
21
|
|
|
return; |
|
22
|
|
|
} |
|
23
|
|
|
$patternList = $this->config[$name]; |
|
24
|
|
|
foreach ($patternList as $series => $pattern) { |
|
25
|
|
|
$pattern = sprintf('/%s/', $pattern); |
|
26
|
|
|
$result = \preg_match($pattern, $this->detector->getUserAgent(), $model); |
|
27
|
|
|
if($result) { |
|
28
|
|
|
$this->resultObject->setModel(sprintf('%s%s', $series, $model[1])); |
|
29
|
|
|
$this->resultObject->setSeries($series); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Detect method |
|
36
|
|
|
* @param array $additional Additional Info |
|
37
|
|
|
*/ |
|
38
|
|
|
public function detect(array $additional = []) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->additionalInfo = $additional; |
|
41
|
|
|
if ($this->configKey !== 'none') { |
|
42
|
|
|
$this->config = $this->detector->getPatternList($this->detector->getDataProvider()->getConfig(), $this->configKey); |
|
43
|
|
|
$this->resultObject = new Model(); |
|
44
|
|
|
} |
|
45
|
|
|
$this->setupResultObject(); |
|
46
|
|
|
if($this->resultObject->getModel()) { |
|
|
|
|
|
|
47
|
|
|
$this->detector->getResultObject()->getDevice()->setModel($this->resultObject); |
|
48
|
|
|
$this->detector->getResultObject()->getDevice()->setHasModel(true); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: