PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / ramsey / uuid / src / Nonstandard / UuidBuilder.php

UuidBuilder.php in Media Cloud Sync 1.4.2, at includes/sdk/google/ramsey/uuid/src/Nonstandard/UuidBuilder.php

68 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 <[email protected]>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Nonstandard;
14
15 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Builder\UuidBuilderInterface;
16 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Codec\CodecInterface;
17 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\NumberConverterInterface;
18 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Converter\TimeConverterInterface;
19 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\Exception\UnableToBuildUuidException;
20 use Dudlewebs\WPMCS\GCP\Ramsey\Uuid\UuidInterface;
21 use Throwable;
22 /**
23 * Nonstandard\UuidBuilder builds instances of Nonstandard\Uuid
24 *
25 * @immutable
26 */
27 class UuidBuilder implements UuidBuilderInterface
28 {
29 /**
30 * @param NumberConverterInterface $numberConverter The number converter to use when constructing the Nonstandard\Uuid
31 * @param TimeConverterInterface $timeConverter The time converter to use for converting timestamps extracted from a
32 * UUID to Unix timestamps
33 */
34 public function __construct(private NumberConverterInterface $numberConverter, private TimeConverterInterface $timeConverter)
35 {
36 }
37 /**
38 * Builds and returns a Nonstandard\Uuid
39 *
40 * @param CodecInterface $codec The codec to use for building this instance
41 * @param string $bytes The byte string from which to construct a UUID
42 *
43 * @return Uuid The Nonstandard\UuidBuilder returns an instance of Nonstandard\Uuid
44 *
45 * @pure
46 */
47 public function build(CodecInterface $codec, string $bytes) : UuidInterface
48 {
49 try {
50 /** @phpstan-ignore possiblyImpure.new */
51 return new Uuid($this->buildFields($bytes), $this->numberConverter, $codec, $this->timeConverter);
52 } catch (Throwable $e) {
53 /** @phpstan-ignore possiblyImpure.methodCall, possiblyImpure.methodCall */
54 throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e);
55 }
56 }
57 /**
58 * Proxy method to allow injecting a mock for testing
59 *
60 * @pure
61 */
62 protected function buildFields(string $bytes) : Fields
63 {
64 /** @phpstan-ignore possiblyImpure.new */
65 return new Fields($bytes);
66 }
67 }
68