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.

115 lines
2.8 KiB

3 years ago
  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. public function __construct(ILogger $logger, string $eventName, ?GenericEvent $event) {
  36. parent::__construct($eventName);
  37. $this->logger = $logger;
  38. $this->event = $event;
  39. $this->eventName = $eventName;
  40. }
  41. private function log() {
  42. $class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
  43. $this->logger->info(
  44. 'Deprecated event type for {name}: {class} is used',
  45. [ 'name' => $this->eventName, 'class' => $class]
  46. );
  47. }
  48. public function isPropagationStopped(): bool {
  49. $this->log();
  50. return $this->event->isPropagationStopped();
  51. }
  52. public function stopPropagation(): void {
  53. $this->log();
  54. $this->event->stopPropagation();
  55. }
  56. public function getSubject() {
  57. $this->log();
  58. return $this->event->getSubject();
  59. }
  60. public function getArgument($key) {
  61. $this->log();
  62. return $this->event->getArgument($key);
  63. }
  64. public function setArgument($key, $value) {
  65. $this->log();
  66. return $this->event->setArgument($key, $value);
  67. }
  68. public function getArguments() {
  69. return $this->event->getArguments();
  70. }
  71. public function setArguments(array $args = []) {
  72. return $this->event->setArguments($args);
  73. }
  74. public function hasArgument($key) {
  75. return $this->event->hasArgument($key);
  76. }
  77. public function offsetGet($key) {
  78. return $this->event->offsetGet($key);
  79. }
  80. public function offsetSet($key, $value) {
  81. return $this->event->offsetSet($key, $value);
  82. }
  83. public function offsetUnset($key) {
  84. return $this->event->offsetUnset($key);
  85. }
  86. public function offsetExists($key) {
  87. return $this->event->offsetExists($key);
  88. }
  89. public function getIterator() {
  90. return$this->event->getIterator();
  91. }
  92. }