Pressroom template verwijderd, website naar root van repo

This commit is contained in:
2020-03-22 15:30:52 +01:00
parent 2cb6a77425
commit f3d1c41e91
7620 changed files with 0 additions and 186900 deletions

View File

@@ -0,0 +1,55 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Codec;
use Ramsey\Uuid\UuidInterface;
/**
* CodecInterface represents a UUID coder-decoder
*/
interface CodecInterface
{
/**
* Encodes a UuidInterface as a string representation of a UUID
*
* @param UuidInterface $uuid
* @return string Hexadecimal string representation of a UUID
*/
public function encode(UuidInterface $uuid);
/**
* Encodes a UuidInterface as a binary representation of a UUID
*
* @param UuidInterface $uuid
* @return string Binary string representation of a UUID
*/
public function encodeBinary(UuidInterface $uuid);
/**
* Decodes a string representation of a UUID into a UuidInterface object instance
*
* @param string $encodedUuid
* @return UuidInterface
*/
public function decode($encodedUuid);
/**
* Decodes a binary representation of a UUID into a UuidInterface object instance
*
* @param string $bytes
* @return UuidInterface
*/
public function decodeBytes($bytes);
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Codec;
use Ramsey\Uuid\UuidInterface;
/**
* GuidStringCodec encodes and decodes globally unique identifiers (GUID)
*
* @link https://en.wikipedia.org/wiki/Globally_unique_identifier
*/
class GuidStringCodec extends StringCodec
{
/**
* Encodes a UuidInterface as a string representation of a GUID
*
* @param UuidInterface $uuid
* @return string Hexadecimal string representation of a GUID
*/
public function encode(UuidInterface $uuid)
{
$components = array_values($uuid->getFieldsHex());
// Swap byte-order on the first three fields
$this->swapFields($components);
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$components
);
}
/**
* Encodes a UuidInterface as a binary representation of a GUID
*
* @param UuidInterface $uuid
* @return string Binary string representation of a GUID
*/
public function encodeBinary(UuidInterface $uuid)
{
$components = array_values($uuid->getFieldsHex());
return hex2bin(implode('', $components));
}
/**
* Decodes a string representation of a GUID into a UuidInterface object instance
*
* @param string $encodedUuid
* @return UuidInterface
*/
public function decode($encodedUuid)
{
$components = $this->extractComponents($encodedUuid);
$this->swapFields($components);
return $this->getBuilder()->build($this, $this->getFields($components));
}
/**
* Decodes a binary representation of a GUID into a UuidInterface object instance
*
* @param string $bytes
* @return UuidInterface
*/
public function decodeBytes($bytes)
{
// Specifically call parent::decode to preserve correct byte order
return parent::decode(bin2hex($bytes));
}
/**
* Swaps fields to support GUID byte order
*
* @param array $components An array of UUID components (the UUID exploded on its dashes)
* @return void
*/
protected function swapFields(array &$components)
{
$hex = unpack('H*', pack('L', hexdec($components[0])));
$components[0] = $hex[1];
$hex = unpack('H*', pack('S', hexdec($components[1])));
$components[1] = $hex[1];
$hex = unpack('H*', pack('S', hexdec($components[2])));
$components[2] = $hex[1];
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Codec;
use InvalidArgumentException;
use Ramsey\Uuid\UuidInterface;
/**
* OrderedTimeCodec optimizes the bytes to increment UUIDs when time goes by, to improve database INSERTs.
* The string value will be unchanged from StringCodec. Only works for UUID type 1.
*/
class OrderedTimeCodec extends StringCodec
{
/**
* Encodes a UuidInterface as an optimized binary representation of a UUID
*
* @param UuidInterface $uuid
* @return string Binary string representation of a UUID
*/
public function encodeBinary(UuidInterface $uuid)
{
$fields = $uuid->getFieldsHex();
$optimized = [
$fields['time_hi_and_version'],
$fields['time_mid'],
$fields['time_low'],
$fields['clock_seq_hi_and_reserved'],
$fields['clock_seq_low'],
$fields['node'],
];
return hex2bin(implode('', $optimized));
}
/**
* Decodes an optimized binary representation of a UUID into a UuidInterface object instance
*
* @param string $bytes
* @return UuidInterface
*/
public function decodeBytes($bytes)
{
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
$hex = unpack('H*', $bytes)[1];
// Rearrange the fields to their original order
$hex = substr($hex, 8, 4) . substr($hex, 12, 4) . substr($hex, 4, 4) . substr($hex, 0, 4) . substr($hex, 16);
return $this->decode($hex);
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Codec;
use InvalidArgumentException;
use Ramsey\Uuid\Builder\UuidBuilderInterface;
use Ramsey\Uuid\Exception\InvalidUuidStringException;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
/**
* StringCodec encodes and decodes RFC 4122 UUIDs
*
* @link http://tools.ietf.org/html/rfc4122
*/
class StringCodec implements CodecInterface
{
/**
* @var UuidBuilderInterface
*/
private $builder;
/**
* Constructs a StringCodec for use encoding and decoding UUIDs
*
* @param UuidBuilderInterface $builder The UUID builder to use when encoding UUIDs
*/
public function __construct(UuidBuilderInterface $builder)
{
$this->builder = $builder;
}
/**
* Encodes a UuidInterface as a string representation of a UUID
*
* @param UuidInterface $uuid
* @return string Hexadecimal string representation of a UUID
*/
public function encode(UuidInterface $uuid)
{
$fields = array_values($uuid->getFieldsHex());
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$fields
);
}
/**
* Encodes a UuidInterface as a binary representation of a UUID
*
* @param UuidInterface $uuid
* @return string Binary string representation of a UUID
*/
public function encodeBinary(UuidInterface $uuid)
{
return hex2bin($uuid->getHex());
}
/**
* Decodes a string representation of a UUID into a UuidInterface object instance
*
* @param string $encodedUuid
* @return UuidInterface
*/
public function decode($encodedUuid)
{
$components = $this->extractComponents($encodedUuid);
$fields = $this->getFields($components);
return $this->builder->build($this, $fields);
}
/**
* Decodes a binary representation of a UUID into a UuidInterface object instance
*
* @param string $bytes
* @return UuidInterface
*/
public function decodeBytes($bytes)
{
if (strlen($bytes) !== 16) {
throw new InvalidArgumentException('$bytes string should contain 16 characters.');
}
$hexUuid = unpack('H*', $bytes);
return $this->decode($hexUuid[1]);
}
/**
* Returns the UUID builder
*
* @return UuidBuilderInterface
*/
protected function getBuilder()
{
return $this->builder;
}
/**
* Returns an array of UUID components (the UUID exploded on its dashes)
*
* @param string $encodedUuid
* @return array
*/
protected function extractComponents($encodedUuid)
{
$nameParsed = str_replace(array(
'urn:',
'uuid:',
'{',
'}',
'-'
), '', $encodedUuid);
// We have stripped out the dashes and are breaking up the string using
// substr(). In this way, we can accept a full hex value that doesn't
// contain dashes.
$components = array(
substr($nameParsed, 0, 8),
substr($nameParsed, 8, 4),
substr($nameParsed, 12, 4),
substr($nameParsed, 16, 4),
substr($nameParsed, 20)
);
$nameParsed = implode('-', $components);
if (!Uuid::isValid($nameParsed)) {
throw new InvalidUuidStringException('Invalid UUID string: ' . $encodedUuid);
}
return $components;
}
/**
* Returns the fields that make up this UUID
*
* @see \Ramsey\Uuid\UuidInterface::getFieldsHex()
* @param array $components
* @return array
*/
protected function getFields(array $components)
{
return array(
'time_low' => str_pad($components[0], 8, '0', STR_PAD_LEFT),
'time_mid' => str_pad($components[1], 4, '0', STR_PAD_LEFT),
'time_hi_and_version' => str_pad($components[2], 4, '0', STR_PAD_LEFT),
'clock_seq_hi_and_reserved' => str_pad(substr($components[3], 0, 2), 2, '0', STR_PAD_LEFT),
'clock_seq_low' => str_pad(substr($components[3], 2), 2, '0', STR_PAD_LEFT),
'node' => str_pad($components[4], 12, '0', STR_PAD_LEFT)
);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Codec;
use Ramsey\Uuid\UuidInterface;
/**
* TimestampLastCombCodec encodes and decodes COMB UUIDs which have the timestamp as the first 48 bits.
* To be used with MySQL, PostgreSQL, Oracle.
*/
class TimestampFirstCombCodec extends StringCodec
{
/**
* Encodes a UuidInterface as a string representation of a timestamp first COMB UUID
*
* @param UuidInterface $uuid
*
* @return string Hexadecimal string representation of a GUID
*/
public function encode(UuidInterface $uuid)
{
$sixPieceComponents = array_values($uuid->getFieldsHex());
$this->swapTimestampAndRandomBits($sixPieceComponents);
return vsprintf(
'%08s-%04s-%04s-%02s%02s-%012s',
$sixPieceComponents
);
}
/**
* Encodes a UuidInterface as a binary representation of timestamp first COMB UUID
*
* @param UuidInterface $uuid
*
* @return string Binary string representation of timestamp first COMB UUID
*/
public function encodeBinary(UuidInterface $uuid)
{
$stringEncoding = $this->encode($uuid);
return hex2bin(str_replace('-', '', $stringEncoding));
}
/**
* Decodes a string representation of timestamp first COMB UUID into a UuidInterface object instance
*
* @param string $encodedUuid
*
* @return UuidInterface
*/
public function decode($encodedUuid)
{
$fivePieceComponents = $this->extractComponents($encodedUuid);
$this->swapTimestampAndRandomBits($fivePieceComponents);
return $this->getBuilder()->build($this, $this->getFields($fivePieceComponents));
}
/**
* Decodes a binary representation of timestamp first COMB UUID into a UuidInterface object instance
*
* @param string $bytes
*
* @return UuidInterface
*/
public function decodeBytes($bytes)
{
return $this->decode(bin2hex($bytes));
}
/**
* Swaps the first 48 bits with the last 48 bits
*
* @param array $components An array of UUID components (the UUID exploded on its dashes)
*
* @return void
*/
protected function swapTimestampAndRandomBits(array &$components)
{
$last48Bits = $components[4];
if (count($components) == 6) {
$last48Bits = $components[5];
$components[5] = $components[0] . $components[1];
} else {
$components[4] = $components[0] . $components[1];
}
$components[0] = substr($last48Bits, 0, 8);
$components[1] = substr($last48Bits, 8, 4);
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Codec;
/**
* TimestampLastCombCodec encodes and decodes COMB UUIDs which have the timestamp as the last 48 bits.
* To be used with MSSQL.
*/
class TimestampLastCombCodec extends StringCodec
{
}