1
0

LogContext.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\WorkflowEngine\Helper;
  8. use OCP\WorkflowEngine\IEntity;
  9. use OCP\WorkflowEngine\IManager;
  10. use OCP\WorkflowEngine\IOperation;
  11. class LogContext {
  12. /** @var array */
  13. protected $details;
  14. public function setDescription(string $description): LogContext {
  15. $this->details['message'] = $description;
  16. return $this;
  17. }
  18. public function setScopes(array $scopes): LogContext {
  19. $this->details['scopes'] = [];
  20. foreach ($scopes as $scope) {
  21. if ($scope instanceof ScopeContext) {
  22. switch ($scope->getScope()) {
  23. case IManager::SCOPE_ADMIN:
  24. $this->details['scopes'][] = ['scope' => 'admin'];
  25. break;
  26. case IManager::SCOPE_USER:
  27. $this->details['scopes'][] = [
  28. 'scope' => 'user',
  29. 'uid' => $scope->getScopeId(),
  30. ];
  31. break;
  32. default:
  33. continue 2;
  34. }
  35. }
  36. }
  37. return $this;
  38. }
  39. public function setOperation(?IOperation $operation): LogContext {
  40. if ($operation instanceof IOperation) {
  41. $this->details['operation'] = [
  42. 'class' => get_class($operation),
  43. 'name' => $operation->getDisplayName(),
  44. ];
  45. }
  46. return $this;
  47. }
  48. public function setEntity(?IEntity $entity): LogContext {
  49. if ($entity instanceof IEntity) {
  50. $this->details['entity'] = [
  51. 'class' => get_class($entity),
  52. 'name' => $entity->getName(),
  53. ];
  54. }
  55. return $this;
  56. }
  57. public function setConfiguration(array $configuration): LogContext {
  58. $this->details['configuration'] = $configuration;
  59. return $this;
  60. }
  61. public function setEventName(string $eventName): LogContext {
  62. $this->details['eventName'] = $eventName;
  63. return $this;
  64. }
  65. public function getDetails(): array {
  66. return $this->details;
  67. }
  68. }