2021-08-25 04:29:26 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-25 04:29:26 +09:00
|
|
|
/*
|
|
|
|
* This file is part of the ActivityPhp package.
|
|
|
|
*
|
|
|
|
* Copyright (c) landrok at github.com/landrok
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please see
|
|
|
|
* <https://github.com/landrok/activitypub/blob/master/LICENSE>.
|
|
|
|
*/
|
|
|
|
|
2021-10-05 01:00:58 +09:00
|
|
|
namespace Plugin\ActivityPub\Util\Type\Validator;
|
2021-08-25 04:29:26 +09:00
|
|
|
|
|
|
|
use Exception;
|
2021-10-05 01:00:58 +09:00
|
|
|
use Plugin\ActivityPub\Util\Type\Core\ObjectType;
|
|
|
|
use Plugin\ActivityPub\Util\Type\Util;
|
|
|
|
use Plugin\ActivityPub\Util\Type\ValidatorInterface;
|
2021-08-25 04:29:26 +09:00
|
|
|
|
|
|
|
/**
|
2021-10-05 01:00:58 +09:00
|
|
|
* \Plugin\ActivityPub\Util\Type\Validator\DurationValidator is a dedicated
|
2021-08-25 04:29:26 +09:00
|
|
|
* validator for duration attribute.
|
|
|
|
*/
|
|
|
|
class DurationValidator implements ValidatorInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Validate an DURATION attribute value
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function validate(mixed $value, mixed $container): bool
|
|
|
|
{
|
|
|
|
// Validate that container has an ObjectType type
|
|
|
|
Util::subclassOf($container, ObjectType::class, true);
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
if (\is_string($value)) {
|
2021-08-25 04:29:26 +09:00
|
|
|
// MUST be an XML 8601 Duration formatted string
|
|
|
|
return Util::isDuration($value, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|