77 * For the full copyright and license information, please view the LICENSE
88 * file that was distributed with this source code.
99 */
10+
1011namespace arabcoders \errors ;
1112
1213use arabcoders \errors \Interfaces \ErrorInterface ;
@@ -262,6 +263,7 @@ public function handleError( ErrorMapInterface $error ) : ErrorInterface
262263 ->setTrace ( $ this ->tracer ->setIgnore ( [ __FILE__ ] )->process ()->getTrace () )
263264 ->setMessage ( $ this ->formatter ->formatError ( $ error ) )
264265 ->setError ( $ error )
266+ ->setId ( $ this ->createUUID () )
265267 ->getInstance ();
266268
267269 if ( array_key_exists ( $ error ->getNumber (), $ this ->listener ) )
@@ -292,6 +294,7 @@ public function handleException( \Throwable $exception ) : ErrorInterface
292294 ->setStructured ( $ this ->getStructured ()->setException ( $ exception )->process ()->getStructured () )
293295 ->setTrace ( $ this ->tracer ->setContext ( $ exception ->getTrace () )->setIgnore ( [ __FILE__ ] )->process ()->getTrace () )
294296 ->setMessage ( $ this ->formatter ->formatException ( $ exception ) )
297+ ->setId ( $ this ->createUUID () )
295298 ->getInstance ();
296299
297300 $ name = get_class ( $ exception );
@@ -551,4 +554,34 @@ protected function setupDefault() : ErrorInterface
551554 return $ this ;
552555 }
553556
557+ /**
558+ * Creates Universal Unique Identifier For Error.
559+ *
560+ * Implements UUIDv4.
561+ *
562+ * @return string
563+ */
564+ protected function createUUID () : string
565+ {
566+ $ version = 4 ;
567+
568+ $ hash = bin2hex ( random_bytes ( 16 ) );
569+
570+ return sprintf (
571+ '%08s-%04s-%04x-%04x-%12s ' ,
572+ // 32 bits for "time_low"
573+ substr ( $ hash , 0 , 8 ),
574+ // 16 bits for "time_mid"
575+ substr ( $ hash , 8 , 4 ),
576+ // 16 bits for "time_hi_and_version",
577+ // four most significant bits holds version number
578+ ( hexdec ( substr ( $ hash , 12 , 4 ) ) & 0x0fff ) | $ version << 12 ,
579+ // 16 bits, 8 bits for "clk_seq_hi_res",
580+ // 8 bits for "clk_seq_low",
581+ // two most significant bits holds zero and one for variant DCE1.1
582+ ( hexdec ( substr ( $ hash , 16 , 4 ) ) & 0x3fff ) | 0x8000 ,
583+ // 48 bits for "node"
584+ substr ( $ hash , 20 , 12 )
585+ );
586+ }
554587}
0 commit comments