keycloak-webdav/src/Collections/HomeCollection.php

39 lines
807 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;
private $userPath;
2024-06-19 16:47:56 +02:00
public function __construct(AuthPlugin $authPlugin, string $userPath)
2024-06-07 22:27:58 +02:00
{
$this->plugin = $authPlugin;
$this->userPath = $userPath;
}
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];
$path = $this->userPath;
if (!is_dir($path.$username)) {
mkdir($path.$username, 0777 , true);
}
return [new Directory($path.$username, $username)];
}
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
}