123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace WhichBrowser\Analyser;
- use WhichBrowser\Constants;
- use WhichBrowser\Model\Version;
- trait Corrections
- {
- private function &applyCorrections()
- {
- if (isset($this->data->browser->name) && isset($this->data->browser->using)) {
- $this->hideBrowserBasedOnUsing();
- }
- if (isset($this->data->browser->name) && isset($this->data->os->name)) {
- $this->hideBrowserBasedOnOperatingSystem();
- }
- if (isset($this->data->browser->name) && $this->data->device->type == Constants\DeviceType::TELEVISION) {
- $this->hideBrowserOnDeviceTypeTelevision();
- }
- if (isset($this->data->browser->name) && $this->data->device->type == Constants\DeviceType::GAMING) {
- $this->hideBrowserOnDeviceTypeGaming();
- }
- if ($this->data->device->type == Constants\DeviceType::TELEVISION) {
- $this->hideOsOnDeviceTypeTelevision();
- }
- if (isset($this->data->browser->name) && isset($this->data->engine->name)) {
- $this->fixMidoriEngineName();
- }
- if (isset($this->data->browser->name) && isset($this->data->engine->name)) {
- $this->fixNineSkyEngineName();
- }
- if (isset($this->data->browser->name) && isset($this->data->browser->family)) {
- $this->hideFamilyIfEqualToBrowser();
- }
- return $this;
- }
- private function hideFamilyIfEqualToBrowser()
- {
- if ($this->data->browser->name == $this->data->browser->family->name) {
- unset($this->data->browser->family);
- }
- }
- private function fixMidoriEngineName()
- {
- if ($this->data->browser->name == 'Midori' && $this->data->engine->name != 'Webkit') {
- $this->data->engine->name = 'Webkit';
- $this->data->engine->version = null;
- }
- }
- private function fixNineSkyEngineName()
- {
- if ($this->data->browser->name == 'NineSky' && $this->data->engine->name != 'Webkit') {
- $this->data->engine->name = 'Webkit';
- $this->data->engine->version = null;
- }
- }
- private function hideBrowserBasedOnUsing()
- {
- if ($this->data->browser->name == 'Chrome') {
- if ($this->data->browser->isUsing('Electron') || $this->data->browser->isUsing('Qt')) {
- unset($this->data->browser->name);
- unset($this->data->browser->version);
- }
- }
- }
- private function hideBrowserBasedOnOperatingSystem()
- {
- if ($this->data->os->name == 'Series60' && $this->data->browser->name == 'Internet Explorer') {
- $this->data->browser->reset();
- $this->data->engine->reset();
- }
- if ($this->data->os->name == 'Series80' && $this->data->browser->name == 'Internet Explorer') {
- $this->data->browser->reset();
- $this->data->engine->reset();
- }
- if ($this->data->os->name == 'Lindows' && $this->data->browser->name == 'Internet Explorer') {
- $this->data->browser->reset();
- $this->data->engine->reset();
- }
- if ($this->data->os->name == 'Tizen' && $this->data->browser->name == 'Chrome') {
- $this->data->browser->reset([
- 'family' => isset($this->data->browser->family) ? $this->data->browser->family : null
- ]);
- }
- if ($this->data->os->name == 'Ubuntu Touch' && $this->data->browser->name == 'Chromium') {
- $this->data->browser->reset([
- 'family' => isset($this->data->browser->family) ? $this->data->browser->family : null
- ]);
- }
- }
- private function hideBrowserOnDeviceTypeGaming()
- {
- if (isset($this->data->device->model) && $this->data->device->model == 'Playstation 2' && $this->data->browser->name == 'Internet Explorer') {
- $this->data->browser->reset();
- }
- }
- private function hideBrowserOnDeviceTypeTelevision()
- {
- switch ($this->data->browser->name) {
- case 'Firefox':
- if (!$this->data->isOs('Firefox OS')) {
- unset($this->data->browser->name);
- unset($this->data->browser->version);
- }
- break;
- case 'Internet Explorer':
- $valid = false;
- if (isset($this->data->device->model) && in_array($this->data->device->model, [ 'WebTV' ])) {
- $valid = true;
- }
- if (!$valid) {
- unset($this->data->browser->name);
- unset($this->data->browser->version);
- }
- break;
- case 'Chrome':
- case 'Chromium':
- $valid = false;
- if (isset($this->data->os->name) && in_array($this->data->os->name, [ 'Google TV', 'Android' ])) {
- $valid = true;
- }
- if (isset($this->data->device->model) && in_array($this->data->device->model, [ 'Chromecast' ])) {
- $valid = true;
- }
- if (!$valid) {
- unset($this->data->browser->name);
- unset($this->data->browser->version);
- }
- break;
- }
- }
- private function hideOsOnDeviceTypeTelevision()
- {
- if (isset($this->data->os->name) && !in_array($this->data->os->name, [ 'Aliyun OS', 'Tizen', 'Android', 'Android TV', 'FireOS', 'Google TV', 'Firefox OS', 'OpenTV', 'webOS' ])) {
- $this->data->os->reset();
- }
- }
- }
|