summaryrefslogtreecommitdiffstats
path: root/lib/private/files/fileinfo.php
diff options
context:
space:
mode:
authoricewind1991 <robin@icewind.nl>2014-02-14 15:16:39 +0100
committericewind1991 <robin@icewind.nl>2014-02-14 15:16:39 +0100
commit2a7509ee50b3d16392c54c44cad003e8c867e349 (patch)
tree200546c66418125ab387ed8fcab70dcc53bce23c /lib/private/files/fileinfo.php
parentd7f454771769d37e06136332f15695a98275f0f5 (diff)
parent4e2b52a376d2aab5e0f9d0034a8e2bfa196c08bd (diff)
downloadnextcloud-server-2a7509ee50b3d16392c54c44cad003e8c867e349.tar.gz
nextcloud-server-2a7509ee50b3d16392c54c44cad003e8c867e349.zip
Merge pull request #6748 from owncloud/fileinfo
Add a FileInfo class which holds all info of a file ...
Diffstat (limited to 'lib/private/files/fileinfo.php')
-rw-r--r--lib/private/files/fileinfo.php189
1 files changed, 189 insertions, 0 deletions
diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php
new file mode 100644
index 00000000000..7edea13df96
--- /dev/null
+++ b/lib/private/files/fileinfo.php
@@ -0,0 +1,189 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files;
+
+class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable {
+ /**
+ * @var array $data
+ */
+ private $data;
+
+ /**
+ * @var string $path
+ */
+ private $path;
+
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var string $internalPath
+ */
+ private $internalPath;
+
+ public function __construct($path, $storage, $internalPath, $data) {
+ $this->path = $path;
+ $this->storage = $storage;
+ $this->internalPath = $internalPath;
+ $this->data = $data;
+ }
+
+ public function offsetSet($offset, $value) {
+ $this->data[$offset] = $value;
+ }
+
+ public function offsetExists($offset) {
+ return isset($this->data[$offset]);
+ }
+
+ public function offsetUnset($offset) {
+ unset($this->data[$offset]);
+ }
+
+ public function offsetGet($offset) {
+ return $this->data[$offset];
+ }
+
+ public function jsonSerialize() {
+ return $this->data;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPath() {
+ return $this->path;
+ }
+
+ /**
+ * @return \OCP\Files\Storage
+ */
+ public function getStorage() {
+ return $this->storage;
+ }
+
+ /**
+ * @return string
+ */
+ public function getInternalPath() {
+ return $this->internalPath;
+ }
+
+ /**
+ * @return int
+ */
+ public function getId() {
+ return $this->data['fileid'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getMimetype() {
+ return $this->data['mimetype'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getMimePart() {
+ return $this->data['mimepart'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getName() {
+ return $this->data['name'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getEtag() {
+ return $this->data['etag'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getSize() {
+ return $this->data['size'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getMTime() {
+ return $this->data['mtime'];
+ }
+
+ /**
+ * @return bool
+ */
+ public function isEncrypted() {
+ return $this->data['encrypted'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getPermissions() {
+ return $this->data['permissions'];
+ }
+
+ /**
+ * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER
+ */
+ public function getType() {
+ return $this->data['type'];
+ }
+
+ public function getData(){
+ return $this->data;
+ }
+
+ /**
+ * @param int $permissions
+ * @return bool
+ */
+ protected function checkPermissions($permissions) {
+ return ($this->getPermissions() & $permissions) === $permissions;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isReadable() {
+ return $this->checkPermissions(\OCP\PERMISSION_READ);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isUpdateable() {
+ return $this->checkPermissions(\OCP\PERMISSION_UPDATE);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isDeletable() {
+ return $this->checkPermissions(\OCP\PERMISSION_DELETE);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isShareable() {
+ return $this->checkPermissions(\OCP\PERMISSION_SHARE);
+ }
+}