generated from Nodarx/template
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXM\ServiceDav\Backends;
|
|
|
|
use KTXF\Documents\Service\ServiceBaseInterface;
|
|
use KTXF\Documents\Service\ServiceCollectionMutableInterface;
|
|
use Sabre\DAV\Collection;
|
|
use Sabre\DAV\Exception\Forbidden;
|
|
use Sabre\DAV\INode;
|
|
|
|
/**
|
|
* A service-level WebDAV collection.
|
|
*
|
|
* Maps one (providerId, serviceId) pair → a DAV folder whose children are
|
|
* the root-level document collections exposed by that service.
|
|
*/
|
|
class FilesServiceNode extends Collection
|
|
{
|
|
public function __construct(
|
|
private readonly ServiceBaseInterface $service,
|
|
) {}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->service->getLabel();
|
|
}
|
|
|
|
/** @return INode[] */
|
|
public function getChildren(): array
|
|
{
|
|
$nodes = [];
|
|
|
|
$collections = $this->service->collectionList(null);
|
|
foreach ($collections as $collection) {
|
|
$nodes[] = new FilesCollectionNode(
|
|
$this->service,
|
|
$collection,
|
|
);
|
|
}
|
|
|
|
/** @var \KTXF\Documents\Entity\EntityBaseInterface[] $entities */
|
|
$entities = $this->service->entityListBulk(null);
|
|
foreach ($entities as $entity) {
|
|
if (is_object($entity)) {
|
|
$nodes[] = new FilesEntityNode(
|
|
$this->service,
|
|
$entity,
|
|
);
|
|
}
|
|
}
|
|
|
|
return $nodes;
|
|
}
|
|
|
|
public function createDirectory($name): void
|
|
{
|
|
if (!$this->service instanceof ServiceCollectionMutableInterface) {
|
|
throw new Forbidden('Service does not support collection creation');
|
|
}
|
|
|
|
$properties = $this->service->collectionFresh()->getProperties();
|
|
$properties->setLabel($name);
|
|
$this->service->collectionCreate(null, $properties);
|
|
}
|
|
}
|