mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-16 19:09:31 +00:00
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".
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user