]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/monolog/monolog/src/Monolog/Processor/UidProcessor.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / monolog / monolog / src / Monolog / Processor / UidProcessor.php
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
14 /**
15  * Adds a unique identifier into records
16  *
17  * @author Simon Mönch <sm@webfactory.de>
18  */
19 class UidProcessor
20 {
21     private $uid;
22
23     public function __construct($length = 7)
24     {
25         if (!is_int($length) || $length > 32 || $length < 1) {
26             throw new \InvalidArgumentException('The uid length must be an integer between 1 and 32');
27         }
28
29         $this->uid = substr(hash('md5', uniqid('', true)), 0, $length);
30     }
31
32     public function __invoke(array $record)
33     {
34         $record['extra']['uid'] = $this->uid;
35
36         return $record;
37     }
38
39     /**
40      * @return string
41      */
42     public function getUid()
43     {
44         return $this->uid;
45     }
46 }