collection->getProperties()->getLabel() ?? (string) $this->collection->identifier(); } /** * Identifier of the collection backing this node */ private function collectionIdentifier(): CollectionIdentifier { return new CollectionIdentifier( $this->service->provider(), (string) $this->service->identifier(), (string) $this->collection->identifier(), ); } /** @return INode[] */ public function getChildren(): array { $nodes = []; // ----- collections (folders) ----- $decendents = $this->service->collectionList($this->collection->identifier()); foreach ($decendents as $decendent) { $nodes[] = new FilesCollectionNode( $this->service, $decendent, ); } // ----- entities (files) ----- /** @var \KTXF\Documents\Entity\EntityBaseInterface[] $entities */ $entities = $this->service->entityListBulk($this->collection->identifier()); 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($this->collectionIdentifier(), $properties); } public function createFile($name, $data = null): string { if (!$this->service instanceof ServiceEntityMutableInterface) { throw new Forbidden('Service does not support entity creation'); } $properties = $this->service->entityFresh()->getProperties(); $properties->setLabel($name); $entity = $this->service->entityCreate($this->collectionIdentifier(), $properties); if ($data !== null) { $content = is_resource($data) ? stream_get_contents($data) : (string) $data; $this->service->entityWrite( new EntityIdentifier( $this->service->provider(), (string) $this->service->identifier(), (string) $entity->collection(), (string) $entity->identifier(), ), $content, ); } return '"' . md5($entity->identifier() . time()) . '"'; } public function delete(): void { if (!$this->service instanceof ServiceCollectionMutableInterface) { throw new Forbidden('Service does not support collection deletion'); } $this->service->collectionDelete($this->collectionIdentifier(), true); } }