Files
chill-bundles/src/Bundle/ChillDocStoreBundle/Dav/Utils/LockTimeoutAnalyzer.php
Julien Fastré c9a632f3a9 Add LockTimeoutAnalyzer utility and corresponding tests
- Implemented `LockTimeoutAnalyzer` to parse timeout values from RFC-compliant strings and return `DateInterval` objects.
- Added `LockTimeoutAnalyzerTest` with data providers to validate handling of various timeout cases, including "Second" and "Infinite".
2026-04-02 14:35:20 +02:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\Dav\Utils;
use DateInterval;
class LockTimeoutAnalyzer
{
/**
* Analyzes the timeout value from the provided content string, RFC2068 string
* and return a DateInterval object representing the timeout duration.
*
* @param string $content The input string containing timeout information, as described by RFC2518, section 4.2
*
* @return \DateInterval the calculated timeout as a DateInterval object
*
* @throws \Exception if the DateInterval creation fails
*/
public function analyzeTimeout(string $content): \DateInterval
{
$types = explode(',', $content);
$firstType = trim(reset($types));
if (str_starts_with($firstType, 'Second-')) {
$seconds = (int) substr($firstType, 7);
return new \DateInterval(sprintf('PT%dS', $seconds));
}
if ('Infinite' === $firstType) {
return new \DateInterval('PT24H');
}
return new \DateInterval('PT3600S');
}
}