PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.9.2
Independent Analytics – WordPress Analytics Plugin v2.9.2
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / vendor / matomo / device-detector / Parser / Client / MobileApp.php
MobileApp.php
110 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Device Detector - The Universal Device Detection library for parsing User Agents
5 *
6 * @link https://matomo.org
7 *
8 * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
9 */
10 declare (strict_types=1);
11 namespace IAWPSCOPED\DeviceDetector\Parser\Client;
12
13 use IAWPSCOPED\DeviceDetector\Cache\CacheInterface;
14 use IAWPSCOPED\DeviceDetector\ClientHints;
15 use IAWPSCOPED\DeviceDetector\Parser\Client\Hints\AppHints;
16 use IAWPSCOPED\DeviceDetector\Yaml\ParserInterface as YamlParser;
17 /**
18 * Class MobileApp
19 *
20 * Client parser for mobile app detection
21 * @internal
22 */
23 class MobileApp extends AbstractClientParser
24 {
25 /**
26 * @var AppHints
27 */
28 private $appHints;
29 /**
30 * @var string
31 */
32 protected $fixtureFile = 'regexes/client/mobile_apps.yml';
33 /**
34 * @var string
35 */
36 protected $parserName = 'mobile app';
37 /**
38 * MobileApp constructor.
39 *
40 * @param string $ua
41 * @param ClientHints|null $clientHints
42 */
43 public function __construct(string $ua = '', ?ClientHints $clientHints = null)
44 {
45 $this->appHints = new AppHints($ua, $clientHints);
46 parent::__construct($ua, $clientHints);
47 }
48 /**
49 * Sets the client hints to parse
50 *
51 * @param ?ClientHints $clientHints client hints
52 */
53 public function setClientHints(?ClientHints $clientHints) : void
54 {
55 parent::setClientHints($clientHints);
56 $this->appHints->setClientHints($clientHints);
57 }
58 /**
59 * Sets the user agent to parse
60 *
61 * @param string $ua user agent
62 */
63 public function setUserAgent(string $ua) : void
64 {
65 parent::setUserAgent($ua);
66 $this->appHints->setUserAgent($ua);
67 }
68 /**
69 * Sets the Cache class
70 *
71 * @param CacheInterface $cache
72 */
73 public function setCache(CacheInterface $cache) : void
74 {
75 parent::setCache($cache);
76 $this->appHints->setCache($cache);
77 }
78 /**
79 * Sets the YamlParser class
80 *
81 * @param YamlParser $yamlParser
82 */
83 public function setYamlParser(YamlParser $yamlParser) : void
84 {
85 parent::setYamlParser($yamlParser);
86 $this->appHints->setYamlParser($this->getYamlParser());
87 }
88 /**
89 * Parses the current UA and checks whether it contains any client information
90 * See parent::parse() for more details.
91 *
92 * @return array|null
93 */
94 public function parse() : ?array
95 {
96 $result = parent::parse();
97 $name = $result['name'] ?? '';
98 $version = $result['version'] ?? '';
99 $appHash = $this->appHints->parse();
100 if (null !== $appHash && $appHash['name'] !== $name) {
101 $name = $appHash['name'];
102 $version = '';
103 }
104 if (empty($name)) {
105 return null;
106 }
107 return ['type' => $this->parserName, 'name' => $name, 'version' => $version];
108 }
109 }
110