Files
chill-bundles/src/Bundle/ChillDocStoreBundle/Dav/Utils/LockTokenParser.php
Julien Fastré a1d72cefff Add LockTokenParser::parseIfCondition method and corresponding tests
- Implemented the `parseIfCondition` method in `LockTokenParser` to extract lock tokens from `if` headers.
- Added `LockTokenParserTest` with multiple test cases using data providers to validate parsing logic, including scenarios with no headers, resource URIs, and "not" conditions.
2026-04-03 18:01:04 +02:00

59 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 Symfony\Component\HttpFoundation\Request;
final readonly class LockTokenParser
{
public function parseLockToken(Request $request): ?string
{
$token = $request->headers->get('lock-token');
if (null === $token) {
return null;
}
if (str_starts_with($token, '"')) {
$token = substr($token, 1, -1);
}
if (str_starts_with($token, '<')) {
$token = substr($token, 1);
}
if (str_ends_with($token, '>')) {
$token = substr($token, 0, -1);
}
if (str_ends_with($token, '"')) {
$token = substr($token, 1, -1);
}
return $token;
}
public function parseIfCondition(Request $request): ?string
{
$if = $request->headers->get('if');
if (null === $if) {
return null;
}
if (preg_match('/\((?:not\s+)?<([^>]+)>/i', $if, $matches)) {
return $matches[1];
}
return null;
}
}