webauthn/src/Application/Model/RelyingPartyEntity.php

83 lines
1.9 KiB
PHP
Raw Normal View History

2022-10-24 22:24:40 +02:00
<?php
/**
2022-11-04 22:45:47 +01:00
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2022-10-24 22:24:40 +02:00
*
2022-11-04 22:45:47 +01:00
* https://www.d3data.de
2022-10-24 22:24:40 +02:00
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2022-11-04 22:45:47 +01:00
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
2022-10-24 22:24:40 +02:00
*/
declare(strict_types=1);
2022-10-31 00:11:06 +01:00
namespace D3\Webauthn\Application\Model;
2022-10-24 22:24:40 +02:00
2022-12-01 00:45:39 +01:00
use D3\TestingTools\Production\IsMockable;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Config;
2022-10-24 22:24:40 +02:00
use Webauthn\PublicKeyCredentialRpEntity;
2022-10-31 00:11:06 +01:00
class RelyingPartyEntity extends PublicKeyCredentialRpEntity
2022-10-24 22:24:40 +02:00
{
2022-12-01 00:45:39 +01:00
use IsMockable;
2022-10-31 00:11:06 +01:00
public function __construct()
2022-10-24 22:24:40 +02:00
{
$this->d3CallMockableFunction(
[
PublicKeyCredentialRpEntity::class,
2022-12-13 22:24:33 +01:00
'__construct',
],
2022-12-01 00:45:39 +01:00
[
$this->getActiveShop()->getFieldData('oxname'),
2022-12-13 22:24:33 +01:00
$this->getRPShopUrl(),
2022-12-01 00:45:39 +01:00
]
);
}
/**
* @return bool
*/
public function hasConfiguredShopUrl(): bool
{
return (bool) strlen(trim((string) $this->getConfiguredShopUrl()));
}
/**
* @return mixed
*/
public function getConfiguredShopUrl()
{
return $this->d3GetMockableRegistryObject(Config::class)->getConfigParam('d3webauthn_diffshopurl');
2022-12-01 00:45:39 +01:00
}
/**
* @return string
*/
public function getShopUrlByHost(): string
{
return preg_replace('/(^www\.)(.*)/mi', '$2', $_SERVER['HTTP_HOST']);
}
/**
* @return string|null
*/
public function getRPShopUrl(): ?string
{
return $this->hasConfiguredShopUrl() ?
trim($this->getConfiguredShopUrl()) :
$this->getShopUrlByHost();
}
/**
* @return Shop
*/
public function getActiveShop(): Shop
{
return $this->d3GetMockableRegistryObject(Config::class)->getActiveShop();
2022-10-24 22:24:40 +02:00
}
2022-12-13 22:24:33 +01:00
}