1
0

TFileCheck.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Check;
  8. use OCA\WorkflowEngine\AppInfo\Application;
  9. use OCA\WorkflowEngine\Entity\File;
  10. use OCP\Files\Node;
  11. use OCP\Files\Storage\IStorage;
  12. use OCP\WorkflowEngine\IEntity;
  13. trait TFileCheck {
  14. /** @var IStorage */
  15. protected $storage;
  16. /** @var string */
  17. protected $path;
  18. /** @var bool */
  19. protected $isDir;
  20. /**
  21. * @param IStorage $storage
  22. * @param string $path
  23. * @param bool $isDir
  24. * @since 18.0.0
  25. */
  26. public function setFileInfo(IStorage $storage, string $path, bool $isDir = false): void {
  27. $this->storage = $storage;
  28. $this->path = $path;
  29. $this->isDir = $isDir;
  30. }
  31. /**
  32. * @throws \OCP\Files\NotFoundException
  33. */
  34. public function setEntitySubject(IEntity $entity, $subject): void {
  35. if ($entity instanceof File) {
  36. if (!$subject instanceof Node) {
  37. throw new \UnexpectedValueException(
  38. 'Expected Node subject for File entity, got {class}',
  39. ['app' => Application::APP_ID, 'class' => get_class($subject)]
  40. );
  41. }
  42. $this->storage = $subject->getStorage();
  43. $this->path = $subject->getPath();
  44. }
  45. }
  46. }