1
0

GenericEventWrapper.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\EventDispatcher;
  26. use Psr\Log\LoggerInterface;
  27. use Symfony\Component\EventDispatcher\GenericEvent;
  28. class GenericEventWrapper extends GenericEvent {
  29. private LoggerInterface $logger;
  30. /** @var GenericEvent */
  31. private $event;
  32. /** @var string */
  33. private $eventName;
  34. /** @var bool */
  35. private $deprecationNoticeLogged = false;
  36. public function __construct(LoggerInterface $logger, string $eventName, ?GenericEvent $event) {
  37. parent::__construct($eventName);
  38. $this->logger = $logger;
  39. $this->event = $event;
  40. $this->eventName = $eventName;
  41. }
  42. private function log() {
  43. if ($this->deprecationNoticeLogged) {
  44. return;
  45. }
  46. $class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
  47. $this->logger->debug(
  48. 'Deprecated event type for {name}: {class} is used',
  49. [ 'name' => $this->eventName, 'class' => $class]
  50. );
  51. $this->deprecationNoticeLogged = true;
  52. }
  53. public function isPropagationStopped(): bool {
  54. $this->log();
  55. return $this->event->isPropagationStopped();
  56. }
  57. public function stopPropagation(): void {
  58. $this->log();
  59. $this->event->stopPropagation();
  60. }
  61. public function getSubject() {
  62. $this->log();
  63. return $this->event->getSubject();
  64. }
  65. public function getArgument($key) {
  66. $this->log();
  67. return $this->event->getArgument($key);
  68. }
  69. public function setArgument($key, $value) {
  70. $this->log();
  71. return $this->event->setArgument($key, $value);
  72. }
  73. public function getArguments() {
  74. return $this->event->getArguments();
  75. }
  76. public function setArguments(array $args = []) {
  77. return $this->event->setArguments($args);
  78. }
  79. public function hasArgument($key) {
  80. return $this->event->hasArgument($key);
  81. }
  82. /**
  83. * @return mixed
  84. */
  85. #[\ReturnTypeWillChange]
  86. public function offsetGet($key) {
  87. return $this->event->offsetGet($key);
  88. }
  89. public function offsetSet($key, $value): void {
  90. $this->event->offsetSet($key, $value);
  91. }
  92. public function offsetUnset($key): void {
  93. $this->event->offsetUnset($key);
  94. }
  95. public function offsetExists($key): bool {
  96. return $this->event->offsetExists($key);
  97. }
  98. public function getIterator() {
  99. return$this->event->getIterator();
  100. }
  101. }