1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-23 01:26:11 +02:00

Merge branch '1.x'

This commit is contained in:
Jordi Boggiano
2018-11-04 18:40:32 +01:00
27 changed files with 654 additions and 24 deletions

View File

@@ -11,12 +11,14 @@
namespace Monolog\Processor;
use Monolog\ResettableInterface;
/**
* Adds a unique identifier into records
*
* @author Simon Mönch <sm@webfactory.de>
*/
class UidProcessor implements ProcessorInterface
class UidProcessor implements ProcessorInterface, ResettableInterface
{
private $uid;
@@ -26,7 +28,7 @@ class UidProcessor implements ProcessorInterface
throw new \InvalidArgumentException('The uid length must be an integer between 1 and 32');
}
$this->uid = substr(bin2hex(random_bytes((int) ceil($length / 2))), 0, $length);
$this->uid = $this->generateUid($length);
}
public function __invoke(array $record): array
@@ -43,4 +45,14 @@ class UidProcessor implements ProcessorInterface
{
return $this->uid;
}
public function reset()
{
$this->uid = $this->generateUid(strlen($this->uid));
}
private function generateUid($length)
{
return substr(bin2hex(random_bytes((int) ceil($length / 2))), 0, $length);
}
}