singleloginsystem/app/Services/Keka/KekaUrlBuilder.php
= c4e2cfc4bb Feat: Modularize Keka HR integration with services
- Introduced `KekaAccessGuard`, `KekaConfigResolver`, `KekaIntegrationService`, `KekaTokenService`, and `KekaUrlBuilder` to streamline Keka HR functionality.
- Refactored `KekaController` to delegate key operations to modular services, improving maintainability.
- Updated dashboard UI to ensure alignment with the new service-based architecture.
- Enhanced error handling, logging, and code reusability for Keka integration workflows.
2026-06-12 11:55:12 +00:00

60 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\Keka;
class KekaUrlBuilder
{
private const DEFAULT_HOST = 'login.keka.com';
public function buildExternalLoginUrl(string $configuredUrl, string $provider): string
{
$parsed = parse_url($configuredUrl);
$host = $parsed['host'] ?? self::DEFAULT_HOST;
$query = [];
if (isset($parsed['query'])) {
parse_str($parsed['query'], $query);
}
$companyId = $query['companyId'] ?? $query['companyid'] ?? null;
if (! $companyId && self::DEFAULT_HOST !== $host) {
$parts = explode('.', $host);
if (count($parts) >= 2) {
$companyId = $parts[0];
}
}
$buildQuery = [
'provider' => $provider,
];
// if ($companyId) {
// $buildQuery['companyId'] = $companyId;
// }
$queryString = http_build_query($buildQuery);
return 'https://'.self::DEFAULT_HOST."/Account/ExternalLogin?{$queryString}";
}
public function buildCallbackUrl(string $configuredUrl, string $callbackPath): string
{
$parsed = parse_url($configuredUrl);
$host = $parsed['host'] ?? self::DEFAULT_HOST;
if (self::DEFAULT_HOST !== $host) {
$parts = explode('.', $host);
if (count($parts) >= 2 && 'keka' === $parts[1]) {
$host = self::DEFAULT_HOST;
}
}
$scheme = $parsed['scheme'] ?? 'https';
return "{$scheme}://{$host}/".mb_ltrim($callbackPath, '/');
}
}