ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFileStaticURLHandler.php
Go to the documentation of this file.
1 <?php
2 
28 
32 class ilFileStaticURLHandler extends BaseHandler implements Handler
33 {
34  public const DOWNLOAD = 'download';
35  public const VERSIONS = 'versions';
36  public const EDIT = 'edit';
37  public const VIEW = 'view';
42 
43  public function __construct()
44  {
45  global $DIC;
47  $this->capabilities = new CapabilityBuilder(
49  $DIC->access(),
50  $DIC->ctrl(),
51  new ActionDBRepository($DIC->database()),
52  $DIC->http()
53  );
54  }
55 
56  public function getNamespace(): string
57  {
58  return 'file';
59  }
60 
61  public function handle(Request $request, Context $context, Factory $response_factory): Response
62  {
63  $reference_id = $request->getReferenceId();
64  if ($reference_id === null) {
65  return $response_factory->cannot();
66  }
67 
68  // special case for shared workspace
69  $additional_params = $request->getAdditionalParameters()[0] ?? null;
70  if ($additional_params === '_wsp') {
71  ilObjectGUI::_gotoSharedWorkspaceNode($reference_id->toInt());
72  return $response_factory->loginFirst();
73  }
74 
75  $capability_context = new \ILIAS\File\Capabilities\Context(
76  $reference_id->toObjectId()->toInt(),
77  $reference_id->toInt(),
79  );
80 
81  $capabilities = $this->capabilities->get($capability_context);
82 
83  $capability = match ($additional_params) {
84  self::DOWNLOAD => $capabilities->get(Capabilities::DOWNLOAD),
85  self::VERSIONS => $capabilities->get(Capabilities::MANAGE_VERSIONS),
86  self::EDIT => $capabilities->get(Capabilities::EDIT_EXTERNAL),
87  self::VIEW => $capabilities->get(Capabilities::VIEW_EXTERNAL),
88  default => $capabilities->get(Capabilities::INFO_PAGE),
89  };
90 
91  if (!$capability->isUnlocked() || $capability->getUri() === null) {
92  return $response_factory->loginFirst();
93  }
94 
95  $uri = $capability->getUri();
96 
97  return $response_factory->can($uri->getPath() . '?' . $uri->getQuery());
98  }
99 
100 }
$context
Definition: webdav.php:31
global $DIC
Definition: feed.php:28
handle(Request $request, Context $context, Factory $response_factory)
__construct(VocabulariesInterface $vocabularies)
static _gotoSharedWorkspaceNode(int $wsp_id)