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 / Guid / GuidBuilder.php

GuidBuilder.php in Media Cloud Sync 1.2.5, at includes/sdk/google/ramsey/uuid/src/Guid/GuidBuilder.php

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