1
0

LogContext.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\WorkflowEngine\Helper;
  27. use OCP\WorkflowEngine\IEntity;
  28. use OCP\WorkflowEngine\IManager;
  29. use OCP\WorkflowEngine\IOperation;
  30. class LogContext {
  31. /** @var array */
  32. protected $details;
  33. public function setDescription(string $description): LogContext {
  34. $this->details['message'] = $description;
  35. return $this;
  36. }
  37. public function setScopes(array $scopes): LogContext {
  38. $this->details['scopes'] = [];
  39. foreach ($scopes as $scope) {
  40. if ($scope instanceof ScopeContext) {
  41. switch ($scope->getScope()) {
  42. case IManager::SCOPE_ADMIN:
  43. $this->details['scopes'][] = ['scope' => 'admin'];
  44. break;
  45. case IManager::SCOPE_USER:
  46. $this->details['scopes'][] = [
  47. 'scope' => 'user',
  48. 'uid' => $scope->getScopeId(),
  49. ];
  50. break;
  51. default:
  52. continue 2;
  53. }
  54. }
  55. }
  56. return $this;
  57. }
  58. public function setOperation(?IOperation $operation): LogContext {
  59. if ($operation instanceof IOperation) {
  60. $this->details['operation'] = [
  61. 'class' => get_class($operation),
  62. 'name' => $operation->getDisplayName(),
  63. ];
  64. }
  65. return $this;
  66. }
  67. public function setEntity(?IEntity $entity): LogContext {
  68. if ($entity instanceof IEntity) {
  69. $this->details['entity'] = [
  70. 'class' => get_class($entity),
  71. 'name' => $entity->getName(),
  72. ];
  73. }
  74. return $this;
  75. }
  76. public function setConfiguration(array $configuration): LogContext {
  77. $this->details['configuration'] = $configuration;
  78. return $this;
  79. }
  80. public function setEventName(string $eventName): LogContext {
  81. $this->details['eventName'] = $eventName;
  82. return $this;
  83. }
  84. public function getDetails(): array {
  85. return $this->details;
  86. }
  87. }