mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
impl. request stat collection
This commit is contained in:
parent
4e4405ade1
commit
3493ac10b1
|
|
@ -145,6 +145,41 @@ final class HttpHeader extends HeaderAbstract
|
|||
return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
|
||||
}
|
||||
|
||||
public function getReferer() : string
|
||||
{
|
||||
return $_SERVER['HTTP_REFERER'] ?? '';
|
||||
}
|
||||
|
||||
public function getRequestTime() : int
|
||||
{
|
||||
return (int) ($_SERVER['REQUEST_TIME'] ?? \time());
|
||||
}
|
||||
|
||||
public function getRequestIp() : string
|
||||
{
|
||||
return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? '';
|
||||
}
|
||||
|
||||
public function getBrowserName() {
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
if (\strpos($userAgent, 'Opera') !== false || \strpos($userAgent, 'OPR/') !== false) {
|
||||
return 'Opera';
|
||||
} elseif (\strpos($userAgent, 'Edge') !== false) {
|
||||
return 'Microsoft Edge';
|
||||
} elseif (\strpos($userAgent, 'Chrome') !== false) {
|
||||
return 'Google Chrome';
|
||||
} elseif (\strpos($userAgent, 'Safari') !== false) {
|
||||
return 'Safari';
|
||||
} elseif (\strpos($userAgent, 'Firefox') !== false) {
|
||||
return 'Mozilla Firefox';
|
||||
} elseif (\strpos($userAgent, 'MSIE') !== false || \strpos($userAgent, 'Trident/7') !== false) {
|
||||
return 'Internet Explorer';
|
||||
}
|
||||
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all headers for apache and nginx
|
||||
*
|
||||
|
|
|
|||
80
Message/Http/ImpressionStat.php
Normal file
80
Message/Http/ImpressionStat.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Jingga
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package phpOMS\Message\Statistic
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Message\Statistic;
|
||||
|
||||
use phpOMS\Localization\ISO3166TwoEnum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
|
||||
/**
|
||||
* Request statistic class.
|
||||
*
|
||||
* @package phpOMS\Message\Statistic
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ImpressionStat
|
||||
{
|
||||
public string $address = '';
|
||||
|
||||
public string $language = ISO639x1Enum::_EN;
|
||||
|
||||
public string $country = ISO3166TwoEnum::_XXX;
|
||||
|
||||
public int $datetime = 0;
|
||||
|
||||
public string $browser = '';
|
||||
|
||||
public string $host = '';
|
||||
|
||||
public string $path = '';
|
||||
|
||||
public string $uri = '';
|
||||
|
||||
public string $referer = '';
|
||||
|
||||
public string $userAgent = '';
|
||||
|
||||
public function __construct(HttpRequest $request)
|
||||
{
|
||||
$this->language = $request->header->l11n->language;
|
||||
$this->country = $request->header->l11n->country;
|
||||
$this->uri = \substr($request->uri->uri, 0, 255);
|
||||
$this->host = $request->uri->host;
|
||||
$this->path = \substr($request->uri->path, 0, 255);
|
||||
$this->address = $request->header->getRequestIp();
|
||||
$this->datetime = $request->header->getRequestTime();
|
||||
$this->referer = \substr($request->header->getReferer(), 0, 255);
|
||||
$this->userAgent = $request->header->getBrowserName();
|
||||
}
|
||||
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'address' => $this->address,
|
||||
'date' => \date('d-m-y', $this->datetime),
|
||||
'hour' => \date('H', $this->datetime),
|
||||
'host' => $this->host,
|
||||
'path' => $this->path,
|
||||
'uri' => $this->uri,
|
||||
'agent' => $this->userAgent,
|
||||
'language' => $this->language,
|
||||
'country' => $this->country,
|
||||
'referer' => $this->referer,
|
||||
'datetime' => $this->datetime,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ final class HttpUri implements UriInterface
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $path;
|
||||
public string $path;
|
||||
|
||||
/**
|
||||
* Uri path with offset.
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ namespace phpOMS\Uri;
|
|||
* @property array $fragments Fragments
|
||||
* @property string $user User
|
||||
* @property string $pass Password
|
||||
* @property string $uri Uri
|
||||
* @property string $path Path
|
||||
*
|
||||
* @package phpOMS\Uri
|
||||
* @license OMS License 2.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user