| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is part of the ramsey/uuid library |
| 4 |
* |
| 5 |
* For the full copyright and license information, please view the LICENSE |
| 6 |
* file that was distributed with this source code. |
| 7 |
* |
| 8 |
* @copyright Copyright (c) Ben Ramsey <[email protected]> |
| 9 |
* @license http://opensource.org/licenses/MIT MIT |
| 10 |
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation |
| 11 |
* @link https://packagist.org/packages/ramsey/uuid Packagist |
| 12 |
* @link https://github.com/ramsey/uuid GitHub |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace Ramsey\Uuid\Builder; |
| 16 |
|
| 17 |
use Ramsey\Uuid\Codec\CodecInterface; |
| 18 |
use Ramsey\Uuid\Converter\NumberConverterInterface; |
| 19 |
use Ramsey\Uuid\Uuid; |
| 20 |
|
| 21 |
/** |
| 22 |
* DefaultUuidBuilder is the default UUID builder for ramsey/uuid; it builds |
| 23 |
* instances of Uuid objects |
| 24 |
*/ |
| 25 |
class DefaultUuidBuilder implements UuidBuilderInterface |
| 26 |
{ |
| 27 |
/** |
| 28 |
* @var NumberConverterInterface |
| 29 |
*/ |
| 30 |
private $converter; |
| 31 |
|
| 32 |
/** |
| 33 |
* Constructs the DefaultUuidBuilder |
| 34 |
* |
| 35 |
* @param NumberConverterInterface $converter The number converter to use when constructing the Uuid |
| 36 |
*/ |
| 37 |
public function __construct(NumberConverterInterface $converter) |
| 38 |
{ |
| 39 |
$this->converter = $converter; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Builds a Uuid |
| 44 |
* |
| 45 |
* @param CodecInterface $codec The codec to use for building this Uuid |
| 46 |
* @param array $fields An array of fields from which to construct the Uuid; |
| 47 |
* see {@see \Ramsey\Uuid\UuidInterface::getFieldsHex()} for array structure. |
| 48 |
* @return Uuid |
| 49 |
*/ |
| 50 |
public function build(CodecInterface $codec, array $fields) |
| 51 |
{ |
| 52 |
return new Uuid($fields, $this->converter, $codec); |
| 53 |
} |
| 54 |
} |