Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/**
4
 * This file is part of the ramsey/uuid library
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
10
 * @license http://opensource.org/licenses/MIT MIT
11
 */
12
 
13
declare(strict_types=1);
14
 
15
namespace Ramsey\Uuid\Rfc4122;
16
 
17
use Ramsey\Uuid\Uuid;
18
 
19
/**
20
 * Provides common functionality for handling the version, as defined by RFC 4122
21
 *
22
 * @psalm-immutable
23
 */
24
trait VersionTrait
25
{
26
    /**
27
     * Returns the version
28
     */
29
    abstract public function getVersion(): ?int;
30
 
31
    /**
32
     * Returns true if these fields represent a max UUID
33
     */
34
    abstract public function isMax(): bool;
35
 
36
    /**
37
     * Returns true if these fields represent a nil UUID
38
     */
39
    abstract public function isNil(): bool;
40
 
41
    /**
42
     * Returns true if the version matches one of those defined by RFC 4122
43
     *
44
     * @return bool True if the UUID version is valid, false otherwise
45
     */
46
    private function isCorrectVersion(): bool
47
    {
48
        if ($this->isNil() || $this->isMax()) {
49
            return true;
50
        }
51
 
52
        return match ($this->getVersion()) {
53
            Uuid::UUID_TYPE_TIME, Uuid::UUID_TYPE_DCE_SECURITY,
54
            Uuid::UUID_TYPE_HASH_MD5, Uuid::UUID_TYPE_RANDOM,
55
            Uuid::UUID_TYPE_HASH_SHA1, Uuid::UUID_TYPE_REORDERED_TIME,
56
            Uuid::UUID_TYPE_UNIX_TIME, Uuid::UUID_TYPE_CUSTOM => true,
57
            default => false,
58
        };
59
    }
60
}