PluginProbe
Media Cloud Sync / 1.2.5
Media Cloud Sync v1.2.5
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.2.5, at includes/sdk/google/ramsey/uuid/src/Nonstandard/UuidBuilder.php

75 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\Ramsey\Uuid\Nonstandard;
14
15 use Dudlewebs\WPMCS\Ramsey\Uuid\Builder\UuidBuilderInterface;
16 use Dudlewebs\WPMCS\Ramsey\Uuid\Codec\CodecInterface;
17 use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\NumberConverterInterface;
18 use Dudlewebs\WPMCS\Ramsey\Uuid\Converter\TimeConverterInterface;
19 use Dudlewebs\WPMCS\Ramsey\Uuid\Exception\UnableToBuildUuidException;
20 use Dudlewebs\WPMCS\Ramsey\Uuid\UuidInterface;
21 use Throwable;
22 /**
23 * Nonstandard\UuidBuilder builds instances of Nonstandard\Uuid
24 *
25 * @psalm-immutable
26 */
27 class UuidBuilder implements UuidBuilderInterface
28 {
29 /**
30 * @var NumberConverterInterface
31 */
32 private $numberConverter;
33 /**
34 * @var TimeConverterInterface
35 */
36 private $timeConverter;
37 /**
38 * @param NumberConverterInterface $numberConverter The number converter to
39 * use when constructing the Nonstandard\Uuid
40 * @param TimeConverterInterface $timeConverter The time converter to use
41 * for converting timestamps extracted from a UUID to Unix timestamps
42 */
43 public function __construct(NumberConverterInterface $numberConverter, TimeConverterInterface $timeConverter)
44 {
45 $this->numberConverter = $numberConverter;
46 $this->timeConverter = $timeConverter;
47 }
48 /**
49 * Builds and returns a Nonstandard\Uuid
50 *
51 * @param CodecInterface $codec The codec to use for building this instance
52 * @param string $bytes The byte string from which to construct a UUID
53 *
54 * @return Uuid The Nonstandard\UuidBuilder returns an instance of
55 * Nonstandard\Uuid
56 *
57 * @psalm-pure
58 */
59 public function build(CodecInterface $codec, string $bytes): UuidInterface
60 {
61 try {
62 return new Uuid($this->buildFields($bytes), $this->numberConverter, $codec, $this->timeConverter);
63 } catch (Throwable $e) {
64 throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e);
65 }
66 }
67 /**
68 * Proxy method to allow injecting a mock, for testing
69 */
70 protected function buildFields(string $bytes): Fields
71 {
72 return new Fields($bytes);
73 }
74 }
75