TFileCheck.php 1.2 KB

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