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

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

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