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