Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| TransactionIdentifier | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | namespace Wikimedia\Rdbms; |
| 7 | |
| 8 | use Stringable; |
| 9 | |
| 10 | /** |
| 11 | * Class used for token representing identifiers for atomic transactions from IDatabase instances |
| 12 | * |
| 13 | * @ingroup Database |
| 14 | * @internal |
| 15 | */ |
| 16 | class TransactionIdentifier implements Stringable { |
| 17 | /** @var string Application-side ID of the active transaction or an empty string otherwise */ |
| 18 | private $id = ''; |
| 19 | |
| 20 | public function __construct() { |
| 21 | static $nextId; |
| 22 | $nextId = ( $nextId !== null ? $nextId++ : mt_rand() ) % 0xffff; |
| 23 | $this->id = sprintf( '%06x', mt_rand( 0, 0xffffff ) ) . sprintf( '%04x', $nextId ); |
| 24 | } |
| 25 | |
| 26 | public function __toString() { |
| 27 | return $this->id; |
| 28 | } |
| 29 | } |