PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 3.0.0
ShareThis Dashboard for Google Analytics v3.0.0
3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.0.0 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.3.0 3.3.1
googleanalytics / lib / analytics-admin / vendor / ramsey / uuid / src / Nonstandard / UuidBuilder.php
googleanalytics / lib / analytics-admin / vendor / ramsey / uuid / src / Nonstandard Last commit date
Fields.php 3 years ago Uuid.php 3 years ago UuidBuilder.php 3 years ago UuidV6.php 3 years ago
UuidBuilder.php
89 lines
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\Nonstandard;
16
17 use Ramsey\Uuid\Builder\UuidBuilderInterface;
18 use Ramsey\Uuid\Codec\CodecInterface;
19 use Ramsey\Uuid\Converter\NumberConverterInterface;
20 use Ramsey\Uuid\Converter\TimeConverterInterface;
21 use Ramsey\Uuid\Exception\UnableToBuildUuidException;
22 use Ramsey\Uuid\UuidInterface;
23 use Throwable;
24
25 /**
26 * Nonstandard\UuidBuilder builds instances of Nonstandard\Uuid
27 *
28 * @psalm-immutable
29 */
30 class UuidBuilder implements UuidBuilderInterface
31 {
32 /**
33 * @var NumberConverterInterface
34 */
35 private $numberConverter;
36
37 /**
38 * @var TimeConverterInterface
39 */
40 private $timeConverter;
41
42 /**
43 * @param NumberConverterInterface $numberConverter The number converter to
44 * use when constructing the Nonstandard\Uuid
45 * @param TimeConverterInterface $timeConverter The time converter to use
46 * for converting timestamps extracted from a UUID to Unix timestamps
47 */
48 public function __construct(
49 NumberConverterInterface $numberConverter,
50 TimeConverterInterface $timeConverter
51 ) {
52 $this->numberConverter = $numberConverter;
53 $this->timeConverter = $timeConverter;
54 }
55
56 /**
57 * Builds and returns a Nonstandard\Uuid
58 *
59 * @param CodecInterface $codec The codec to use for building this instance
60 * @param string $bytes The byte string from which to construct a UUID
61 *
62 * @return Uuid The Nonstandard\UuidBuilder returns an instance of
63 * Nonstandard\Uuid
64 *
65 * @psalm-pure
66 */
67 public function build(CodecInterface $codec, string $bytes): UuidInterface
68 {
69 try {
70 return new Uuid(
71 $this->buildFields($bytes),
72 $this->numberConverter,
73 $codec,
74 $this->timeConverter
75 );
76 } catch (Throwable $e) {
77 throw new UnableToBuildUuidException($e->getMessage(), (int) $e->getCode(), $e);
78 }
79 }
80
81 /**
82 * Proxy method to allow injecting a mock, for testing
83 */
84 protected function buildFields(string $bytes): Fields
85 {
86 return new Fields($bytes);
87 }
88 }
89