mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-09 06:23:45 +00:00
- 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.
59 lines
1.2 KiB
PHP
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;
|
|
}
|
|
}
|