ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
UidProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Processor;
13 
15 
22 {
23  private $uid;
24 
25  public function __construct($length = 7)
26  {
27  if (!is_int($length) || $length > 32 || $length < 1) {
28  throw new \InvalidArgumentException('The uid length must be an integer between 1 and 32');
29  }
30 
31 
32  $this->uid = $this->generateUid($length);
33  }
34 
35  public function __invoke(array $record)
36  {
37  $record['extra']['uid'] = $this->uid;
38 
39  return $record;
40  }
41 
45  public function getUid()
46  {
47  return $this->uid;
48  }
49 
50  public function reset()
51  {
52  $this->uid = $this->generateUid(strlen($this->uid));
53  }
54 
55  private function generateUid($length)
56  {
57  return substr(hash('md5', uniqid('', true)), 0, $length);
58  }
59 }
Handler or Processor implementing this interface will be reset when Logger::reset() is called...
Adds a unique identifier into records.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
An optional interface to allow labelling Monolog processors.