ManagerEvent.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCP\SystemTag;
  23. use Symfony\Component\EventDispatcher\Event;
  24. /**
  25. * Class ManagerEvent
  26. *
  27. * @package OCP\SystemTag
  28. * @since 9.0.0
  29. */
  30. class ManagerEvent extends Event {
  31. const EVENT_CREATE = 'OCP\SystemTag\ISystemTagManager::createTag';
  32. const EVENT_UPDATE = 'OCP\SystemTag\ISystemTagManager::updateTag';
  33. const EVENT_DELETE = 'OCP\SystemTag\ISystemTagManager::deleteTag';
  34. /** @var string */
  35. protected $event;
  36. /** @var ISystemTag */
  37. protected $tag;
  38. /** @var ISystemTag */
  39. protected $beforeTag;
  40. /**
  41. * DispatcherEvent constructor.
  42. *
  43. * @param string $event
  44. * @param ISystemTag $tag
  45. * @param ISystemTag $beforeTag
  46. * @since 9.0.0
  47. */
  48. public function __construct($event, ISystemTag $tag, ISystemTag $beforeTag = null) {
  49. $this->event = $event;
  50. $this->tag = $tag;
  51. $this->beforeTag = $beforeTag;
  52. }
  53. /**
  54. * @return string
  55. * @since 9.0.0
  56. */
  57. public function getEvent() {
  58. return $this->event;
  59. }
  60. /**
  61. * @return ISystemTag
  62. * @since 9.0.0
  63. */
  64. public function getTag() {
  65. return $this->tag;
  66. }
  67. /**
  68. * @return ISystemTag
  69. * @since 9.0.0
  70. */
  71. public function getTagBefore() {
  72. if ($this->event !== self::EVENT_UPDATE) {
  73. throw new \BadMethodCallException('getTagBefore is only available on the update Event');
  74. }
  75. return $this->beforeTag;
  76. }
  77. }