-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
96 changed files
with
842 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
use Psr\Http\Message\MessageInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\SimpleCache\InvalidArgumentException; | ||
use UaBrowserType\Unknown; | ||
use UaDeviceType\Type; | ||
use UaLoader\BrowserLoaderInterface; | ||
use UaLoader\Data\ClientDataInterface; | ||
|
@@ -37,18 +36,18 @@ | |
use UaRequest\Header\HeaderInterface; | ||
use UaRequest\RequestBuilderInterface; | ||
use UaResult\Browser\Browser; | ||
use UaResult\Browser\BrowserInterface; | ||
use UaResult\Company\Company; | ||
use UaResult\Device\Device; | ||
use UaResult\Device\DeviceInterface; | ||
use UaResult\Device\Display; | ||
use UaResult\Engine\Engine; | ||
use UaResult\Engine\EngineInterface; | ||
use UaResult\Os\Os; | ||
use UaResult\Os\OsInterface; | ||
use UnexpectedValueException; | ||
|
||
use function array_change_key_case; | ||
use function array_filter; | ||
use function array_map; | ||
use function assert; | ||
use function explode; | ||
use function is_array; | ||
|
@@ -61,6 +60,8 @@ | |
use function str_contains; | ||
use function trim; | ||
|
||
use const CASE_LOWER; | ||
|
||
final readonly class Detector implements DetectorInterface | ||
{ | ||
/** | ||
|
@@ -115,7 +116,7 @@ public function getBrowser(array | GenericRequestInterface | MessageInterface | | |
} | ||
|
||
/** | ||
* @return array{headers: array<non-empty-string, non-empty-string>, device: array{architecture: string|null, deviceName: string|null, marketingName: string|null, manufacturer: string|null, brand: string|null, dualOrientation: bool|null, simCount: int|null, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, type: string|null, ismobile: bool, istv: bool, bits: int|null}, os: array{name: string|null, marketingName: string|null, version: string|null, manufacturer: string|null}, client: array{name: string|null, version: string|null, manufacturer: string|null, type: string|null, isbot: bool}, engine: array{name: string|null, version: string|null, manufacturer: string|null}} | ||
* @return array{headers: array<non-empty-string, string>, device: array{architecture: string|null, deviceName: string|null, marketingName: string|null, manufacturer: string|null, brand: string|null, dualOrientation: bool|null, simCount: int|null, display: array{width: int|null, height: int|null, touch: bool|null, size: float|null}, type: string|null, ismobile: bool, istv: bool, bits: int|null}, os: array{name: string|null, marketingName: string|null, version: string|null, manufacturer: string|null}, client: array{name: string|null, version: string|null, manufacturer: string|null, type: string|null, isbot: bool}, engine: array{name: string|null, version: string|null, manufacturer: string|null}} | ||
* | ||
* @throws UnexpectedValueException | ||
*/ | ||
|
@@ -127,11 +128,9 @@ private function parse(GenericRequestInterface $request): array | |
/* detect device */ | ||
$deviceIsMobile = $this->getDeviceIsMobile(filteredHeaders: $filteredHeaders); | ||
|
||
$deviceData = $this->getDeviceData( | ||
filteredHeaders: $filteredHeaders, | ||
); | ||
$deviceData = $this->getDeviceData(filteredHeaders: $filteredHeaders); | ||
|
||
$device = $deviceData->getDevice(); | ||
$device = $deviceData->getDevice(); | ||
$deviceMarketingName = $device->getMarketingName(); | ||
|
||
/* detect platform */ | ||
|
@@ -164,9 +163,7 @@ private function parse(GenericRequestInterface $request): array | |
} | ||
|
||
/* detect client */ | ||
$clientData = $this->getClientData( | ||
filteredHeaders: $filteredHeaders, | ||
); | ||
$clientData = $this->getClientData(filteredHeaders: $filteredHeaders); | ||
|
||
$client = $clientData->getClient(); | ||
|
||
|
@@ -186,9 +183,7 @@ private function parse(GenericRequestInterface $request): array | |
|
||
return [ | ||
'headers' => array_map( | ||
callback: function(HeaderInterface $header): string { | ||
return $header->getValue(); | ||
}, | ||
callback: static fn (HeaderInterface $header): string => $header->getValue(), | ||
array: array_change_key_case($request->getHeaders(), CASE_LOWER), | ||
Check warning on line 187 in src/Detector.php GitHub Actions / UnitTests / Code Coverage with PHPUnit (ubuntu-24.04, 8.3, lowest)
Check warning on line 187 in src/Detector.php GitHub Actions / UnitTests / Code Coverage with PHPUnit (ubuntu-24.04, 8.3, lowest)
|
||
), | ||
'device' => [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the browser-detector package. | ||
* | ||
* Copyright (c) 2012-2025, Thomas Mueller <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace BrowserDetector\Loader\Data; | ||
|
||
use Override; | ||
use UaLoader\Data\ClientDataInterface; | ||
use UaResult\Browser\BrowserInterface; | ||
|
||
class ClientData implements ClientDataInterface | ||
final readonly class ClientData implements ClientDataInterface | ||
{ | ||
private BrowserInterface $client; | ||
private string|null $engine; | ||
|
||
/** | ||
* @param BrowserInterface $client | ||
* @param string|null $engine | ||
* @throws void | ||
*/ | ||
public function __construct(BrowserInterface $client, ?string $engine) | ||
/** @throws void */ | ||
public function __construct(private BrowserInterface $client, private string | null $engine) | ||
{ | ||
$this->client = $client; | ||
$this->engine = $engine; | ||
} | ||
|
||
/** | ||
* @return BrowserInterface | ||
* @throws void | ||
*/ | ||
/** @throws void */ | ||
#[Override] | ||
public function getClient(): BrowserInterface | ||
{ | ||
return $this->client; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @throws void | ||
*/ | ||
public function getEngine(): string|null | ||
/** @throws void */ | ||
#[Override] | ||
public function getEngine(): string | null | ||
{ | ||
return $this->engine; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the browser-detector package. | ||
* | ||
* Copyright (c) 2012-2025, Thomas Mueller <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace BrowserDetector\Loader\Data; | ||
|
||
use Override; | ||
use UaLoader\Data\DeviceDataInterface; | ||
use UaResult\Device\DeviceInterface; | ||
|
||
class DeviceData implements DeviceDataInterface | ||
final readonly class DeviceData implements DeviceDataInterface | ||
{ | ||
private DeviceInterface $device; | ||
private string|null $os; | ||
|
||
/** | ||
* @param DeviceInterface $device | ||
* @param string|null $os | ||
* @throws void | ||
*/ | ||
public function __construct(DeviceInterface $device, ?string $os) | ||
/** @throws void */ | ||
public function __construct(private DeviceInterface $device, private string | null $os) | ||
{ | ||
$this->device = $device; | ||
$this->os = $os; | ||
} | ||
|
||
/** | ||
* @return DeviceInterface | ||
* @throws void | ||
*/ | ||
/** @throws void */ | ||
#[Override] | ||
public function getDevice(): DeviceInterface | ||
{ | ||
return $this->device; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @throws void | ||
*/ | ||
public function getOs(): string|null | ||
/** @throws void */ | ||
#[Override] | ||
public function getOs(): string | null | ||
{ | ||
return $this->os; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the mimmi20/ua-generic-request package. | ||
* This file is part of the browser-detector package. | ||
* | ||
* Copyright (c) 2015-2025, Thomas Mueller <[email protected]> | ||
* Copyright (c) 2012-2025, Thomas Mueller <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
|
@@ -19,10 +19,10 @@ | |
|
||
use function preg_match; | ||
|
||
final class BaiduFlyflow implements DeviceCodeInterface | ||
final readonly class BaiduFlyflow implements DeviceCodeInterface | ||
{ | ||
/** @throws void */ | ||
public function __construct(private readonly DeviceParserInterface $deviceParser) | ||
public function __construct(private DeviceParserInterface $deviceParser) | ||
{ | ||
// nothing to do | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the browser-detector package. | ||
* | ||
* Copyright (c) 2012-2025, Thomas Mueller <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace BrowserDetector\Parser\Header; | ||
|
||
use Override; | ||
use UaParser\ClientCodeInterface; | ||
|
||
use function array_key_first; | ||
use function mb_strtolower; | ||
use function str_contains; | ||
|
||
final class CrawledByClientCode implements ClientCodeInterface | ||
{ | ||
use SortTrait; | ||
|
||
/** @throws void */ | ||
#[Override] | ||
public function hasClientCode(string $value): bool | ||
{ | ||
$list = $this->sort($value); | ||
|
||
if ($list === null || $list === []) { | ||
return false; | ||
} | ||
|
||
$key = array_key_first($list); | ||
$code = mb_strtolower($key); | ||
|
||
return !str_contains($code, 'brand') && $code !== 'chromium'; | ||
} | ||
|
||
/** | ||
* @return non-empty-string|null | ||
* | ||
* @throws void | ||
* | ||
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter | ||
*/ | ||
#[Override] | ||
public function getClientCode(string $value): string | null | ||
{ | ||
return null; | ||
} | ||
} |
Oops, something went wrong.