-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDurationTrait.php
More file actions
41 lines (35 loc) · 944 Bytes
/
DurationTrait.php
File metadata and controls
41 lines (35 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace SimpleSAML\XML\Assert;
use InvalidArgumentException;
/**
* @package simplesamlphp/xml-common
*/
trait DurationTrait
{
private static string $duration_regex = '/^
([-+]?)
P
(?!$)
(?:(?<years>\d+(?:[\.\,]\d+)?)Y)?
(?:(?<months>\d+(?:[\.\,]\d+)?)M)?
(?:(?<weeks>\d+(?:[\.\,]\d+)?)W)?
(?:(?<days>\d+(?:[\.\,]\d+)?)D)?
(T(?=\d)(?:(?<hours>\d+(?:[\.\,]\d+)?)H)?
(?:(?<minutes>\d+(?:[\.\,]\d+)?)M)?
(?:(?<seconds>\d+(?:[\.\,]\d+)?)S)?)?
$/Dx';
/**
* @param string $value
* @param string $message
*/
protected static function validDuration(string $value, string $message = ''): void
{
parent::regex(
$value,
self::$duration_regex,
$message ?: '%s is not a valid xs:duration',
InvalidArgumentException::class,
);
}
}