PharInvocation.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace TYPO3\PharStreamWrapper\Resolver;
  3. /*
  4. * This file is part of the TYPO3 project.
  5. *
  6. * It is free software; you can redistribute it and/or modify it under the terms
  7. * of the MIT License (MIT). For the full copyright and license information,
  8. * please read the LICENSE file that was distributed with this source code.
  9. *
  10. * The TYPO3 project - inspiring people to share!
  11. */
  12. use TYPO3\PharStreamWrapper\Exception;
  13. class PharInvocation
  14. {
  15. /**
  16. * @var string
  17. */
  18. private $baseName;
  19. /**
  20. * @var string
  21. */
  22. private $alias;
  23. /**
  24. * @var bool
  25. * @see \TYPO3\PharStreamWrapper\PharStreamWrapper::collectInvocation()
  26. */
  27. private $confirmed = false;
  28. /**
  29. * Arbitrary variables to be used by interceptors as registry
  30. * (e.g. in order to avoid duplicate processing and assertions)
  31. *
  32. * @var array
  33. */
  34. private $variables;
  35. /**
  36. * @param string $baseName
  37. * @param string $alias
  38. */
  39. public function __construct($baseName, $alias = '')
  40. {
  41. if ($baseName === '') {
  42. throw new Exception(
  43. 'Base-name cannot be empty',
  44. 1551283689
  45. );
  46. }
  47. $this->baseName = $baseName;
  48. $this->alias = $alias;
  49. }
  50. /**
  51. * @return string
  52. */
  53. public function __toString()
  54. {
  55. return $this->baseName;
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function getBaseName()
  61. {
  62. return $this->baseName;
  63. }
  64. /**
  65. * @return null|string
  66. */
  67. public function getAlias()
  68. {
  69. return $this->alias;
  70. }
  71. /**
  72. * @return bool
  73. */
  74. public function isConfirmed()
  75. {
  76. return $this->confirmed;
  77. }
  78. public function confirm()
  79. {
  80. $this->confirmed = true;
  81. }
  82. /**
  83. * @param string $name
  84. * @return mixed|null
  85. */
  86. public function getVariable($name)
  87. {
  88. if (!isset($this->variables[$name])) {
  89. return null;
  90. }
  91. return $this->variables[$name];
  92. }
  93. /**
  94. * @param string $name
  95. * @param mixed $value
  96. */
  97. public function setVariable($name, $value)
  98. {
  99. $this->variables[$name] = $value;
  100. }
  101. /**
  102. * @param PharInvocation $other
  103. * @return bool
  104. */
  105. public function equals(PharInvocation $other)
  106. {
  107. return $other->baseName === $this->baseName
  108. && $other->alias === $this->alias;
  109. }
  110. }