PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 All 169 releases
woocommerce-pos / vendor / ramsey / uuid / src / Nonstandard / UuidBuilder.php

UuidBuilder.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.21, at vendor/ramsey/uuid/src/Nonstandard/UuidBuilder.php

89 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
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