123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- <?php
- declare(strict_types=1);
- namespace OC\Files\Node;
- use OC\Files\Filesystem;
- use OC\Files\Utils\PathHelper;
- use OCP\Constants;
- use OCP\Files\Folder;
- use OCP\Files\IRootFolder;
- use OCP\Files\Mount\IMountPoint;
- use OCP\Files\NotPermittedException;
- class LazyFolder implements Folder {
-
- private \Closure $folderClosure;
- protected ?Folder $folder = null;
- protected IRootFolder $rootFolder;
- protected array $data;
-
- public function __construct(IRootFolder $rootFolder, \Closure $folderClosure, array $data = []) {
- $this->rootFolder = $rootFolder;
- $this->folderClosure = $folderClosure;
- $this->data = $data;
- }
- protected function getRootFolder(): IRootFolder {
- return $this->rootFolder;
- }
- protected function getRealFolder(): Folder {
- if ($this->folder === null) {
- $this->folder = call_user_func($this->folderClosure);
- }
- return $this->folder;
- }
-
- public function __call($method, $args) {
- return call_user_func_array([$this->getRealFolder(), $method], $args);
- }
-
- public function getUser() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function listen($scope, $method, callable $callback) {
- $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function removeListener($scope = null, $method = null, ?callable $callback = null) {
- $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function emit($scope, $method, $arguments = []) {
- $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function mount($storage, $mountPoint, $arguments = []) {
- $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMount(string $mountPoint): IMountPoint {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMountsIn(string $mountPoint): array {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMountByStorageId($storageId) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMountByNumericStorageId($numericId) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function unMount($mount) {
- $this->__call(__FUNCTION__, func_get_args());
- }
- public function get($path) {
- return $this->getRootFolder()->get($this->getFullPath($path));
- }
-
- public function rename($targetPath) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function delete() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function copy($targetPath) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function touch($mtime = null) {
- $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getStorage() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getPath() {
- if (isset($this->data['path'])) {
- return $this->data['path'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getInternalPath() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getId() {
- if (isset($this->data['fileid'])) {
- return $this->data['fileid'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function stat() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMTime() {
- if (isset($this->data['mtime'])) {
- return $this->data['mtime'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getSize($includeMounts = true): int|float {
- if (isset($this->data['size'])) {
- return $this->data['size'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getEtag() {
- if (isset($this->data['etag'])) {
- return $this->data['etag'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getPermissions() {
- if (isset($this->data['permissions'])) {
- return $this->data['permissions'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isReadable() {
- if (isset($this->data['permissions'])) {
- return ($this->data['permissions'] & Constants::PERMISSION_READ) == Constants::PERMISSION_READ;
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isUpdateable() {
- if (isset($this->data['permissions'])) {
- return ($this->data['permissions'] & Constants::PERMISSION_UPDATE) == Constants::PERMISSION_UPDATE;
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isDeletable() {
- if (isset($this->data['permissions'])) {
- return ($this->data['permissions'] & Constants::PERMISSION_DELETE) == Constants::PERMISSION_DELETE;
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isShareable() {
- if (isset($this->data['permissions'])) {
- return ($this->data['permissions'] & Constants::PERMISSION_SHARE) == Constants::PERMISSION_SHARE;
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getParent() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getName() {
- if (isset($this->data['path'])) {
- return basename($this->data['path']);
- }
- if (isset($this->data['name'])) {
- return $this->data['name'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getUserFolder($userId) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMimetype() {
- if (isset($this->data['mimetype'])) {
- return $this->data['mimetype'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMimePart() {
- if (isset($this->data['mimetype'])) {
- [$part,] = explode('/', $this->data['mimetype']);
- return $part;
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isEncrypted() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getType() {
- if (isset($this->data['type'])) {
- return $this->data['type'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isShared() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isMounted() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMountPoint() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getOwner() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getChecksum() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
- public function getExtension(): string {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getFullPath($path) {
- if (isset($this->data['path'])) {
- $path = PathHelper::normalizePath($path);
- if (!Filesystem::isValidPath($path)) {
- throw new NotPermittedException('Invalid path "' . $path . '"');
- }
- return $this->data['path'] . $path;
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isSubNode($node) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getDirectoryListing() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
- public function nodeExists($path) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function newFolder($path) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function newFile($path, $content = null) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function search($query) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function searchByMime($mimetype) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function searchByTag($tag, $userId) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
- public function searchBySystemTag(string $tagName, string $userId, int $limit = 0, int $offset = 0) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getById($id) {
- return $this->getRootFolder()->getByIdInPath((int)$id, $this->getPath());
- }
- public function getFirstNodeById(int $id): ?\OCP\Files\Node {
- return $this->getRootFolder()->getFirstNodeByIdInPath($id, $this->getPath());
- }
-
- public function getFreeSpace() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function isCreatable() {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getNonExistingName($name) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function move($targetPath) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function lock($type) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function changeLock($targetType) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function unlock($type) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getRecent($limit, $offset = 0) {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getCreationTime(): int {
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getUploadTime(): int {
- return $this->__call(__FUNCTION__, func_get_args());
- }
- public function getRelativePath($path) {
- return PathHelper::getRelativePath($this->getPath(), $path);
- }
- public function getParentId(): int {
- if (isset($this->data['parent'])) {
- return $this->data['parent'];
- }
- return $this->__call(__FUNCTION__, func_get_args());
- }
-
- public function getMetadata(): array {
- return $this->data['metadata'] ?? $this->__call(__FUNCTION__, func_get_args());
- }
- }
|