37 lines
1005 B
PHP
37 lines
1005 B
PHP
<?php
|
|
|
|
class OCPPFrameRouter
|
|
{
|
|
public function route(array $routes, string $chargePointId, int $evseId = 1, int $connectorId = 1, int $defaultTarget = 0): int
|
|
{
|
|
foreach ($routes as $route) {
|
|
if (!is_array($route)) {
|
|
continue;
|
|
}
|
|
if ((string)($route['ChargePointId'] ?? '') !== $chargePointId) {
|
|
continue;
|
|
}
|
|
$routeEvse = (int)($route['EVSEId'] ?? 1);
|
|
$routeConnector = (int)($route['ConnectorId'] ?? 1);
|
|
if ($routeEvse === $evseId && $routeConnector === $connectorId) {
|
|
return (int)($route['TargetInstance'] ?? 0);
|
|
}
|
|
}
|
|
|
|
return $defaultTarget;
|
|
}
|
|
|
|
public function extractChargePointId(string $path, string $fallback = ''): string
|
|
{
|
|
$path = trim($path, '/');
|
|
if ($path === '') {
|
|
return $fallback;
|
|
}
|
|
|
|
$parts = explode('/', $path);
|
|
return (string)end($parts);
|
|
}
|
|
}
|
|
|
|
?>
|