flashii/eeprom
Archived
3
0
Fork 1
This repository has been archived on 2025-03-27. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
eeprom/src/EEPROMAccessControlHandler.php

30 lines
841 B
PHP

<?php
namespace EEPROM;
use Index\Http\HttpUri;
use Index\Http\Routing\HandlerContext;
use Index\Http\Routing\Routes\RouteInfo;
use Index\Http\Routing\AccessControl\{AccessControl,SimpleAccessControlHandler};
class EEPROMAccessControlHandler extends SimpleAccessControlHandler {
public function __construct(
private array $origins,
) {}
#[\Override]
public function checkAccess(
HandlerContext $context,
AccessControl $accessControl,
HttpUri $origin,
?RouteInfo $routeInfo = null,
): string|bool {
if($accessControl->credentials) {
$host = '.' . $origin->host;
foreach($this->origins as $allowOrigin)
if(str_ends_with($host, '.' . $allowOrigin))
return (string)$origin;
}
return true;
}
}