Passed
Push — master ( 201fc9...402930 )
by Roeland
15:58
created
lib/private/Files/ObjectStore/Swift.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -33,106 +33,106 @@
 block discarded – undo
33 33
 use OpenStack\Common\Error\BadResponseError;
34 34
 
35 35
 class Swift implements IObjectStore {
36
-	/**
37
-	 * @var array
38
-	 */
39
-	private $params;
40
-
41
-	/** @var SwiftFactory */
42
-	private $swiftFactory;
43
-
44
-	public function __construct($params, SwiftFactory $connectionFactory = null) {
45
-		$this->swiftFactory = $connectionFactory ?: new SwiftFactory(
46
-			\OC::$server->getMemCacheFactory()->createDistributed('swift::'),
47
-			$params,
48
-			\OC::$server->getLogger()
49
-		);
50
-		$this->params = $params;
51
-	}
52
-
53
-	/**
54
-	 * @return \OpenStack\ObjectStore\v1\Models\Container
55
-	 * @throws StorageAuthException
56
-	 * @throws \OCP\Files\StorageNotAvailableException
57
-	 */
58
-	private function getContainer() {
59
-		return $this->swiftFactory->getContainer();
60
-	}
61
-
62
-	/**
63
-	 * @return string the container name where objects are stored
64
-	 */
65
-	public function getStorageId() {
66
-		if (isset($this->params['bucket'])) {
67
-			return $this->params['bucket'];
68
-		}
69
-
70
-		return $this->params['container'];
71
-	}
72
-
73
-	/**
74
-	 * @param string $urn the unified resource name used to identify the object
75
-	 * @param resource $stream stream with the data to write
76
-	 * @throws \Exception from openstack lib when something goes wrong
77
-	 */
78
-	public function writeObject($urn, $stream) {
79
-		$tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite');
80
-		file_put_contents($tmpFile, $stream);
81
-		$handle = fopen($tmpFile, 'rb');
82
-
83
-		$this->getContainer()->createObject([
84
-			'name' => $urn,
85
-			'stream' => stream_for($handle)
86
-		]);
87
-	}
88
-
89
-	/**
90
-	 * @param string $urn the unified resource name used to identify the object
91
-	 * @return resource stream with the read data
92
-	 * @throws \Exception from openstack lib when something goes wrong
93
-	 * @throws NotFoundException if file does not exist
94
-	 */
95
-	public function readObject($urn) {
96
-		try {
97
-			$object = $this->getContainer()->getObject($urn);
98
-
99
-			// we need to keep a reference to objectContent or
100
-			// the stream will be closed before we can do anything with it
101
-			$objectContent = $object->download();
102
-		} catch (BadResponseError $e) {
103
-			if ($e->getResponse()->getStatusCode() === 404) {
104
-				throw new NotFoundException("object $urn not found in object store");
105
-			} else {
106
-				throw $e;
107
-			}
108
-		}
109
-		$objectContent->rewind();
110
-
111
-		$stream = $objectContent->detach();
112
-		// save the object content in the context of the stream to prevent it being gc'd until the stream is closed
113
-		stream_context_set_option($stream, 'swift', 'content', $objectContent);
114
-
115
-		return RetryWrapper::wrap($stream);
116
-	}
117
-
118
-	/**
119
-	 * @param string $urn Unified Resource Name
120
-	 * @return void
121
-	 * @throws \Exception from openstack lib when something goes wrong
122
-	 */
123
-	public function deleteObject($urn) {
124
-		$this->getContainer()->getObject($urn)->delete();
125
-	}
126
-
127
-	/**
128
-	 * @return void
129
-	 * @throws \Exception from openstack lib when something goes wrong
130
-	 */
131
-	public function deleteContainer() {
132
-		$this->getContainer()->delete();
133
-	}
134
-
135
-	public function objectExists($urn) {
136
-		return $this->getContainer()->objectExists($urn);
137
-	}
36
+    /**
37
+     * @var array
38
+     */
39
+    private $params;
40
+
41
+    /** @var SwiftFactory */
42
+    private $swiftFactory;
43
+
44
+    public function __construct($params, SwiftFactory $connectionFactory = null) {
45
+        $this->swiftFactory = $connectionFactory ?: new SwiftFactory(
46
+            \OC::$server->getMemCacheFactory()->createDistributed('swift::'),
47
+            $params,
48
+            \OC::$server->getLogger()
49
+        );
50
+        $this->params = $params;
51
+    }
52
+
53
+    /**
54
+     * @return \OpenStack\ObjectStore\v1\Models\Container
55
+     * @throws StorageAuthException
56
+     * @throws \OCP\Files\StorageNotAvailableException
57
+     */
58
+    private function getContainer() {
59
+        return $this->swiftFactory->getContainer();
60
+    }
61
+
62
+    /**
63
+     * @return string the container name where objects are stored
64
+     */
65
+    public function getStorageId() {
66
+        if (isset($this->params['bucket'])) {
67
+            return $this->params['bucket'];
68
+        }
69
+
70
+        return $this->params['container'];
71
+    }
72
+
73
+    /**
74
+     * @param string $urn the unified resource name used to identify the object
75
+     * @param resource $stream stream with the data to write
76
+     * @throws \Exception from openstack lib when something goes wrong
77
+     */
78
+    public function writeObject($urn, $stream) {
79
+        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('swiftwrite');
80
+        file_put_contents($tmpFile, $stream);
81
+        $handle = fopen($tmpFile, 'rb');
82
+
83
+        $this->getContainer()->createObject([
84
+            'name' => $urn,
85
+            'stream' => stream_for($handle)
86
+        ]);
87
+    }
88
+
89
+    /**
90
+     * @param string $urn the unified resource name used to identify the object
91
+     * @return resource stream with the read data
92
+     * @throws \Exception from openstack lib when something goes wrong
93
+     * @throws NotFoundException if file does not exist
94
+     */
95
+    public function readObject($urn) {
96
+        try {
97
+            $object = $this->getContainer()->getObject($urn);
98
+
99
+            // we need to keep a reference to objectContent or
100
+            // the stream will be closed before we can do anything with it
101
+            $objectContent = $object->download();
102
+        } catch (BadResponseError $e) {
103
+            if ($e->getResponse()->getStatusCode() === 404) {
104
+                throw new NotFoundException("object $urn not found in object store");
105
+            } else {
106
+                throw $e;
107
+            }
108
+        }
109
+        $objectContent->rewind();
110
+
111
+        $stream = $objectContent->detach();
112
+        // save the object content in the context of the stream to prevent it being gc'd until the stream is closed
113
+        stream_context_set_option($stream, 'swift', 'content', $objectContent);
114
+
115
+        return RetryWrapper::wrap($stream);
116
+    }
117
+
118
+    /**
119
+     * @param string $urn Unified Resource Name
120
+     * @return void
121
+     * @throws \Exception from openstack lib when something goes wrong
122
+     */
123
+    public function deleteObject($urn) {
124
+        $this->getContainer()->getObject($urn)->delete();
125
+    }
126
+
127
+    /**
128
+     * @return void
129
+     * @throws \Exception from openstack lib when something goes wrong
130
+     */
131
+    public function deleteContainer() {
132
+        $this->getContainer()->delete();
133
+    }
134
+
135
+    public function objectExists($urn) {
136
+        return $this->getContainer()->objectExists($urn);
137
+    }
138 138
 }
Please login to merge, or discard this patch.