TransactionStack.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. class Raven_TransactionStack
  11. {
  12. public function __construct()
  13. {
  14. $this->stack = array();
  15. }
  16. public function clear()
  17. {
  18. $this->stack = array();
  19. }
  20. public function peek()
  21. {
  22. $len = count($this->stack);
  23. if ($len === 0) {
  24. return null;
  25. }
  26. return $this->stack[$len - 1];
  27. }
  28. public function push($context)
  29. {
  30. $this->stack[] = $context;
  31. }
  32. /** @noinspection PhpInconsistentReturnPointsInspection
  33. * @param string|null $context
  34. * @return mixed
  35. */
  36. public function pop($context = null)
  37. {
  38. if (!$context) {
  39. return array_pop($this->stack);
  40. }
  41. while (!empty($this->stack)) {
  42. if (array_pop($this->stack) === $context) {
  43. return $context;
  44. }
  45. }
  46. // @codeCoverageIgnoreStart
  47. }
  48. // @codeCoverageIgnoreEnd
  49. }