IOperation.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\WorkflowEngine;
  7. use OCP\EventDispatcher\Event;
  8. /**
  9. * Interface IOperation
  10. *
  11. * @since 9.1
  12. */
  13. interface IOperation {
  14. /**
  15. * returns a translated name to be presented in the web interface
  16. *
  17. * Example: "Automated tagging" (en), "Aŭtomata etikedado" (eo)
  18. *
  19. * @since 18.0.0
  20. */
  21. public function getDisplayName(): string;
  22. /**
  23. * returns a translated, descriptive text to be presented in the web interface.
  24. *
  25. * It should be short and precise.
  26. *
  27. * Example: "Tag based automatic deletion of files after a given time." (en)
  28. *
  29. * @since 18.0.0
  30. */
  31. public function getDescription(): string;
  32. /**
  33. * returns the URL to the icon of the operator for display in the web interface.
  34. *
  35. * Usually, the implementation would utilize the `imagePath()` method of the
  36. * `\OCP\IURLGenerator` instance and simply return its result.
  37. *
  38. * Example implementation: return $this->urlGenerator->imagePath('myApp', 'cat.svg');
  39. *
  40. * @since 18.0.0
  41. */
  42. public function getIcon(): string;
  43. /**
  44. * returns whether the operation can be used in the requested scope.
  45. *
  46. * Scope IDs are defined as constants in OCP\WorkflowEngine\IManager. At
  47. * time of writing these are SCOPE_ADMIN and SCOPE_USER.
  48. *
  49. * For possibly unknown future scopes the recommended behaviour is: if
  50. * user scope is permitted, the default behaviour should return `true`,
  51. * otherwise `false`.
  52. *
  53. * @param int $scope
  54. * @psalm-param IManager::SCOPE_* $scope
  55. *
  56. * @since 18.0.0
  57. */
  58. public function isAvailableForScope(int $scope): bool;
  59. /**
  60. * Validates whether a configured workflow rule is valid. If it is not,
  61. * an `\UnexpectedValueException` is supposed to be thrown.
  62. *
  63. * @throws \UnexpectedValueException
  64. * @since 9.1
  65. */
  66. public function validateOperation(string $name, array $checks, string $operation): void;
  67. /**
  68. * Is being called by the workflow engine when an event was triggered that
  69. * is configured for this operation. An evaluation whether the event
  70. * qualifies for this operation to run has still to be done by the
  71. * implementor by calling the RuleMatchers getMatchingOperations method
  72. * and evaluating the results.
  73. *
  74. * If the implementor is an IComplexOperation, this method will not be
  75. * called automatically. It can be used or left as no-op by the implementor.
  76. *
  77. * @since 18.0.0
  78. */
  79. public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void;
  80. }