| 1 |
<?php |
| 2 |
/* |
| 3 |
* This file is part of Raven. |
| 4 |
* |
| 5 |
* (c) Sentry Team |
| 6 |
* |
| 7 |
* For the full copyright and license information, please view the LICENSE |
| 8 |
* file that was distributed with this source code. |
| 9 |
*/ |
| 10 |
|
| 11 |
class Raven_TransactionStack |
| 12 |
{ |
| 13 |
public function __construct() |
| 14 |
{ |
| 15 |
$this->stack = array(); |
| 16 |
} |
| 17 |
|
| 18 |
public function clear() |
| 19 |
{ |
| 20 |
$this->stack = array(); |
| 21 |
} |
| 22 |
|
| 23 |
public function peek() |
| 24 |
{ |
| 25 |
$len = count($this->stack); |
| 26 |
if ($len === 0) { |
| 27 |
return null; |
| 28 |
} |
| 29 |
return $this->stack[$len - 1]; |
| 30 |
} |
| 31 |
|
| 32 |
public function push($context) |
| 33 |
{ |
| 34 |
$this->stack[] = $context; |
| 35 |
} |
| 36 |
|
| 37 |
/** @noinspection PhpInconsistentReturnPointsInspection |
| 38 |
* @param string|null $context |
| 39 |
* @return mixed |
| 40 |
*/ |
| 41 |
public function pop($context = null) |
| 42 |
{ |
| 43 |
if (!$context) { |
| 44 |
return array_pop($this->stack); |
| 45 |
} |
| 46 |
while (!empty($this->stack)) { |
| 47 |
if (array_pop($this->stack) === $context) { |
| 48 |
return $context; |
| 49 |
} |
| 50 |
} |
| 51 |
// @codeCoverageIgnoreStart |
| 52 |
} |
| 53 |
// @codeCoverageIgnoreEnd |
| 54 |
} |
| 55 |
|