keycloak-webdav/src/Collections/HomeCollection.php

39 lines
849 B
PHP
Raw Normal View History

2024-06-07 22:27:58 +02:00
<?php
namespace Collections;
use Sabre\DAV\Collection;
use Sabre\DAV\Auth\Plugin as AuthPlugin;
use Sabre\DAV\FS\Directory;
class HomeCollection extends Collection
{
private $plugin;
2024-06-20 01:29:02 +02:00
private $dataPath;
2024-06-07 22:27:58 +02:00
2024-06-20 01:29:02 +02:00
public function __construct(AuthPlugin $authPlugin, string $dataPath)
2024-06-07 22:27:58 +02:00
{
$this->plugin = $authPlugin;
2024-06-20 01:29:02 +02:00
$this->dataPath = $dataPath;
2024-06-07 22:27:58 +02:00
}
2024-06-19 16:47:56 +02:00
public function getChildren(): array
2024-06-07 22:27:58 +02:00
{
$principal = $this->plugin->getCurrentPrincipal();
$username = explode("/", $principal)[1];
2024-06-20 01:29:02 +02:00
$path = $this->dataPath;
2024-06-07 22:27:58 +02:00
2024-06-20 01:29:02 +02:00
if (!is_dir($path . '/users/' . $username)) {
mkdir($path . '/users/' . $username, 0777 , true);
2024-06-07 22:27:58 +02:00
}
2024-06-20 01:29:02 +02:00
return [new Directory($path . '/users/' . $username, $username)];
2024-06-07 22:27:58 +02:00
}
2024-06-19 16:47:56 +02:00
public function getName(): string
2024-06-07 22:27:58 +02:00
{
return "Home";
}
2024-06-19 16:47:56 +02:00
}