You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.0 KiB

  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 OCP\ILogger;
  27. use Symfony\Component\EventDispatcher\GenericEvent;
  28. class GenericEventWrapper extends GenericEvent {
  29. /** @var ILogger */
  30. private $logger;
  31. /** @var GenericEvent */
  32. private $event;
  33. /** @var string */
  34. private $eventName;
  35. /** @var bool */
  36. private $deprecationNoticeLogged = false;
  37. public function __construct(ILogger $logger, string $eventName, ?GenericEvent $event) {
  38. parent::__construct($eventName);
  39. $this->logger = $logger;
  40. $this->event = $event;
  41. $this->eventName = $eventName;
  42. }
  43. private function log() {
  44. if ($this->deprecationNoticeLogged) {
  45. return;
  46. }
  47. $class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
  48. $this->logger->info(
  49. 'Deprecated event type for {name}: {class} is used',
  50. [ 'name' => $this->eventName, 'class' => $class]
  51. );
  52. $this->deprecationNoticeLogged = true;
  53. }
  54. public function isPropagationStopped(): bool {
  55. $this->log();
  56. return $this->event->isPropagationStopped();
  57. }
  58. public function stopPropagation(): void {
  59. $this->log();
  60. $this->event->stopPropagation();
  61. }
  62. public function getSubject() {
  63. $this->log();
  64. return $this->event->getSubject();
  65. }
  66. public function getArgument($key) {
  67. $this->log();
  68. return $this->event->getArgument($key);
  69. }
  70. public function setArgument($key, $value) {
  71. $this->log();
  72. return $this->event->setArgument($key, $value);
  73. }
  74. public function getArguments() {
  75. return $this->event->getArguments();
  76. }
  77. public function setArguments(array $args = []) {
  78. return $this->event->setArguments($args);
  79. }
  80. public function hasArgument($key) {
  81. return $this->event->hasArgument($key);
  82. }
  83. public function offsetGet($key) {
  84. return $this->event->offsetGet($key);
  85. }
  86. public function offsetSet($key, $value) {
  87. return $this->event->offsetSet($key, $value);
  88. }
  89. public function offsetUnset($key) {
  90. return $this->event->offsetUnset($key);
  91. }
  92. public function offsetExists($key) {
  93. return $this->event->offsetExists($key);
  94. }
  95. public function getIterator() {
  96. return$this->event->getIterator();
  97. }
  98. }