@@ -39,190 +39,190 @@ |
||
39 | 39 | * @since 6.0.0 |
40 | 40 | */ |
41 | 41 | interface IManager { |
42 | - /** |
|
43 | - * Generates a new IEvent object |
|
44 | - * |
|
45 | - * Make sure to call at least the following methods before sending it to the |
|
46 | - * app with via the publish() method: |
|
47 | - * - setApp() |
|
48 | - * - setType() |
|
49 | - * - setAffectedUser() |
|
50 | - * - setSubject() |
|
51 | - * |
|
52 | - * @return IEvent |
|
53 | - * @since 8.2.0 |
|
54 | - */ |
|
55 | - public function generateEvent(); |
|
56 | - |
|
57 | - /** |
|
58 | - * Publish an event to the activity consumers |
|
59 | - * |
|
60 | - * Make sure to call at least the following methods before sending an Event: |
|
61 | - * - setApp() |
|
62 | - * - setType() |
|
63 | - * - setAffectedUser() |
|
64 | - * - setSubject() |
|
65 | - * |
|
66 | - * @param IEvent $event |
|
67 | - * @return null |
|
68 | - * @since 8.2.0 |
|
69 | - */ |
|
70 | - public function publish(IEvent $event); |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $app The app where this event is associated with |
|
74 | - * @param string $subject A short description of the event |
|
75 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
76 | - * @param string $message A longer description of the event |
|
77 | - * @param array $messageParams Array with parameters that are filled in the message |
|
78 | - * @param string $file The file including path where this event is associated with |
|
79 | - * @param string $link A link where this event is associated with |
|
80 | - * @param string $affectedUser Recipient of the activity |
|
81 | - * @param string $type Type of the notification |
|
82 | - * @param int $priority Priority of the notification |
|
83 | - * @return null |
|
84 | - * @since 6.0.0 |
|
85 | - * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method |
|
86 | - */ |
|
87 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); |
|
88 | - |
|
89 | - /** |
|
90 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
91 | - * activity consumers are actually requested |
|
92 | - * |
|
93 | - * $callable has to return an instance of \OCP\Activity\IConsumer |
|
94 | - * |
|
95 | - * @param \Closure $callable |
|
96 | - * @return void |
|
97 | - * @since 6.0.0 |
|
98 | - */ |
|
99 | - public function registerConsumer(\Closure $callable); |
|
100 | - |
|
101 | - /** |
|
102 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
103 | - * activity consumers are actually requested |
|
104 | - * |
|
105 | - * $callable has to return an instance of \OCP\Activity\IExtension |
|
106 | - * |
|
107 | - * @param \Closure $callable |
|
108 | - * @return void |
|
109 | - * @since 8.0.0 |
|
110 | - */ |
|
111 | - public function registerExtension(\Closure $callable); |
|
112 | - |
|
113 | - /** |
|
114 | - * Will return additional notification types as specified by other apps |
|
115 | - * |
|
116 | - * @param string $languageCode |
|
117 | - * @return array Array "stringID of the type" => "translated string description for the setting" |
|
118 | - * or Array "stringID of the type" => [ |
|
119 | - * 'desc' => "translated string description for the setting" |
|
120 | - * 'methods' => [\OCP\Activity\IExtension::METHOD_*], |
|
121 | - * ] |
|
122 | - * @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods |
|
123 | - */ |
|
124 | - public function getNotificationTypes($languageCode); |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $method |
|
128 | - * @return array |
|
129 | - * @since 8.0.0 |
|
130 | - */ |
|
131 | - public function getDefaultTypes($method); |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $type |
|
135 | - * @return string |
|
136 | - * @since 8.0.0 |
|
137 | - */ |
|
138 | - public function getTypeIcon($type); |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $type |
|
142 | - * @param int $id |
|
143 | - * @since 8.2.0 |
|
144 | - */ |
|
145 | - public function setFormattingObject($type, $id); |
|
146 | - |
|
147 | - /** |
|
148 | - * @return bool |
|
149 | - * @since 8.2.0 |
|
150 | - */ |
|
151 | - public function isFormattingFilteredObject(); |
|
152 | - |
|
153 | - /** |
|
154 | - * @param string $app |
|
155 | - * @param string $text |
|
156 | - * @param array $params |
|
157 | - * @param boolean $stripPath |
|
158 | - * @param boolean $highlightParams |
|
159 | - * @param string $languageCode |
|
160 | - * @return string|false |
|
161 | - * @since 8.0.0 |
|
162 | - */ |
|
163 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
164 | - |
|
165 | - /** |
|
166 | - * @param string $app |
|
167 | - * @param string $text |
|
168 | - * @return array|false |
|
169 | - * @since 8.0.0 |
|
170 | - */ |
|
171 | - public function getSpecialParameterList($app, $text); |
|
172 | - |
|
173 | - /** |
|
174 | - * @param array $activity |
|
175 | - * @return integer|false |
|
176 | - * @since 8.0.0 |
|
177 | - */ |
|
178 | - public function getGroupParameter($activity); |
|
179 | - |
|
180 | - /** |
|
181 | - * @return array |
|
182 | - * @since 8.0.0 |
|
183 | - */ |
|
184 | - public function getNavigation(); |
|
185 | - |
|
186 | - /** |
|
187 | - * @param string $filterValue |
|
188 | - * @return boolean |
|
189 | - * @since 8.0.0 |
|
190 | - */ |
|
191 | - public function isFilterValid($filterValue); |
|
192 | - |
|
193 | - /** |
|
194 | - * @param array $types |
|
195 | - * @param string $filter |
|
196 | - * @return array |
|
197 | - * @since 8.0.0 |
|
198 | - */ |
|
199 | - public function filterNotificationTypes($types, $filter); |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $filter |
|
203 | - * @return array |
|
204 | - * @since 8.0.0 |
|
205 | - */ |
|
206 | - public function getQueryForFilter($filter); |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Set the user we need to use |
|
211 | - * |
|
212 | - * @param string|null $currentUserId |
|
213 | - * @throws \UnexpectedValueException If the user is invalid |
|
214 | - * @since 9.0.1 |
|
215 | - */ |
|
216 | - public function setCurrentUserId($currentUserId); |
|
217 | - |
|
218 | - /** |
|
219 | - * Get the user we need to use |
|
220 | - * |
|
221 | - * Either the user is logged in, or we try to get it from the token |
|
222 | - * |
|
223 | - * @return string |
|
224 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
225 | - * @since 8.1.0 |
|
226 | - */ |
|
227 | - public function getCurrentUserId(); |
|
42 | + /** |
|
43 | + * Generates a new IEvent object |
|
44 | + * |
|
45 | + * Make sure to call at least the following methods before sending it to the |
|
46 | + * app with via the publish() method: |
|
47 | + * - setApp() |
|
48 | + * - setType() |
|
49 | + * - setAffectedUser() |
|
50 | + * - setSubject() |
|
51 | + * |
|
52 | + * @return IEvent |
|
53 | + * @since 8.2.0 |
|
54 | + */ |
|
55 | + public function generateEvent(); |
|
56 | + |
|
57 | + /** |
|
58 | + * Publish an event to the activity consumers |
|
59 | + * |
|
60 | + * Make sure to call at least the following methods before sending an Event: |
|
61 | + * - setApp() |
|
62 | + * - setType() |
|
63 | + * - setAffectedUser() |
|
64 | + * - setSubject() |
|
65 | + * |
|
66 | + * @param IEvent $event |
|
67 | + * @return null |
|
68 | + * @since 8.2.0 |
|
69 | + */ |
|
70 | + public function publish(IEvent $event); |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $app The app where this event is associated with |
|
74 | + * @param string $subject A short description of the event |
|
75 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
76 | + * @param string $message A longer description of the event |
|
77 | + * @param array $messageParams Array with parameters that are filled in the message |
|
78 | + * @param string $file The file including path where this event is associated with |
|
79 | + * @param string $link A link where this event is associated with |
|
80 | + * @param string $affectedUser Recipient of the activity |
|
81 | + * @param string $type Type of the notification |
|
82 | + * @param int $priority Priority of the notification |
|
83 | + * @return null |
|
84 | + * @since 6.0.0 |
|
85 | + * @deprecated 8.2.0 Grab an IEvent from generateEvent() instead and use the publish() method |
|
86 | + */ |
|
87 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); |
|
88 | + |
|
89 | + /** |
|
90 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
91 | + * activity consumers are actually requested |
|
92 | + * |
|
93 | + * $callable has to return an instance of \OCP\Activity\IConsumer |
|
94 | + * |
|
95 | + * @param \Closure $callable |
|
96 | + * @return void |
|
97 | + * @since 6.0.0 |
|
98 | + */ |
|
99 | + public function registerConsumer(\Closure $callable); |
|
100 | + |
|
101 | + /** |
|
102 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
103 | + * activity consumers are actually requested |
|
104 | + * |
|
105 | + * $callable has to return an instance of \OCP\Activity\IExtension |
|
106 | + * |
|
107 | + * @param \Closure $callable |
|
108 | + * @return void |
|
109 | + * @since 8.0.0 |
|
110 | + */ |
|
111 | + public function registerExtension(\Closure $callable); |
|
112 | + |
|
113 | + /** |
|
114 | + * Will return additional notification types as specified by other apps |
|
115 | + * |
|
116 | + * @param string $languageCode |
|
117 | + * @return array Array "stringID of the type" => "translated string description for the setting" |
|
118 | + * or Array "stringID of the type" => [ |
|
119 | + * 'desc' => "translated string description for the setting" |
|
120 | + * 'methods' => [\OCP\Activity\IExtension::METHOD_*], |
|
121 | + * ] |
|
122 | + * @since 8.0.0 - 8.2.0: Added support to allow limiting notifications to certain methods |
|
123 | + */ |
|
124 | + public function getNotificationTypes($languageCode); |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $method |
|
128 | + * @return array |
|
129 | + * @since 8.0.0 |
|
130 | + */ |
|
131 | + public function getDefaultTypes($method); |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $type |
|
135 | + * @return string |
|
136 | + * @since 8.0.0 |
|
137 | + */ |
|
138 | + public function getTypeIcon($type); |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $type |
|
142 | + * @param int $id |
|
143 | + * @since 8.2.0 |
|
144 | + */ |
|
145 | + public function setFormattingObject($type, $id); |
|
146 | + |
|
147 | + /** |
|
148 | + * @return bool |
|
149 | + * @since 8.2.0 |
|
150 | + */ |
|
151 | + public function isFormattingFilteredObject(); |
|
152 | + |
|
153 | + /** |
|
154 | + * @param string $app |
|
155 | + * @param string $text |
|
156 | + * @param array $params |
|
157 | + * @param boolean $stripPath |
|
158 | + * @param boolean $highlightParams |
|
159 | + * @param string $languageCode |
|
160 | + * @return string|false |
|
161 | + * @since 8.0.0 |
|
162 | + */ |
|
163 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
164 | + |
|
165 | + /** |
|
166 | + * @param string $app |
|
167 | + * @param string $text |
|
168 | + * @return array|false |
|
169 | + * @since 8.0.0 |
|
170 | + */ |
|
171 | + public function getSpecialParameterList($app, $text); |
|
172 | + |
|
173 | + /** |
|
174 | + * @param array $activity |
|
175 | + * @return integer|false |
|
176 | + * @since 8.0.0 |
|
177 | + */ |
|
178 | + public function getGroupParameter($activity); |
|
179 | + |
|
180 | + /** |
|
181 | + * @return array |
|
182 | + * @since 8.0.0 |
|
183 | + */ |
|
184 | + public function getNavigation(); |
|
185 | + |
|
186 | + /** |
|
187 | + * @param string $filterValue |
|
188 | + * @return boolean |
|
189 | + * @since 8.0.0 |
|
190 | + */ |
|
191 | + public function isFilterValid($filterValue); |
|
192 | + |
|
193 | + /** |
|
194 | + * @param array $types |
|
195 | + * @param string $filter |
|
196 | + * @return array |
|
197 | + * @since 8.0.0 |
|
198 | + */ |
|
199 | + public function filterNotificationTypes($types, $filter); |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $filter |
|
203 | + * @return array |
|
204 | + * @since 8.0.0 |
|
205 | + */ |
|
206 | + public function getQueryForFilter($filter); |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Set the user we need to use |
|
211 | + * |
|
212 | + * @param string|null $currentUserId |
|
213 | + * @throws \UnexpectedValueException If the user is invalid |
|
214 | + * @since 9.0.1 |
|
215 | + */ |
|
216 | + public function setCurrentUserId($currentUserId); |
|
217 | + |
|
218 | + /** |
|
219 | + * Get the user we need to use |
|
220 | + * |
|
221 | + * Either the user is logged in, or we try to get it from the token |
|
222 | + * |
|
223 | + * @return string |
|
224 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
225 | + * @since 8.1.0 |
|
226 | + */ |
|
227 | + public function getCurrentUserId(); |
|
228 | 228 | } |
@@ -36,166 +36,166 @@ |
||
36 | 36 | * @since 8.2.0 |
37 | 37 | */ |
38 | 38 | interface IEvent { |
39 | - /** |
|
40 | - * Set the app of the activity |
|
41 | - * |
|
42 | - * @param string $app |
|
43 | - * @return IEvent |
|
44 | - * @since 8.2.0 |
|
45 | - */ |
|
46 | - public function setApp($app); |
|
47 | - |
|
48 | - /** |
|
49 | - * Set the type of the activity |
|
50 | - * |
|
51 | - * @param string $type |
|
52 | - * @return IEvent |
|
53 | - * @since 8.2.0 |
|
54 | - */ |
|
55 | - public function setType($type); |
|
56 | - |
|
57 | - /** |
|
58 | - * Set the affected user of the activity |
|
59 | - * |
|
60 | - * @param string $user |
|
61 | - * @return IEvent |
|
62 | - * @since 8.2.0 |
|
63 | - */ |
|
64 | - public function setAffectedUser($user); |
|
65 | - |
|
66 | - /** |
|
67 | - * Set the author of the activity |
|
68 | - * |
|
69 | - * @param string $author |
|
70 | - * @return IEvent |
|
71 | - * @since 8.2.0 |
|
72 | - */ |
|
73 | - public function setAuthor($author); |
|
74 | - |
|
75 | - /** |
|
76 | - * Set the author of the activity |
|
77 | - * |
|
78 | - * @param int $timestamp |
|
79 | - * @return IEvent |
|
80 | - * @since 8.2.0 |
|
81 | - */ |
|
82 | - public function setTimestamp($timestamp); |
|
83 | - |
|
84 | - /** |
|
85 | - * Set the subject of the activity |
|
86 | - * |
|
87 | - * @param string $subject |
|
88 | - * @param array $parameters |
|
89 | - * @return IEvent |
|
90 | - * @since 8.2.0 |
|
91 | - */ |
|
92 | - public function setSubject($subject, array $parameters = []); |
|
93 | - |
|
94 | - /** |
|
95 | - * Set the message of the activity |
|
96 | - * |
|
97 | - * @param string $message |
|
98 | - * @param array $parameters |
|
99 | - * @return IEvent |
|
100 | - * @since 8.2.0 |
|
101 | - */ |
|
102 | - public function setMessage($message, array $parameters = []); |
|
103 | - |
|
104 | - /** |
|
105 | - * Set the object of the activity |
|
106 | - * |
|
107 | - * @param string $objectType |
|
108 | - * @param int $objectId |
|
109 | - * @param string $objectName |
|
110 | - * @return IEvent |
|
111 | - * @since 8.2.0 |
|
112 | - */ |
|
113 | - public function setObject($objectType, $objectId, $objectName = ''); |
|
114 | - |
|
115 | - /** |
|
116 | - * Set the link of the activity |
|
117 | - * |
|
118 | - * @param string $link |
|
119 | - * @return IEvent |
|
120 | - * @since 8.2.0 |
|
121 | - */ |
|
122 | - public function setLink($link); |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - * @since 8.2.0 |
|
127 | - */ |
|
128 | - public function getApp(); |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - * @since 8.2.0 |
|
133 | - */ |
|
134 | - public function getType(); |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - * @since 8.2.0 |
|
139 | - */ |
|
140 | - public function getAffectedUser(); |
|
141 | - |
|
142 | - /** |
|
143 | - * @return string |
|
144 | - * @since 8.2.0 |
|
145 | - */ |
|
146 | - public function getAuthor(); |
|
147 | - |
|
148 | - /** |
|
149 | - * @return int |
|
150 | - * @since 8.2.0 |
|
151 | - */ |
|
152 | - public function getTimestamp(); |
|
153 | - |
|
154 | - /** |
|
155 | - * @return string |
|
156 | - * @since 8.2.0 |
|
157 | - */ |
|
158 | - public function getSubject(); |
|
159 | - |
|
160 | - /** |
|
161 | - * @return array |
|
162 | - * @since 8.2.0 |
|
163 | - */ |
|
164 | - public function getSubjectParameters(); |
|
165 | - |
|
166 | - /** |
|
167 | - * @return string |
|
168 | - * @since 8.2.0 |
|
169 | - */ |
|
170 | - public function getMessage(); |
|
171 | - |
|
172 | - /** |
|
173 | - * @return array |
|
174 | - * @since 8.2.0 |
|
175 | - */ |
|
176 | - public function getMessageParameters(); |
|
177 | - |
|
178 | - /** |
|
179 | - * @return string |
|
180 | - * @since 8.2.0 |
|
181 | - */ |
|
182 | - public function getObjectType(); |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string |
|
186 | - * @since 8.2.0 |
|
187 | - */ |
|
188 | - public function getObjectId(); |
|
189 | - |
|
190 | - /** |
|
191 | - * @return string |
|
192 | - * @since 8.2.0 |
|
193 | - */ |
|
194 | - public function getObjectName(); |
|
195 | - |
|
196 | - /** |
|
197 | - * @return string |
|
198 | - * @since 8.2.0 |
|
199 | - */ |
|
200 | - public function getLink(); |
|
39 | + /** |
|
40 | + * Set the app of the activity |
|
41 | + * |
|
42 | + * @param string $app |
|
43 | + * @return IEvent |
|
44 | + * @since 8.2.0 |
|
45 | + */ |
|
46 | + public function setApp($app); |
|
47 | + |
|
48 | + /** |
|
49 | + * Set the type of the activity |
|
50 | + * |
|
51 | + * @param string $type |
|
52 | + * @return IEvent |
|
53 | + * @since 8.2.0 |
|
54 | + */ |
|
55 | + public function setType($type); |
|
56 | + |
|
57 | + /** |
|
58 | + * Set the affected user of the activity |
|
59 | + * |
|
60 | + * @param string $user |
|
61 | + * @return IEvent |
|
62 | + * @since 8.2.0 |
|
63 | + */ |
|
64 | + public function setAffectedUser($user); |
|
65 | + |
|
66 | + /** |
|
67 | + * Set the author of the activity |
|
68 | + * |
|
69 | + * @param string $author |
|
70 | + * @return IEvent |
|
71 | + * @since 8.2.0 |
|
72 | + */ |
|
73 | + public function setAuthor($author); |
|
74 | + |
|
75 | + /** |
|
76 | + * Set the author of the activity |
|
77 | + * |
|
78 | + * @param int $timestamp |
|
79 | + * @return IEvent |
|
80 | + * @since 8.2.0 |
|
81 | + */ |
|
82 | + public function setTimestamp($timestamp); |
|
83 | + |
|
84 | + /** |
|
85 | + * Set the subject of the activity |
|
86 | + * |
|
87 | + * @param string $subject |
|
88 | + * @param array $parameters |
|
89 | + * @return IEvent |
|
90 | + * @since 8.2.0 |
|
91 | + */ |
|
92 | + public function setSubject($subject, array $parameters = []); |
|
93 | + |
|
94 | + /** |
|
95 | + * Set the message of the activity |
|
96 | + * |
|
97 | + * @param string $message |
|
98 | + * @param array $parameters |
|
99 | + * @return IEvent |
|
100 | + * @since 8.2.0 |
|
101 | + */ |
|
102 | + public function setMessage($message, array $parameters = []); |
|
103 | + |
|
104 | + /** |
|
105 | + * Set the object of the activity |
|
106 | + * |
|
107 | + * @param string $objectType |
|
108 | + * @param int $objectId |
|
109 | + * @param string $objectName |
|
110 | + * @return IEvent |
|
111 | + * @since 8.2.0 |
|
112 | + */ |
|
113 | + public function setObject($objectType, $objectId, $objectName = ''); |
|
114 | + |
|
115 | + /** |
|
116 | + * Set the link of the activity |
|
117 | + * |
|
118 | + * @param string $link |
|
119 | + * @return IEvent |
|
120 | + * @since 8.2.0 |
|
121 | + */ |
|
122 | + public function setLink($link); |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + * @since 8.2.0 |
|
127 | + */ |
|
128 | + public function getApp(); |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + * @since 8.2.0 |
|
133 | + */ |
|
134 | + public function getType(); |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + * @since 8.2.0 |
|
139 | + */ |
|
140 | + public function getAffectedUser(); |
|
141 | + |
|
142 | + /** |
|
143 | + * @return string |
|
144 | + * @since 8.2.0 |
|
145 | + */ |
|
146 | + public function getAuthor(); |
|
147 | + |
|
148 | + /** |
|
149 | + * @return int |
|
150 | + * @since 8.2.0 |
|
151 | + */ |
|
152 | + public function getTimestamp(); |
|
153 | + |
|
154 | + /** |
|
155 | + * @return string |
|
156 | + * @since 8.2.0 |
|
157 | + */ |
|
158 | + public function getSubject(); |
|
159 | + |
|
160 | + /** |
|
161 | + * @return array |
|
162 | + * @since 8.2.0 |
|
163 | + */ |
|
164 | + public function getSubjectParameters(); |
|
165 | + |
|
166 | + /** |
|
167 | + * @return string |
|
168 | + * @since 8.2.0 |
|
169 | + */ |
|
170 | + public function getMessage(); |
|
171 | + |
|
172 | + /** |
|
173 | + * @return array |
|
174 | + * @since 8.2.0 |
|
175 | + */ |
|
176 | + public function getMessageParameters(); |
|
177 | + |
|
178 | + /** |
|
179 | + * @return string |
|
180 | + * @since 8.2.0 |
|
181 | + */ |
|
182 | + public function getObjectType(); |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string |
|
186 | + * @since 8.2.0 |
|
187 | + */ |
|
188 | + public function getObjectId(); |
|
189 | + |
|
190 | + /** |
|
191 | + * @return string |
|
192 | + * @since 8.2.0 |
|
193 | + */ |
|
194 | + public function getObjectName(); |
|
195 | + |
|
196 | + /** |
|
197 | + * @return string |
|
198 | + * @since 8.2.0 |
|
199 | + */ |
|
200 | + public function getLink(); |
|
201 | 201 | } |
@@ -33,65 +33,65 @@ |
||
33 | 33 | */ |
34 | 34 | class SabrePluginEvent extends Event { |
35 | 35 | |
36 | - /** @var int */ |
|
37 | - protected $statusCode; |
|
36 | + /** @var int */ |
|
37 | + protected $statusCode; |
|
38 | 38 | |
39 | - /** @var string */ |
|
40 | - protected $message; |
|
39 | + /** @var string */ |
|
40 | + protected $message; |
|
41 | 41 | |
42 | - /** @var Server */ |
|
43 | - protected $server; |
|
42 | + /** @var Server */ |
|
43 | + protected $server; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @since 8.2.0 |
|
47 | - */ |
|
48 | - public function __construct($server = null) { |
|
49 | - $this->message = ''; |
|
50 | - $this->statusCode = Http::STATUS_OK; |
|
51 | - $this->server = $server; |
|
52 | - } |
|
45 | + /** |
|
46 | + * @since 8.2.0 |
|
47 | + */ |
|
48 | + public function __construct($server = null) { |
|
49 | + $this->message = ''; |
|
50 | + $this->statusCode = Http::STATUS_OK; |
|
51 | + $this->server = $server; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param int $statusCode |
|
56 | - * @return self |
|
57 | - * @since 8.2.0 |
|
58 | - */ |
|
59 | - public function setStatusCode($statusCode) { |
|
60 | - $this->statusCode = (int) $statusCode; |
|
61 | - return $this; |
|
62 | - } |
|
54 | + /** |
|
55 | + * @param int $statusCode |
|
56 | + * @return self |
|
57 | + * @since 8.2.0 |
|
58 | + */ |
|
59 | + public function setStatusCode($statusCode) { |
|
60 | + $this->statusCode = (int) $statusCode; |
|
61 | + return $this; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $message |
|
66 | - * @return self |
|
67 | - * @since 8.2.0 |
|
68 | - */ |
|
69 | - public function setMessage($message) { |
|
70 | - $this->message = (string) $message; |
|
71 | - return $this; |
|
72 | - } |
|
64 | + /** |
|
65 | + * @param string $message |
|
66 | + * @return self |
|
67 | + * @since 8.2.0 |
|
68 | + */ |
|
69 | + public function setMessage($message) { |
|
70 | + $this->message = (string) $message; |
|
71 | + return $this; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return int |
|
76 | - * @since 8.2.0 |
|
77 | - */ |
|
78 | - public function getStatusCode() { |
|
79 | - return $this->statusCode; |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return int |
|
76 | + * @since 8.2.0 |
|
77 | + */ |
|
78 | + public function getStatusCode() { |
|
79 | + return $this->statusCode; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return string |
|
84 | - * @since 8.2.0 |
|
85 | - */ |
|
86 | - public function getMessage() { |
|
87 | - return $this->message; |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + * @since 8.2.0 |
|
85 | + */ |
|
86 | + public function getMessage() { |
|
87 | + return $this->message; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return null|Server |
|
92 | - * @since 9.0.0 |
|
93 | - */ |
|
94 | - public function getServer() { |
|
95 | - return $this->server; |
|
96 | - } |
|
90 | + /** |
|
91 | + * @return null|Server |
|
92 | + * @since 9.0.0 |
|
93 | + */ |
|
94 | + public function getServer() { |
|
95 | + return $this->server; |
|
96 | + } |
|
97 | 97 | } |
@@ -34,165 +34,165 @@ |
||
34 | 34 | use \OCP\AutoloadNotAllowedException; |
35 | 35 | |
36 | 36 | class Autoloader { |
37 | - /** @var bool */ |
|
38 | - private $useGlobalClassPath = true; |
|
39 | - /** @var array */ |
|
40 | - private $validRoots = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * Optional low-latency memory cache for class to path mapping. |
|
44 | - * |
|
45 | - * @var \OC\Memcache\Cache |
|
46 | - */ |
|
47 | - protected $memoryCache; |
|
48 | - |
|
49 | - /** |
|
50 | - * Autoloader constructor. |
|
51 | - * |
|
52 | - * @param string[] $validRoots |
|
53 | - */ |
|
54 | - public function __construct(array $validRoots) { |
|
55 | - foreach ($validRoots as $root) { |
|
56 | - $this->validRoots[$root] = true; |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Add a path to the list of valid php roots for auto loading |
|
62 | - * |
|
63 | - * @param string $root |
|
64 | - */ |
|
65 | - public function addValidRoot($root) { |
|
66 | - $root = stream_resolve_include_path($root); |
|
67 | - $this->validRoots[$root] = true; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * disable the usage of the global classpath \OC::$CLASSPATH |
|
72 | - */ |
|
73 | - public function disableGlobalClassPath() { |
|
74 | - $this->useGlobalClassPath = false; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * enable the usage of the global classpath \OC::$CLASSPATH |
|
79 | - */ |
|
80 | - public function enableGlobalClassPath() { |
|
81 | - $this->useGlobalClassPath = true; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * get the possible paths for a class |
|
86 | - * |
|
87 | - * @param string $class |
|
88 | - * @return array|bool an array of possible paths or false if the class is not part of ownCloud |
|
89 | - */ |
|
90 | - public function findClass($class) { |
|
91 | - $class = trim($class, '\\'); |
|
92 | - |
|
93 | - $paths = array(); |
|
94 | - if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) { |
|
95 | - $paths[] = \OC::$CLASSPATH[$class]; |
|
96 | - /** |
|
97 | - * @TODO: Remove this when necessary |
|
98 | - * Remove "apps/" from inclusion path for smooth migration to mutli app dir |
|
99 | - */ |
|
100 | - if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { |
|
101 | - \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG); |
|
102 | - $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); |
|
103 | - } |
|
104 | - } elseif (strpos($class, 'OC_') === 0) { |
|
105 | - $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
106 | - $paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
107 | - } elseif (strpos($class, 'OC\\') === 0) { |
|
108 | - $split = explode('\\', $class, 3); |
|
109 | - |
|
110 | - if (count($split) === 3) { |
|
111 | - $split[1] = strtolower($split[1]); |
|
112 | - |
|
113 | - if ($split[1] === 'core') { |
|
114 | - $paths[] = \OC::$SERVERROOT . '/core/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
115 | - } else if ($split[1] === 'settings') { |
|
116 | - $paths[] = \OC::$SERVERROOT . '/settings/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
117 | - } else { |
|
118 | - $paths[] = \OC::$SERVERROOT . '/lib/private/' . $split[1] . '/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
119 | - } |
|
120 | - |
|
121 | - } else { |
|
122 | - $paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('\\', '/', $split[1])) . '.php'; |
|
123 | - } |
|
124 | - } elseif (strpos($class, 'OCP\\') === 0) { |
|
125 | - $paths[] = \OC::$SERVERROOT . '/lib/public/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); |
|
126 | - } elseif (strpos($class, 'OCA\\') === 0) { |
|
127 | - list(, $app, $rest) = explode('\\', $class, 3); |
|
128 | - $app = strtolower($app); |
|
129 | - $appPath = \OC_App::getAppPath($app); |
|
130 | - if ($appPath && stream_resolve_include_path($appPath)) { |
|
131 | - $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
132 | - // If not found in the root of the app directory, insert '/lib' after app id and try again. |
|
133 | - $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
134 | - } |
|
135 | - } elseif (strpos($class, 'Test_') === 0) { |
|
136 | - $paths[] = \OC::$SERVERROOT . '/tests/lib/' . strtolower(str_replace('_', '/', substr($class, 5)) . '.php'); |
|
137 | - } elseif (strpos($class, 'Test\\') === 0) { |
|
138 | - $paths[] = \OC::$SERVERROOT . '/tests/lib/' . strtolower(str_replace('\\', '/', substr($class, 5)) . '.php'); |
|
139 | - } |
|
140 | - return $paths; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $fullPath |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - protected function isValidPath($fullPath) { |
|
148 | - foreach ($this->validRoots as $root => $true) { |
|
149 | - if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') { |
|
150 | - return true; |
|
151 | - } |
|
152 | - } |
|
153 | - throw new AutoloadNotAllowedException($fullPath); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load the specified class |
|
158 | - * |
|
159 | - * @param string $class |
|
160 | - * @return bool |
|
161 | - */ |
|
162 | - public function load($class) { |
|
163 | - $pathsToRequire = null; |
|
164 | - if ($this->memoryCache) { |
|
165 | - $pathsToRequire = $this->memoryCache->get($class); |
|
166 | - } |
|
167 | - |
|
168 | - if (!is_array($pathsToRequire)) { |
|
169 | - // No cache or cache miss |
|
170 | - $pathsToRequire = array(); |
|
171 | - foreach ($this->findClass($class) as $path) { |
|
172 | - $fullPath = stream_resolve_include_path($path); |
|
173 | - if ($fullPath && $this->isValidPath($fullPath)) { |
|
174 | - $pathsToRequire[] = $fullPath; |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - if ($this->memoryCache) { |
|
179 | - $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - foreach ($pathsToRequire as $fullPath) { |
|
184 | - require_once $fullPath; |
|
185 | - } |
|
186 | - |
|
187 | - return false; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Sets the optional low-latency cache for class to path mapping. |
|
192 | - * |
|
193 | - * @param \OC\Memcache\Cache $memoryCache Instance of memory cache. |
|
194 | - */ |
|
195 | - public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null) { |
|
196 | - $this->memoryCache = $memoryCache; |
|
197 | - } |
|
37 | + /** @var bool */ |
|
38 | + private $useGlobalClassPath = true; |
|
39 | + /** @var array */ |
|
40 | + private $validRoots = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * Optional low-latency memory cache for class to path mapping. |
|
44 | + * |
|
45 | + * @var \OC\Memcache\Cache |
|
46 | + */ |
|
47 | + protected $memoryCache; |
|
48 | + |
|
49 | + /** |
|
50 | + * Autoloader constructor. |
|
51 | + * |
|
52 | + * @param string[] $validRoots |
|
53 | + */ |
|
54 | + public function __construct(array $validRoots) { |
|
55 | + foreach ($validRoots as $root) { |
|
56 | + $this->validRoots[$root] = true; |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Add a path to the list of valid php roots for auto loading |
|
62 | + * |
|
63 | + * @param string $root |
|
64 | + */ |
|
65 | + public function addValidRoot($root) { |
|
66 | + $root = stream_resolve_include_path($root); |
|
67 | + $this->validRoots[$root] = true; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * disable the usage of the global classpath \OC::$CLASSPATH |
|
72 | + */ |
|
73 | + public function disableGlobalClassPath() { |
|
74 | + $this->useGlobalClassPath = false; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * enable the usage of the global classpath \OC::$CLASSPATH |
|
79 | + */ |
|
80 | + public function enableGlobalClassPath() { |
|
81 | + $this->useGlobalClassPath = true; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * get the possible paths for a class |
|
86 | + * |
|
87 | + * @param string $class |
|
88 | + * @return array|bool an array of possible paths or false if the class is not part of ownCloud |
|
89 | + */ |
|
90 | + public function findClass($class) { |
|
91 | + $class = trim($class, '\\'); |
|
92 | + |
|
93 | + $paths = array(); |
|
94 | + if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) { |
|
95 | + $paths[] = \OC::$CLASSPATH[$class]; |
|
96 | + /** |
|
97 | + * @TODO: Remove this when necessary |
|
98 | + * Remove "apps/" from inclusion path for smooth migration to mutli app dir |
|
99 | + */ |
|
100 | + if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { |
|
101 | + \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG); |
|
102 | + $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); |
|
103 | + } |
|
104 | + } elseif (strpos($class, 'OC_') === 0) { |
|
105 | + $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
106 | + $paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
107 | + } elseif (strpos($class, 'OC\\') === 0) { |
|
108 | + $split = explode('\\', $class, 3); |
|
109 | + |
|
110 | + if (count($split) === 3) { |
|
111 | + $split[1] = strtolower($split[1]); |
|
112 | + |
|
113 | + if ($split[1] === 'core') { |
|
114 | + $paths[] = \OC::$SERVERROOT . '/core/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
115 | + } else if ($split[1] === 'settings') { |
|
116 | + $paths[] = \OC::$SERVERROOT . '/settings/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
117 | + } else { |
|
118 | + $paths[] = \OC::$SERVERROOT . '/lib/private/' . $split[1] . '/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
119 | + } |
|
120 | + |
|
121 | + } else { |
|
122 | + $paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('\\', '/', $split[1])) . '.php'; |
|
123 | + } |
|
124 | + } elseif (strpos($class, 'OCP\\') === 0) { |
|
125 | + $paths[] = \OC::$SERVERROOT . '/lib/public/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); |
|
126 | + } elseif (strpos($class, 'OCA\\') === 0) { |
|
127 | + list(, $app, $rest) = explode('\\', $class, 3); |
|
128 | + $app = strtolower($app); |
|
129 | + $appPath = \OC_App::getAppPath($app); |
|
130 | + if ($appPath && stream_resolve_include_path($appPath)) { |
|
131 | + $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
132 | + // If not found in the root of the app directory, insert '/lib' after app id and try again. |
|
133 | + $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
134 | + } |
|
135 | + } elseif (strpos($class, 'Test_') === 0) { |
|
136 | + $paths[] = \OC::$SERVERROOT . '/tests/lib/' . strtolower(str_replace('_', '/', substr($class, 5)) . '.php'); |
|
137 | + } elseif (strpos($class, 'Test\\') === 0) { |
|
138 | + $paths[] = \OC::$SERVERROOT . '/tests/lib/' . strtolower(str_replace('\\', '/', substr($class, 5)) . '.php'); |
|
139 | + } |
|
140 | + return $paths; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $fullPath |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + protected function isValidPath($fullPath) { |
|
148 | + foreach ($this->validRoots as $root => $true) { |
|
149 | + if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') { |
|
150 | + return true; |
|
151 | + } |
|
152 | + } |
|
153 | + throw new AutoloadNotAllowedException($fullPath); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load the specified class |
|
158 | + * |
|
159 | + * @param string $class |
|
160 | + * @return bool |
|
161 | + */ |
|
162 | + public function load($class) { |
|
163 | + $pathsToRequire = null; |
|
164 | + if ($this->memoryCache) { |
|
165 | + $pathsToRequire = $this->memoryCache->get($class); |
|
166 | + } |
|
167 | + |
|
168 | + if (!is_array($pathsToRequire)) { |
|
169 | + // No cache or cache miss |
|
170 | + $pathsToRequire = array(); |
|
171 | + foreach ($this->findClass($class) as $path) { |
|
172 | + $fullPath = stream_resolve_include_path($path); |
|
173 | + if ($fullPath && $this->isValidPath($fullPath)) { |
|
174 | + $pathsToRequire[] = $fullPath; |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + if ($this->memoryCache) { |
|
179 | + $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + foreach ($pathsToRequire as $fullPath) { |
|
184 | + require_once $fullPath; |
|
185 | + } |
|
186 | + |
|
187 | + return false; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Sets the optional low-latency cache for class to path mapping. |
|
192 | + * |
|
193 | + * @param \OC\Memcache\Cache $memoryCache Instance of memory cache. |
|
194 | + */ |
|
195 | + public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null) { |
|
196 | + $this->memoryCache = $memoryCache; |
|
197 | + } |
|
198 | 198 | } |
@@ -98,12 +98,12 @@ discard block |
||
98 | 98 | * Remove "apps/" from inclusion path for smooth migration to mutli app dir |
99 | 99 | */ |
100 | 100 | if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { |
101 | - \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG); |
|
101 | + \OCP\Util::writeLog('core', 'include path for class "'.$class.'" starts with "apps/"', \OCP\Util::DEBUG); |
|
102 | 102 | $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); |
103 | 103 | } |
104 | 104 | } elseif (strpos($class, 'OC_') === 0) { |
105 | - $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
106 | - $paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
|
105 | + $paths[] = \OC::$SERVERROOT.'/lib/private/legacy/'.strtolower(str_replace('_', '/', substr($class, 3)).'.php'); |
|
106 | + $paths[] = \OC::$SERVERROOT.'/lib/private/'.strtolower(str_replace('_', '/', substr($class, 3)).'.php'); |
|
107 | 107 | } elseif (strpos($class, 'OC\\') === 0) { |
108 | 108 | $split = explode('\\', $class, 3); |
109 | 109 | |
@@ -111,31 +111,31 @@ discard block |
||
111 | 111 | $split[1] = strtolower($split[1]); |
112 | 112 | |
113 | 113 | if ($split[1] === 'core') { |
114 | - $paths[] = \OC::$SERVERROOT . '/core/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
114 | + $paths[] = \OC::$SERVERROOT.'/core/'.strtolower(str_replace('\\', '/', $split[2])).'.php'; |
|
115 | 115 | } else if ($split[1] === 'settings') { |
116 | - $paths[] = \OC::$SERVERROOT . '/settings/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
116 | + $paths[] = \OC::$SERVERROOT.'/settings/'.strtolower(str_replace('\\', '/', $split[2])).'.php'; |
|
117 | 117 | } else { |
118 | - $paths[] = \OC::$SERVERROOT . '/lib/private/' . $split[1] . '/' . strtolower(str_replace('\\', '/', $split[2])) . '.php'; |
|
118 | + $paths[] = \OC::$SERVERROOT.'/lib/private/'.$split[1].'/'.strtolower(str_replace('\\', '/', $split[2])).'.php'; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | } else { |
122 | - $paths[] = \OC::$SERVERROOT . '/lib/private/' . strtolower(str_replace('\\', '/', $split[1])) . '.php'; |
|
122 | + $paths[] = \OC::$SERVERROOT.'/lib/private/'.strtolower(str_replace('\\', '/', $split[1])).'.php'; |
|
123 | 123 | } |
124 | 124 | } elseif (strpos($class, 'OCP\\') === 0) { |
125 | - $paths[] = \OC::$SERVERROOT . '/lib/public/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); |
|
125 | + $paths[] = \OC::$SERVERROOT.'/lib/public/'.strtolower(str_replace('\\', '/', substr($class, 4)).'.php'); |
|
126 | 126 | } elseif (strpos($class, 'OCA\\') === 0) { |
127 | 127 | list(, $app, $rest) = explode('\\', $class, 3); |
128 | 128 | $app = strtolower($app); |
129 | 129 | $appPath = \OC_App::getAppPath($app); |
130 | 130 | if ($appPath && stream_resolve_include_path($appPath)) { |
131 | - $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
131 | + $paths[] = $appPath.'/'.strtolower(str_replace('\\', '/', $rest).'.php'); |
|
132 | 132 | // If not found in the root of the app directory, insert '/lib' after app id and try again. |
133 | - $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
|
133 | + $paths[] = $appPath.'/lib/'.strtolower(str_replace('\\', '/', $rest).'.php'); |
|
134 | 134 | } |
135 | 135 | } elseif (strpos($class, 'Test_') === 0) { |
136 | - $paths[] = \OC::$SERVERROOT . '/tests/lib/' . strtolower(str_replace('_', '/', substr($class, 5)) . '.php'); |
|
136 | + $paths[] = \OC::$SERVERROOT.'/tests/lib/'.strtolower(str_replace('_', '/', substr($class, 5)).'.php'); |
|
137 | 137 | } elseif (strpos($class, 'Test\\') === 0) { |
138 | - $paths[] = \OC::$SERVERROOT . '/tests/lib/' . strtolower(str_replace('\\', '/', substr($class, 5)) . '.php'); |
|
138 | + $paths[] = \OC::$SERVERROOT.'/tests/lib/'.strtolower(str_replace('\\', '/', substr($class, 5)).'.php'); |
|
139 | 139 | } |
140 | 140 | return $paths; |
141 | 141 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | protected function isValidPath($fullPath) { |
148 | 148 | foreach ($this->validRoots as $root => $true) { |
149 | - if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') { |
|
149 | + if (substr($fullPath, 0, strlen($root) + 1) === $root.'/') { |
|
150 | 150 | return true; |
151 | 151 | } |
152 | 152 | } |
@@ -29,201 +29,201 @@ |
||
29 | 29 | */ |
30 | 30 | |
31 | 31 | class OC_Archive_ZIP extends OC_Archive{ |
32 | - /** |
|
33 | - * @var ZipArchive zip |
|
34 | - */ |
|
35 | - private $zip=null; |
|
36 | - private $path; |
|
32 | + /** |
|
33 | + * @var ZipArchive zip |
|
34 | + */ |
|
35 | + private $zip=null; |
|
36 | + private $path; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $source |
|
40 | - */ |
|
41 | - function __construct($source) { |
|
42 | - $this->path=$source; |
|
43 | - $this->zip=new ZipArchive(); |
|
44 | - if($this->zip->open($source, ZipArchive::CREATE)) { |
|
45 | - }else{ |
|
46 | - OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, OCP\Util::WARN); |
|
47 | - } |
|
48 | - } |
|
49 | - /** |
|
50 | - * add an empty folder to the archive |
|
51 | - * @param string $path |
|
52 | - * @return bool |
|
53 | - */ |
|
54 | - function addFolder($path) { |
|
55 | - return $this->zip->addEmptyDir($path); |
|
56 | - } |
|
57 | - /** |
|
58 | - * add a file to the archive |
|
59 | - * @param string $path |
|
60 | - * @param string $source either a local file or string data |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - function addFile($path, $source='') { |
|
64 | - if($source and $source[0]=='/' and file_exists($source)) { |
|
65 | - $result=$this->zip->addFile($source, $path); |
|
66 | - }else{ |
|
67 | - $result=$this->zip->addFromString($path, $source); |
|
68 | - } |
|
69 | - if($result) { |
|
70 | - $this->zip->close();//close and reopen to save the zip |
|
71 | - $this->zip->open($this->path); |
|
72 | - } |
|
73 | - return $result; |
|
74 | - } |
|
75 | - /** |
|
76 | - * rename a file or folder in the archive |
|
77 | - * @param string $source |
|
78 | - * @param string $dest |
|
79 | - * @return boolean|null |
|
80 | - */ |
|
81 | - function rename($source, $dest) { |
|
82 | - $source=$this->stripPath($source); |
|
83 | - $dest=$this->stripPath($dest); |
|
84 | - $this->zip->renameName($source, $dest); |
|
85 | - } |
|
86 | - /** |
|
87 | - * get the uncompressed size of a file in the archive |
|
88 | - * @param string $path |
|
89 | - * @return int |
|
90 | - */ |
|
91 | - function filesize($path) { |
|
92 | - $stat=$this->zip->statName($path); |
|
93 | - return $stat['size']; |
|
94 | - } |
|
95 | - /** |
|
96 | - * get the last modified time of a file in the archive |
|
97 | - * @param string $path |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - function mtime($path) { |
|
101 | - return filemtime($this->path); |
|
102 | - } |
|
103 | - /** |
|
104 | - * get the files in a folder |
|
105 | - * @param string $path |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - function getFolder($path) { |
|
109 | - $files=$this->getFiles(); |
|
110 | - $folderContent=array(); |
|
111 | - $pathLength=strlen($path); |
|
112 | - foreach($files as $file) { |
|
113 | - if(substr($file, 0, $pathLength)==$path and $file!=$path) { |
|
114 | - if(strrpos(substr($file, 0, -1), '/')<=$pathLength) { |
|
115 | - $folderContent[]=substr($file, $pathLength); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - return $folderContent; |
|
120 | - } |
|
121 | - /** |
|
122 | - * get all files in the archive |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - function getFiles() { |
|
126 | - $fileCount=$this->zip->numFiles; |
|
127 | - $files=array(); |
|
128 | - for($i=0;$i<$fileCount;$i++) { |
|
129 | - $files[]=$this->zip->getNameIndex($i); |
|
130 | - } |
|
131 | - return $files; |
|
132 | - } |
|
133 | - /** |
|
134 | - * get the content of a file |
|
135 | - * @param string $path |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - function getFile($path) { |
|
139 | - return $this->zip->getFromName($path); |
|
140 | - } |
|
141 | - /** |
|
142 | - * extract a single file from the archive |
|
143 | - * @param string $path |
|
144 | - * @param string $dest |
|
145 | - * @return boolean|null |
|
146 | - */ |
|
147 | - function extractFile($path, $dest) { |
|
148 | - $fp = $this->zip->getStream($path); |
|
149 | - file_put_contents($dest, $fp); |
|
150 | - } |
|
151 | - /** |
|
152 | - * extract the archive |
|
153 | - * @param string $dest |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - function extract($dest) { |
|
157 | - return $this->zip->extractTo($dest); |
|
158 | - } |
|
159 | - /** |
|
160 | - * check if a file or folder exists in the archive |
|
161 | - * @param string $path |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - function fileExists($path) { |
|
165 | - return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false); |
|
166 | - } |
|
167 | - /** |
|
168 | - * remove a file or folder from the archive |
|
169 | - * @param string $path |
|
170 | - * @return bool |
|
171 | - */ |
|
172 | - function remove($path) { |
|
173 | - if($this->fileExists($path.'/')) { |
|
174 | - return $this->zip->deleteName($path.'/'); |
|
175 | - }else{ |
|
176 | - return $this->zip->deleteName($path); |
|
177 | - } |
|
178 | - } |
|
179 | - /** |
|
180 | - * get a file handler |
|
181 | - * @param string $path |
|
182 | - * @param string $mode |
|
183 | - * @return resource |
|
184 | - */ |
|
185 | - function getStream($path, $mode) { |
|
186 | - if($mode=='r' or $mode=='rb') { |
|
187 | - return $this->zip->getStream($path); |
|
188 | - } else { |
|
189 | - //since we cant directly get a writable stream, |
|
190 | - //make a temp copy of the file and put it back |
|
191 | - //in the archive when the stream is closed |
|
192 | - if(strrpos($path, '.')!==false) { |
|
193 | - $ext=substr($path, strrpos($path, '.')); |
|
194 | - }else{ |
|
195 | - $ext=''; |
|
196 | - } |
|
197 | - $tmpFile=OCP\Files::tmpFile($ext); |
|
198 | - \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); |
|
199 | - if($this->fileExists($path)) { |
|
200 | - $this->extractFile($path, $tmpFile); |
|
201 | - } |
|
202 | - self::$tempFiles[$tmpFile]=$path; |
|
203 | - return fopen('close://'.$tmpFile, $mode); |
|
204 | - } |
|
205 | - } |
|
38 | + /** |
|
39 | + * @param string $source |
|
40 | + */ |
|
41 | + function __construct($source) { |
|
42 | + $this->path=$source; |
|
43 | + $this->zip=new ZipArchive(); |
|
44 | + if($this->zip->open($source, ZipArchive::CREATE)) { |
|
45 | + }else{ |
|
46 | + OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, OCP\Util::WARN); |
|
47 | + } |
|
48 | + } |
|
49 | + /** |
|
50 | + * add an empty folder to the archive |
|
51 | + * @param string $path |
|
52 | + * @return bool |
|
53 | + */ |
|
54 | + function addFolder($path) { |
|
55 | + return $this->zip->addEmptyDir($path); |
|
56 | + } |
|
57 | + /** |
|
58 | + * add a file to the archive |
|
59 | + * @param string $path |
|
60 | + * @param string $source either a local file or string data |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + function addFile($path, $source='') { |
|
64 | + if($source and $source[0]=='/' and file_exists($source)) { |
|
65 | + $result=$this->zip->addFile($source, $path); |
|
66 | + }else{ |
|
67 | + $result=$this->zip->addFromString($path, $source); |
|
68 | + } |
|
69 | + if($result) { |
|
70 | + $this->zip->close();//close and reopen to save the zip |
|
71 | + $this->zip->open($this->path); |
|
72 | + } |
|
73 | + return $result; |
|
74 | + } |
|
75 | + /** |
|
76 | + * rename a file or folder in the archive |
|
77 | + * @param string $source |
|
78 | + * @param string $dest |
|
79 | + * @return boolean|null |
|
80 | + */ |
|
81 | + function rename($source, $dest) { |
|
82 | + $source=$this->stripPath($source); |
|
83 | + $dest=$this->stripPath($dest); |
|
84 | + $this->zip->renameName($source, $dest); |
|
85 | + } |
|
86 | + /** |
|
87 | + * get the uncompressed size of a file in the archive |
|
88 | + * @param string $path |
|
89 | + * @return int |
|
90 | + */ |
|
91 | + function filesize($path) { |
|
92 | + $stat=$this->zip->statName($path); |
|
93 | + return $stat['size']; |
|
94 | + } |
|
95 | + /** |
|
96 | + * get the last modified time of a file in the archive |
|
97 | + * @param string $path |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + function mtime($path) { |
|
101 | + return filemtime($this->path); |
|
102 | + } |
|
103 | + /** |
|
104 | + * get the files in a folder |
|
105 | + * @param string $path |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + function getFolder($path) { |
|
109 | + $files=$this->getFiles(); |
|
110 | + $folderContent=array(); |
|
111 | + $pathLength=strlen($path); |
|
112 | + foreach($files as $file) { |
|
113 | + if(substr($file, 0, $pathLength)==$path and $file!=$path) { |
|
114 | + if(strrpos(substr($file, 0, -1), '/')<=$pathLength) { |
|
115 | + $folderContent[]=substr($file, $pathLength); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + return $folderContent; |
|
120 | + } |
|
121 | + /** |
|
122 | + * get all files in the archive |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + function getFiles() { |
|
126 | + $fileCount=$this->zip->numFiles; |
|
127 | + $files=array(); |
|
128 | + for($i=0;$i<$fileCount;$i++) { |
|
129 | + $files[]=$this->zip->getNameIndex($i); |
|
130 | + } |
|
131 | + return $files; |
|
132 | + } |
|
133 | + /** |
|
134 | + * get the content of a file |
|
135 | + * @param string $path |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + function getFile($path) { |
|
139 | + return $this->zip->getFromName($path); |
|
140 | + } |
|
141 | + /** |
|
142 | + * extract a single file from the archive |
|
143 | + * @param string $path |
|
144 | + * @param string $dest |
|
145 | + * @return boolean|null |
|
146 | + */ |
|
147 | + function extractFile($path, $dest) { |
|
148 | + $fp = $this->zip->getStream($path); |
|
149 | + file_put_contents($dest, $fp); |
|
150 | + } |
|
151 | + /** |
|
152 | + * extract the archive |
|
153 | + * @param string $dest |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + function extract($dest) { |
|
157 | + return $this->zip->extractTo($dest); |
|
158 | + } |
|
159 | + /** |
|
160 | + * check if a file or folder exists in the archive |
|
161 | + * @param string $path |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + function fileExists($path) { |
|
165 | + return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false); |
|
166 | + } |
|
167 | + /** |
|
168 | + * remove a file or folder from the archive |
|
169 | + * @param string $path |
|
170 | + * @return bool |
|
171 | + */ |
|
172 | + function remove($path) { |
|
173 | + if($this->fileExists($path.'/')) { |
|
174 | + return $this->zip->deleteName($path.'/'); |
|
175 | + }else{ |
|
176 | + return $this->zip->deleteName($path); |
|
177 | + } |
|
178 | + } |
|
179 | + /** |
|
180 | + * get a file handler |
|
181 | + * @param string $path |
|
182 | + * @param string $mode |
|
183 | + * @return resource |
|
184 | + */ |
|
185 | + function getStream($path, $mode) { |
|
186 | + if($mode=='r' or $mode=='rb') { |
|
187 | + return $this->zip->getStream($path); |
|
188 | + } else { |
|
189 | + //since we cant directly get a writable stream, |
|
190 | + //make a temp copy of the file and put it back |
|
191 | + //in the archive when the stream is closed |
|
192 | + if(strrpos($path, '.')!==false) { |
|
193 | + $ext=substr($path, strrpos($path, '.')); |
|
194 | + }else{ |
|
195 | + $ext=''; |
|
196 | + } |
|
197 | + $tmpFile=OCP\Files::tmpFile($ext); |
|
198 | + \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); |
|
199 | + if($this->fileExists($path)) { |
|
200 | + $this->extractFile($path, $tmpFile); |
|
201 | + } |
|
202 | + self::$tempFiles[$tmpFile]=$path; |
|
203 | + return fopen('close://'.$tmpFile, $mode); |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - private static $tempFiles=array(); |
|
208 | - /** |
|
209 | - * write back temporary files |
|
210 | - */ |
|
211 | - function writeBack($tmpFile) { |
|
212 | - if(isset(self::$tempFiles[$tmpFile])) { |
|
213 | - $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); |
|
214 | - unlink($tmpFile); |
|
215 | - } |
|
216 | - } |
|
207 | + private static $tempFiles=array(); |
|
208 | + /** |
|
209 | + * write back temporary files |
|
210 | + */ |
|
211 | + function writeBack($tmpFile) { |
|
212 | + if(isset(self::$tempFiles[$tmpFile])) { |
|
213 | + $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); |
|
214 | + unlink($tmpFile); |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @param string $path |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - private function stripPath($path) { |
|
223 | - if(!$path || $path[0]=='/') { |
|
224 | - return substr($path, 1); |
|
225 | - }else{ |
|
226 | - return $path; |
|
227 | - } |
|
228 | - } |
|
218 | + /** |
|
219 | + * @param string $path |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + private function stripPath($path) { |
|
223 | + if(!$path || $path[0]=='/') { |
|
224 | + return substr($path, 1); |
|
225 | + }else{ |
|
226 | + return $path; |
|
227 | + } |
|
228 | + } |
|
229 | 229 | } |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | * |
29 | 29 | */ |
30 | 30 | |
31 | -class OC_Archive_ZIP extends OC_Archive{ |
|
31 | +class OC_Archive_ZIP extends OC_Archive { |
|
32 | 32 | /** |
33 | 33 | * @var ZipArchive zip |
34 | 34 | */ |
35 | - private $zip=null; |
|
35 | + private $zip = null; |
|
36 | 36 | private $path; |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param string $source |
40 | 40 | */ |
41 | 41 | function __construct($source) { |
42 | - $this->path=$source; |
|
43 | - $this->zip=new ZipArchive(); |
|
44 | - if($this->zip->open($source, ZipArchive::CREATE)) { |
|
45 | - }else{ |
|
42 | + $this->path = $source; |
|
43 | + $this->zip = new ZipArchive(); |
|
44 | + if ($this->zip->open($source, ZipArchive::CREATE)) { |
|
45 | + } else { |
|
46 | 46 | OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, OCP\Util::WARN); |
47 | 47 | } |
48 | 48 | } |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * @param string $source either a local file or string data |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | - function addFile($path, $source='') { |
|
64 | - if($source and $source[0]=='/' and file_exists($source)) { |
|
65 | - $result=$this->zip->addFile($source, $path); |
|
66 | - }else{ |
|
67 | - $result=$this->zip->addFromString($path, $source); |
|
63 | + function addFile($path, $source = '') { |
|
64 | + if ($source and $source[0] == '/' and file_exists($source)) { |
|
65 | + $result = $this->zip->addFile($source, $path); |
|
66 | + } else { |
|
67 | + $result = $this->zip->addFromString($path, $source); |
|
68 | 68 | } |
69 | - if($result) { |
|
70 | - $this->zip->close();//close and reopen to save the zip |
|
69 | + if ($result) { |
|
70 | + $this->zip->close(); //close and reopen to save the zip |
|
71 | 71 | $this->zip->open($this->path); |
72 | 72 | } |
73 | 73 | return $result; |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * @return boolean|null |
80 | 80 | */ |
81 | 81 | function rename($source, $dest) { |
82 | - $source=$this->stripPath($source); |
|
83 | - $dest=$this->stripPath($dest); |
|
82 | + $source = $this->stripPath($source); |
|
83 | + $dest = $this->stripPath($dest); |
|
84 | 84 | $this->zip->renameName($source, $dest); |
85 | 85 | } |
86 | 86 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return int |
90 | 90 | */ |
91 | 91 | function filesize($path) { |
92 | - $stat=$this->zip->statName($path); |
|
92 | + $stat = $this->zip->statName($path); |
|
93 | 93 | return $stat['size']; |
94 | 94 | } |
95 | 95 | /** |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | * @return array |
107 | 107 | */ |
108 | 108 | function getFolder($path) { |
109 | - $files=$this->getFiles(); |
|
110 | - $folderContent=array(); |
|
111 | - $pathLength=strlen($path); |
|
112 | - foreach($files as $file) { |
|
113 | - if(substr($file, 0, $pathLength)==$path and $file!=$path) { |
|
114 | - if(strrpos(substr($file, 0, -1), '/')<=$pathLength) { |
|
115 | - $folderContent[]=substr($file, $pathLength); |
|
109 | + $files = $this->getFiles(); |
|
110 | + $folderContent = array(); |
|
111 | + $pathLength = strlen($path); |
|
112 | + foreach ($files as $file) { |
|
113 | + if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
114 | + if (strrpos(substr($file, 0, -1), '/') <= $pathLength) { |
|
115 | + $folderContent[] = substr($file, $pathLength); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | * @return array |
124 | 124 | */ |
125 | 125 | function getFiles() { |
126 | - $fileCount=$this->zip->numFiles; |
|
127 | - $files=array(); |
|
128 | - for($i=0;$i<$fileCount;$i++) { |
|
129 | - $files[]=$this->zip->getNameIndex($i); |
|
126 | + $fileCount = $this->zip->numFiles; |
|
127 | + $files = array(); |
|
128 | + for ($i = 0; $i < $fileCount; $i++) { |
|
129 | + $files[] = $this->zip->getNameIndex($i); |
|
130 | 130 | } |
131 | 131 | return $files; |
132 | 132 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @return bool |
163 | 163 | */ |
164 | 164 | function fileExists($path) { |
165 | - return ($this->zip->locateName($path)!==false) or ($this->zip->locateName($path.'/')!==false); |
|
165 | + return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path.'/') !== false); |
|
166 | 166 | } |
167 | 167 | /** |
168 | 168 | * remove a file or folder from the archive |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | function remove($path) { |
173 | - if($this->fileExists($path.'/')) { |
|
173 | + if ($this->fileExists($path.'/')) { |
|
174 | 174 | return $this->zip->deleteName($path.'/'); |
175 | - }else{ |
|
175 | + } else { |
|
176 | 176 | return $this->zip->deleteName($path); |
177 | 177 | } |
178 | 178 | } |
@@ -183,33 +183,33 @@ discard block |
||
183 | 183 | * @return resource |
184 | 184 | */ |
185 | 185 | function getStream($path, $mode) { |
186 | - if($mode=='r' or $mode=='rb') { |
|
186 | + if ($mode == 'r' or $mode == 'rb') { |
|
187 | 187 | return $this->zip->getStream($path); |
188 | 188 | } else { |
189 | 189 | //since we cant directly get a writable stream, |
190 | 190 | //make a temp copy of the file and put it back |
191 | 191 | //in the archive when the stream is closed |
192 | - if(strrpos($path, '.')!==false) { |
|
193 | - $ext=substr($path, strrpos($path, '.')); |
|
194 | - }else{ |
|
195 | - $ext=''; |
|
192 | + if (strrpos($path, '.') !== false) { |
|
193 | + $ext = substr($path, strrpos($path, '.')); |
|
194 | + } else { |
|
195 | + $ext = ''; |
|
196 | 196 | } |
197 | - $tmpFile=OCP\Files::tmpFile($ext); |
|
197 | + $tmpFile = OCP\Files::tmpFile($ext); |
|
198 | 198 | \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); |
199 | - if($this->fileExists($path)) { |
|
199 | + if ($this->fileExists($path)) { |
|
200 | 200 | $this->extractFile($path, $tmpFile); |
201 | 201 | } |
202 | - self::$tempFiles[$tmpFile]=$path; |
|
202 | + self::$tempFiles[$tmpFile] = $path; |
|
203 | 203 | return fopen('close://'.$tmpFile, $mode); |
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | - private static $tempFiles=array(); |
|
207 | + private static $tempFiles = array(); |
|
208 | 208 | /** |
209 | 209 | * write back temporary files |
210 | 210 | */ |
211 | 211 | function writeBack($tmpFile) { |
212 | - if(isset(self::$tempFiles[$tmpFile])) { |
|
212 | + if (isset(self::$tempFiles[$tmpFile])) { |
|
213 | 213 | $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); |
214 | 214 | unlink($tmpFile); |
215 | 215 | } |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | * @return string |
221 | 221 | */ |
222 | 222 | private function stripPath($path) { |
223 | - if(!$path || $path[0]=='/') { |
|
223 | + if (!$path || $path[0] == '/') { |
|
224 | 224 | return substr($path, 1); |
225 | - }else{ |
|
225 | + } else { |
|
226 | 226 | return $path; |
227 | 227 | } |
228 | 228 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $this->path=$source; |
43 | 43 | $this->zip=new ZipArchive(); |
44 | 44 | if($this->zip->open($source, ZipArchive::CREATE)) { |
45 | - }else{ |
|
45 | + } else{ |
|
46 | 46 | OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, OCP\Util::WARN); |
47 | 47 | } |
48 | 48 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | function addFile($path, $source='') { |
64 | 64 | if($source and $source[0]=='/' and file_exists($source)) { |
65 | 65 | $result=$this->zip->addFile($source, $path); |
66 | - }else{ |
|
66 | + } else{ |
|
67 | 67 | $result=$this->zip->addFromString($path, $source); |
68 | 68 | } |
69 | 69 | if($result) { |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | function remove($path) { |
173 | 173 | if($this->fileExists($path.'/')) { |
174 | 174 | return $this->zip->deleteName($path.'/'); |
175 | - }else{ |
|
175 | + } else{ |
|
176 | 176 | return $this->zip->deleteName($path); |
177 | 177 | } |
178 | 178 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | //in the archive when the stream is closed |
192 | 192 | if(strrpos($path, '.')!==false) { |
193 | 193 | $ext=substr($path, strrpos($path, '.')); |
194 | - }else{ |
|
194 | + } else{ |
|
195 | 195 | $ext=''; |
196 | 196 | } |
197 | 197 | $tmpFile=OCP\Files::tmpFile($ext); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | private function stripPath($path) { |
223 | 223 | if(!$path || $path[0]=='/') { |
224 | 224 | return substr($path, 1); |
225 | - }else{ |
|
225 | + } else{ |
|
226 | 226 | return $path; |
227 | 227 | } |
228 | 228 | } |
@@ -32,358 +32,358 @@ |
||
32 | 32 | */ |
33 | 33 | |
34 | 34 | class OC_Archive_TAR extends OC_Archive { |
35 | - const PLAIN = 0; |
|
36 | - const GZIP = 1; |
|
37 | - const BZIP = 2; |
|
35 | + const PLAIN = 0; |
|
36 | + const GZIP = 1; |
|
37 | + const BZIP = 2; |
|
38 | 38 | |
39 | - private $fileList; |
|
40 | - private $cachedHeaders; |
|
39 | + private $fileList; |
|
40 | + private $cachedHeaders; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var Archive_Tar tar |
|
44 | - */ |
|
45 | - private $tar = null; |
|
46 | - private $path; |
|
42 | + /** |
|
43 | + * @var Archive_Tar tar |
|
44 | + */ |
|
45 | + private $tar = null; |
|
46 | + private $path; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $source |
|
50 | - */ |
|
51 | - function __construct($source) { |
|
52 | - $types = array(null, 'gz', 'bz2'); |
|
53 | - $this->path = $source; |
|
54 | - $this->tar = new Archive_Tar($source, $types[self::getTarType($source)]); |
|
55 | - } |
|
48 | + /** |
|
49 | + * @param string $source |
|
50 | + */ |
|
51 | + function __construct($source) { |
|
52 | + $types = array(null, 'gz', 'bz2'); |
|
53 | + $this->path = $source; |
|
54 | + $this->tar = new Archive_Tar($source, $types[self::getTarType($source)]); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * try to detect the type of tar compression |
|
59 | - * |
|
60 | - * @param string $file |
|
61 | - * @return integer |
|
62 | - */ |
|
63 | - static public function getTarType($file) { |
|
64 | - if (strpos($file, '.')) { |
|
65 | - $extension = substr($file, strrpos($file, '.')); |
|
66 | - switch ($extension) { |
|
67 | - case '.gz': |
|
68 | - case '.tgz': |
|
69 | - return self::GZIP; |
|
70 | - case '.bz': |
|
71 | - case '.bz2': |
|
72 | - return self::BZIP; |
|
73 | - case '.tar': |
|
74 | - return self::PLAIN; |
|
75 | - default: |
|
76 | - return self::PLAIN; |
|
77 | - } |
|
78 | - } else { |
|
79 | - return self::PLAIN; |
|
80 | - } |
|
81 | - } |
|
57 | + /** |
|
58 | + * try to detect the type of tar compression |
|
59 | + * |
|
60 | + * @param string $file |
|
61 | + * @return integer |
|
62 | + */ |
|
63 | + static public function getTarType($file) { |
|
64 | + if (strpos($file, '.')) { |
|
65 | + $extension = substr($file, strrpos($file, '.')); |
|
66 | + switch ($extension) { |
|
67 | + case '.gz': |
|
68 | + case '.tgz': |
|
69 | + return self::GZIP; |
|
70 | + case '.bz': |
|
71 | + case '.bz2': |
|
72 | + return self::BZIP; |
|
73 | + case '.tar': |
|
74 | + return self::PLAIN; |
|
75 | + default: |
|
76 | + return self::PLAIN; |
|
77 | + } |
|
78 | + } else { |
|
79 | + return self::PLAIN; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * add an empty folder to the archive |
|
85 | - * |
|
86 | - * @param string $path |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - function addFolder($path) { |
|
90 | - $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
91 | - if (substr($path, -1, 1) != '/') { |
|
92 | - $path .= '/'; |
|
93 | - } |
|
94 | - if ($this->fileExists($path)) { |
|
95 | - return false; |
|
96 | - } |
|
97 | - $parts = explode('/', $path); |
|
98 | - $folder = $tmpBase; |
|
99 | - foreach ($parts as $part) { |
|
100 | - $folder .= '/' . $part; |
|
101 | - if (!is_dir($folder)) { |
|
102 | - mkdir($folder); |
|
103 | - } |
|
104 | - } |
|
105 | - $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
106 | - rmdir($tmpBase . $path); |
|
107 | - $this->fileList = false; |
|
108 | - $this->cachedHeaders = false; |
|
109 | - return $result; |
|
110 | - } |
|
83 | + /** |
|
84 | + * add an empty folder to the archive |
|
85 | + * |
|
86 | + * @param string $path |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + function addFolder($path) { |
|
90 | + $tmpBase = \OC::$server->getTempManager()->getTemporaryFolder(); |
|
91 | + if (substr($path, -1, 1) != '/') { |
|
92 | + $path .= '/'; |
|
93 | + } |
|
94 | + if ($this->fileExists($path)) { |
|
95 | + return false; |
|
96 | + } |
|
97 | + $parts = explode('/', $path); |
|
98 | + $folder = $tmpBase; |
|
99 | + foreach ($parts as $part) { |
|
100 | + $folder .= '/' . $part; |
|
101 | + if (!is_dir($folder)) { |
|
102 | + mkdir($folder); |
|
103 | + } |
|
104 | + } |
|
105 | + $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
106 | + rmdir($tmpBase . $path); |
|
107 | + $this->fileList = false; |
|
108 | + $this->cachedHeaders = false; |
|
109 | + return $result; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * add a file to the archive |
|
114 | - * |
|
115 | - * @param string $path |
|
116 | - * @param string $source either a local file or string data |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - function addFile($path, $source = '') { |
|
120 | - if ($this->fileExists($path)) { |
|
121 | - $this->remove($path); |
|
122 | - } |
|
123 | - if ($source and $source[0] == '/' and file_exists($source)) { |
|
124 | - $source = file_get_contents($source); |
|
125 | - } |
|
126 | - $result = $this->tar->addString($path, $source); |
|
127 | - $this->fileList = false; |
|
128 | - $this->cachedHeaders = false; |
|
129 | - return $result; |
|
130 | - } |
|
112 | + /** |
|
113 | + * add a file to the archive |
|
114 | + * |
|
115 | + * @param string $path |
|
116 | + * @param string $source either a local file or string data |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + function addFile($path, $source = '') { |
|
120 | + if ($this->fileExists($path)) { |
|
121 | + $this->remove($path); |
|
122 | + } |
|
123 | + if ($source and $source[0] == '/' and file_exists($source)) { |
|
124 | + $source = file_get_contents($source); |
|
125 | + } |
|
126 | + $result = $this->tar->addString($path, $source); |
|
127 | + $this->fileList = false; |
|
128 | + $this->cachedHeaders = false; |
|
129 | + return $result; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * rename a file or folder in the archive |
|
134 | - * |
|
135 | - * @param string $source |
|
136 | - * @param string $dest |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - function rename($source, $dest) { |
|
140 | - //no proper way to delete, rename entire archive, rename file and remake archive |
|
141 | - $tmp = OCP\Files::tmpFolder(); |
|
142 | - $this->tar->extract($tmp); |
|
143 | - rename($tmp . $source, $tmp . $dest); |
|
144 | - $this->tar = null; |
|
145 | - unlink($this->path); |
|
146 | - $types = array(null, 'gz', 'bz'); |
|
147 | - $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
148 | - $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
149 | - $this->fileList = false; |
|
150 | - $this->cachedHeaders = false; |
|
151 | - return true; |
|
152 | - } |
|
132 | + /** |
|
133 | + * rename a file or folder in the archive |
|
134 | + * |
|
135 | + * @param string $source |
|
136 | + * @param string $dest |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + function rename($source, $dest) { |
|
140 | + //no proper way to delete, rename entire archive, rename file and remake archive |
|
141 | + $tmp = OCP\Files::tmpFolder(); |
|
142 | + $this->tar->extract($tmp); |
|
143 | + rename($tmp . $source, $tmp . $dest); |
|
144 | + $this->tar = null; |
|
145 | + unlink($this->path); |
|
146 | + $types = array(null, 'gz', 'bz'); |
|
147 | + $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
148 | + $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
149 | + $this->fileList = false; |
|
150 | + $this->cachedHeaders = false; |
|
151 | + return true; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @param string $file |
|
156 | - */ |
|
157 | - private function getHeader($file) { |
|
158 | - if (!$this->cachedHeaders) { |
|
159 | - $this->cachedHeaders = $this->tar->listContent(); |
|
160 | - } |
|
161 | - foreach ($this->cachedHeaders as $header) { |
|
162 | - if ($file == $header['filename'] |
|
163 | - or $file . '/' == $header['filename'] |
|
164 | - or '/' . $file . '/' == $header['filename'] |
|
165 | - or '/' . $file == $header['filename'] |
|
166 | - ) { |
|
167 | - return $header; |
|
168 | - } |
|
169 | - } |
|
170 | - return null; |
|
171 | - } |
|
154 | + /** |
|
155 | + * @param string $file |
|
156 | + */ |
|
157 | + private function getHeader($file) { |
|
158 | + if (!$this->cachedHeaders) { |
|
159 | + $this->cachedHeaders = $this->tar->listContent(); |
|
160 | + } |
|
161 | + foreach ($this->cachedHeaders as $header) { |
|
162 | + if ($file == $header['filename'] |
|
163 | + or $file . '/' == $header['filename'] |
|
164 | + or '/' . $file . '/' == $header['filename'] |
|
165 | + or '/' . $file == $header['filename'] |
|
166 | + ) { |
|
167 | + return $header; |
|
168 | + } |
|
169 | + } |
|
170 | + return null; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * get the uncompressed size of a file in the archive |
|
175 | - * |
|
176 | - * @param string $path |
|
177 | - * @return int |
|
178 | - */ |
|
179 | - function filesize($path) { |
|
180 | - $stat = $this->getHeader($path); |
|
181 | - return $stat['size']; |
|
182 | - } |
|
173 | + /** |
|
174 | + * get the uncompressed size of a file in the archive |
|
175 | + * |
|
176 | + * @param string $path |
|
177 | + * @return int |
|
178 | + */ |
|
179 | + function filesize($path) { |
|
180 | + $stat = $this->getHeader($path); |
|
181 | + return $stat['size']; |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * get the last modified time of a file in the archive |
|
186 | - * |
|
187 | - * @param string $path |
|
188 | - * @return int |
|
189 | - */ |
|
190 | - function mtime($path) { |
|
191 | - $stat = $this->getHeader($path); |
|
192 | - return $stat['mtime']; |
|
193 | - } |
|
184 | + /** |
|
185 | + * get the last modified time of a file in the archive |
|
186 | + * |
|
187 | + * @param string $path |
|
188 | + * @return int |
|
189 | + */ |
|
190 | + function mtime($path) { |
|
191 | + $stat = $this->getHeader($path); |
|
192 | + return $stat['mtime']; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * get the files in a folder |
|
197 | - * |
|
198 | - * @param string $path |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - function getFolder($path) { |
|
202 | - $files = $this->getFiles(); |
|
203 | - $folderContent = array(); |
|
204 | - $pathLength = strlen($path); |
|
205 | - foreach ($files as $file) { |
|
206 | - if ($file[0] == '/') { |
|
207 | - $file = substr($file, 1); |
|
208 | - } |
|
209 | - if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
210 | - $result = substr($file, $pathLength); |
|
211 | - if ($pos = strpos($result, '/')) { |
|
212 | - $result = substr($result, 0, $pos + 1); |
|
213 | - } |
|
214 | - if (array_search($result, $folderContent) === false) { |
|
215 | - $folderContent[] = $result; |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - return $folderContent; |
|
220 | - } |
|
195 | + /** |
|
196 | + * get the files in a folder |
|
197 | + * |
|
198 | + * @param string $path |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + function getFolder($path) { |
|
202 | + $files = $this->getFiles(); |
|
203 | + $folderContent = array(); |
|
204 | + $pathLength = strlen($path); |
|
205 | + foreach ($files as $file) { |
|
206 | + if ($file[0] == '/') { |
|
207 | + $file = substr($file, 1); |
|
208 | + } |
|
209 | + if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
210 | + $result = substr($file, $pathLength); |
|
211 | + if ($pos = strpos($result, '/')) { |
|
212 | + $result = substr($result, 0, $pos + 1); |
|
213 | + } |
|
214 | + if (array_search($result, $folderContent) === false) { |
|
215 | + $folderContent[] = $result; |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + return $folderContent; |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * get all files in the archive |
|
224 | - * |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - function getFiles() { |
|
228 | - if ($this->fileList) { |
|
229 | - return $this->fileList; |
|
230 | - } |
|
231 | - if (!$this->cachedHeaders) { |
|
232 | - $this->cachedHeaders = $this->tar->listContent(); |
|
233 | - } |
|
234 | - $files = array(); |
|
235 | - foreach ($this->cachedHeaders as $header) { |
|
236 | - $files[] = $header['filename']; |
|
237 | - } |
|
238 | - $this->fileList = $files; |
|
239 | - return $files; |
|
240 | - } |
|
222 | + /** |
|
223 | + * get all files in the archive |
|
224 | + * |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + function getFiles() { |
|
228 | + if ($this->fileList) { |
|
229 | + return $this->fileList; |
|
230 | + } |
|
231 | + if (!$this->cachedHeaders) { |
|
232 | + $this->cachedHeaders = $this->tar->listContent(); |
|
233 | + } |
|
234 | + $files = array(); |
|
235 | + foreach ($this->cachedHeaders as $header) { |
|
236 | + $files[] = $header['filename']; |
|
237 | + } |
|
238 | + $this->fileList = $files; |
|
239 | + return $files; |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * get the content of a file |
|
244 | - * |
|
245 | - * @param string $path |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - function getFile($path) { |
|
249 | - return $this->tar->extractInString($path); |
|
250 | - } |
|
242 | + /** |
|
243 | + * get the content of a file |
|
244 | + * |
|
245 | + * @param string $path |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + function getFile($path) { |
|
249 | + return $this->tar->extractInString($path); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * extract a single file from the archive |
|
254 | - * |
|
255 | - * @param string $path |
|
256 | - * @param string $dest |
|
257 | - * @return bool |
|
258 | - */ |
|
259 | - function extractFile($path, $dest) { |
|
260 | - $tmp = OCP\Files::tmpFolder(); |
|
261 | - if (!$this->fileExists($path)) { |
|
262 | - return false; |
|
263 | - } |
|
264 | - if ($this->fileExists('/' . $path)) { |
|
265 | - $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
266 | - } else { |
|
267 | - $success = $this->tar->extractList(array($path), $tmp); |
|
268 | - } |
|
269 | - if ($success) { |
|
270 | - rename($tmp . $path, $dest); |
|
271 | - } |
|
272 | - OCP\Files::rmdirr($tmp); |
|
273 | - return $success; |
|
274 | - } |
|
252 | + /** |
|
253 | + * extract a single file from the archive |
|
254 | + * |
|
255 | + * @param string $path |
|
256 | + * @param string $dest |
|
257 | + * @return bool |
|
258 | + */ |
|
259 | + function extractFile($path, $dest) { |
|
260 | + $tmp = OCP\Files::tmpFolder(); |
|
261 | + if (!$this->fileExists($path)) { |
|
262 | + return false; |
|
263 | + } |
|
264 | + if ($this->fileExists('/' . $path)) { |
|
265 | + $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
266 | + } else { |
|
267 | + $success = $this->tar->extractList(array($path), $tmp); |
|
268 | + } |
|
269 | + if ($success) { |
|
270 | + rename($tmp . $path, $dest); |
|
271 | + } |
|
272 | + OCP\Files::rmdirr($tmp); |
|
273 | + return $success; |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * extract the archive |
|
278 | - * |
|
279 | - * @param string $dest |
|
280 | - * @return bool |
|
281 | - */ |
|
282 | - function extract($dest) { |
|
283 | - return $this->tar->extract($dest); |
|
284 | - } |
|
276 | + /** |
|
277 | + * extract the archive |
|
278 | + * |
|
279 | + * @param string $dest |
|
280 | + * @return bool |
|
281 | + */ |
|
282 | + function extract($dest) { |
|
283 | + return $this->tar->extract($dest); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * check if a file or folder exists in the archive |
|
288 | - * |
|
289 | - * @param string $path |
|
290 | - * @return bool |
|
291 | - */ |
|
292 | - function fileExists($path) { |
|
293 | - $files = $this->getFiles(); |
|
294 | - if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
295 | - return true; |
|
296 | - } else { |
|
297 | - $folderPath = $path; |
|
298 | - if (substr($folderPath, -1, 1) != '/') { |
|
299 | - $folderPath .= '/'; |
|
300 | - } |
|
301 | - $pathLength = strlen($folderPath); |
|
302 | - foreach ($files as $file) { |
|
303 | - if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) { |
|
304 | - return true; |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - if ($path[0] != '/') { //not all programs agree on the use of a leading / |
|
309 | - return $this->fileExists('/' . $path); |
|
310 | - } else { |
|
311 | - return false; |
|
312 | - } |
|
313 | - } |
|
286 | + /** |
|
287 | + * check if a file or folder exists in the archive |
|
288 | + * |
|
289 | + * @param string $path |
|
290 | + * @return bool |
|
291 | + */ |
|
292 | + function fileExists($path) { |
|
293 | + $files = $this->getFiles(); |
|
294 | + if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
295 | + return true; |
|
296 | + } else { |
|
297 | + $folderPath = $path; |
|
298 | + if (substr($folderPath, -1, 1) != '/') { |
|
299 | + $folderPath .= '/'; |
|
300 | + } |
|
301 | + $pathLength = strlen($folderPath); |
|
302 | + foreach ($files as $file) { |
|
303 | + if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) { |
|
304 | + return true; |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + if ($path[0] != '/') { //not all programs agree on the use of a leading / |
|
309 | + return $this->fileExists('/' . $path); |
|
310 | + } else { |
|
311 | + return false; |
|
312 | + } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * remove a file or folder from the archive |
|
317 | - * |
|
318 | - * @param string $path |
|
319 | - * @return bool |
|
320 | - */ |
|
321 | - function remove($path) { |
|
322 | - if (!$this->fileExists($path)) { |
|
323 | - return false; |
|
324 | - } |
|
325 | - $this->fileList = false; |
|
326 | - $this->cachedHeaders = false; |
|
327 | - //no proper way to delete, extract entire archive, delete file and remake archive |
|
328 | - $tmp = OCP\Files::tmpFolder(); |
|
329 | - $this->tar->extract($tmp); |
|
330 | - OCP\Files::rmdirr($tmp . $path); |
|
331 | - $this->tar = null; |
|
332 | - unlink($this->path); |
|
333 | - $this->reopen(); |
|
334 | - $this->tar->createModify(array($tmp), '', $tmp); |
|
335 | - return true; |
|
336 | - } |
|
315 | + /** |
|
316 | + * remove a file or folder from the archive |
|
317 | + * |
|
318 | + * @param string $path |
|
319 | + * @return bool |
|
320 | + */ |
|
321 | + function remove($path) { |
|
322 | + if (!$this->fileExists($path)) { |
|
323 | + return false; |
|
324 | + } |
|
325 | + $this->fileList = false; |
|
326 | + $this->cachedHeaders = false; |
|
327 | + //no proper way to delete, extract entire archive, delete file and remake archive |
|
328 | + $tmp = OCP\Files::tmpFolder(); |
|
329 | + $this->tar->extract($tmp); |
|
330 | + OCP\Files::rmdirr($tmp . $path); |
|
331 | + $this->tar = null; |
|
332 | + unlink($this->path); |
|
333 | + $this->reopen(); |
|
334 | + $this->tar->createModify(array($tmp), '', $tmp); |
|
335 | + return true; |
|
336 | + } |
|
337 | 337 | |
338 | - /** |
|
339 | - * get a file handler |
|
340 | - * |
|
341 | - * @param string $path |
|
342 | - * @param string $mode |
|
343 | - * @return resource |
|
344 | - */ |
|
345 | - function getStream($path, $mode) { |
|
346 | - if (strrpos($path, '.') !== false) { |
|
347 | - $ext = substr($path, strrpos($path, '.')); |
|
348 | - } else { |
|
349 | - $ext = ''; |
|
350 | - } |
|
351 | - $tmpFile = OCP\Files::tmpFile($ext); |
|
352 | - if ($this->fileExists($path)) { |
|
353 | - $this->extractFile($path, $tmpFile); |
|
354 | - } elseif ($mode == 'r' or $mode == 'rb') { |
|
355 | - return false; |
|
356 | - } |
|
357 | - if ($mode == 'r' or $mode == 'rb') { |
|
358 | - return fopen($tmpFile, $mode); |
|
359 | - } else { |
|
360 | - \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); |
|
361 | - self::$tempFiles[$tmpFile] = $path; |
|
362 | - return fopen('close://' . $tmpFile, $mode); |
|
363 | - } |
|
364 | - } |
|
338 | + /** |
|
339 | + * get a file handler |
|
340 | + * |
|
341 | + * @param string $path |
|
342 | + * @param string $mode |
|
343 | + * @return resource |
|
344 | + */ |
|
345 | + function getStream($path, $mode) { |
|
346 | + if (strrpos($path, '.') !== false) { |
|
347 | + $ext = substr($path, strrpos($path, '.')); |
|
348 | + } else { |
|
349 | + $ext = ''; |
|
350 | + } |
|
351 | + $tmpFile = OCP\Files::tmpFile($ext); |
|
352 | + if ($this->fileExists($path)) { |
|
353 | + $this->extractFile($path, $tmpFile); |
|
354 | + } elseif ($mode == 'r' or $mode == 'rb') { |
|
355 | + return false; |
|
356 | + } |
|
357 | + if ($mode == 'r' or $mode == 'rb') { |
|
358 | + return fopen($tmpFile, $mode); |
|
359 | + } else { |
|
360 | + \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); |
|
361 | + self::$tempFiles[$tmpFile] = $path; |
|
362 | + return fopen('close://' . $tmpFile, $mode); |
|
363 | + } |
|
364 | + } |
|
365 | 365 | |
366 | - private static $tempFiles = array(); |
|
366 | + private static $tempFiles = array(); |
|
367 | 367 | |
368 | - /** |
|
369 | - * write back temporary files |
|
370 | - */ |
|
371 | - function writeBack($tmpFile) { |
|
372 | - if (isset(self::$tempFiles[$tmpFile])) { |
|
373 | - $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); |
|
374 | - unlink($tmpFile); |
|
375 | - } |
|
376 | - } |
|
368 | + /** |
|
369 | + * write back temporary files |
|
370 | + */ |
|
371 | + function writeBack($tmpFile) { |
|
372 | + if (isset(self::$tempFiles[$tmpFile])) { |
|
373 | + $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); |
|
374 | + unlink($tmpFile); |
|
375 | + } |
|
376 | + } |
|
377 | 377 | |
378 | - /** |
|
379 | - * reopen the archive to ensure everything is written |
|
380 | - */ |
|
381 | - private function reopen() { |
|
382 | - if ($this->tar) { |
|
383 | - $this->tar->_close(); |
|
384 | - $this->tar = null; |
|
385 | - } |
|
386 | - $types = array(null, 'gz', 'bz'); |
|
387 | - $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
388 | - } |
|
378 | + /** |
|
379 | + * reopen the archive to ensure everything is written |
|
380 | + */ |
|
381 | + private function reopen() { |
|
382 | + if ($this->tar) { |
|
383 | + $this->tar->_close(); |
|
384 | + $this->tar = null; |
|
385 | + } |
|
386 | + $types = array(null, 'gz', 'bz'); |
|
387 | + $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
|
388 | + } |
|
389 | 389 | } |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | $parts = explode('/', $path); |
98 | 98 | $folder = $tmpBase; |
99 | 99 | foreach ($parts as $part) { |
100 | - $folder .= '/' . $part; |
|
100 | + $folder .= '/'.$part; |
|
101 | 101 | if (!is_dir($folder)) { |
102 | 102 | mkdir($folder); |
103 | 103 | } |
104 | 104 | } |
105 | - $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase); |
|
106 | - rmdir($tmpBase . $path); |
|
105 | + $result = $this->tar->addModify(array($tmpBase.$path), '', $tmpBase); |
|
106 | + rmdir($tmpBase.$path); |
|
107 | 107 | $this->fileList = false; |
108 | 108 | $this->cachedHeaders = false; |
109 | 109 | return $result; |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | //no proper way to delete, rename entire archive, rename file and remake archive |
141 | 141 | $tmp = OCP\Files::tmpFolder(); |
142 | 142 | $this->tar->extract($tmp); |
143 | - rename($tmp . $source, $tmp . $dest); |
|
143 | + rename($tmp.$source, $tmp.$dest); |
|
144 | 144 | $this->tar = null; |
145 | 145 | unlink($this->path); |
146 | 146 | $types = array(null, 'gz', 'bz'); |
147 | 147 | $this->tar = new Archive_Tar($this->path, $types[self::getTarType($this->path)]); |
148 | - $this->tar->createModify(array($tmp), '', $tmp . '/'); |
|
148 | + $this->tar->createModify(array($tmp), '', $tmp.'/'); |
|
149 | 149 | $this->fileList = false; |
150 | 150 | $this->cachedHeaders = false; |
151 | 151 | return true; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | } |
161 | 161 | foreach ($this->cachedHeaders as $header) { |
162 | 162 | if ($file == $header['filename'] |
163 | - or $file . '/' == $header['filename'] |
|
164 | - or '/' . $file . '/' == $header['filename'] |
|
165 | - or '/' . $file == $header['filename'] |
|
163 | + or $file.'/' == $header['filename'] |
|
164 | + or '/'.$file.'/' == $header['filename'] |
|
165 | + or '/'.$file == $header['filename'] |
|
166 | 166 | ) { |
167 | 167 | return $header; |
168 | 168 | } |
@@ -261,13 +261,13 @@ discard block |
||
261 | 261 | if (!$this->fileExists($path)) { |
262 | 262 | return false; |
263 | 263 | } |
264 | - if ($this->fileExists('/' . $path)) { |
|
265 | - $success = $this->tar->extractList(array('/' . $path), $tmp); |
|
264 | + if ($this->fileExists('/'.$path)) { |
|
265 | + $success = $this->tar->extractList(array('/'.$path), $tmp); |
|
266 | 266 | } else { |
267 | 267 | $success = $this->tar->extractList(array($path), $tmp); |
268 | 268 | } |
269 | 269 | if ($success) { |
270 | - rename($tmp . $path, $dest); |
|
270 | + rename($tmp.$path, $dest); |
|
271 | 271 | } |
272 | 272 | OCP\Files::rmdirr($tmp); |
273 | 273 | return $success; |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | function fileExists($path) { |
293 | 293 | $files = $this->getFiles(); |
294 | - if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) { |
|
294 | + if ((array_search($path, $files) !== false) or (array_search($path.'/', $files) !== false)) { |
|
295 | 295 | return true; |
296 | 296 | } else { |
297 | 297 | $folderPath = $path; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | } |
307 | 307 | } |
308 | 308 | if ($path[0] != '/') { //not all programs agree on the use of a leading / |
309 | - return $this->fileExists('/' . $path); |
|
309 | + return $this->fileExists('/'.$path); |
|
310 | 310 | } else { |
311 | 311 | return false; |
312 | 312 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | //no proper way to delete, extract entire archive, delete file and remake archive |
328 | 328 | $tmp = OCP\Files::tmpFolder(); |
329 | 329 | $this->tar->extract($tmp); |
330 | - OCP\Files::rmdirr($tmp . $path); |
|
330 | + OCP\Files::rmdirr($tmp.$path); |
|
331 | 331 | $this->tar = null; |
332 | 332 | unlink($this->path); |
333 | 333 | $this->reopen(); |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | } else { |
360 | 360 | \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); |
361 | 361 | self::$tempFiles[$tmpFile] = $path; |
362 | - return fopen('close://' . $tmpFile, $mode); |
|
362 | + return fopen('close://'.$tmpFile, $mode); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 |
@@ -27,53 +27,53 @@ |
||
27 | 27 | */ |
28 | 28 | |
29 | 29 | class OC_L10N_String implements JsonSerializable { |
30 | - /** @var \OC_L10N|\OC\L10N\L10N */ |
|
31 | - protected $l10n; |
|
30 | + /** @var \OC_L10N|\OC\L10N\L10N */ |
|
31 | + protected $l10n; |
|
32 | 32 | |
33 | - /** @var string */ |
|
34 | - protected $text; |
|
33 | + /** @var string */ |
|
34 | + protected $text; |
|
35 | 35 | |
36 | - /** @var array */ |
|
37 | - protected $parameters; |
|
36 | + /** @var array */ |
|
37 | + protected $parameters; |
|
38 | 38 | |
39 | - /** @var integer */ |
|
40 | - protected $count; |
|
39 | + /** @var integer */ |
|
40 | + protected $count; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param \OC_L10N|\OC\L10N\L10N $l10n |
|
44 | - * @param string|string[] $text |
|
45 | - * @param array $parameters |
|
46 | - * @param int $count |
|
47 | - */ |
|
48 | - public function __construct($l10n, $text, $parameters, $count = 1) { |
|
49 | - $this->l10n = $l10n; |
|
50 | - $this->text = $text; |
|
51 | - $this->parameters = $parameters; |
|
52 | - $this->count = $count; |
|
53 | - } |
|
42 | + /** |
|
43 | + * @param \OC_L10N|\OC\L10N\L10N $l10n |
|
44 | + * @param string|string[] $text |
|
45 | + * @param array $parameters |
|
46 | + * @param int $count |
|
47 | + */ |
|
48 | + public function __construct($l10n, $text, $parameters, $count = 1) { |
|
49 | + $this->l10n = $l10n; |
|
50 | + $this->text = $text; |
|
51 | + $this->parameters = $parameters; |
|
52 | + $this->count = $count; |
|
53 | + } |
|
54 | 54 | |
55 | - public function __toString() { |
|
56 | - $translations = $this->l10n->getTranslations(); |
|
55 | + public function __toString() { |
|
56 | + $translations = $this->l10n->getTranslations(); |
|
57 | 57 | |
58 | - $text = $this->text; |
|
59 | - if(array_key_exists($this->text, $translations)) { |
|
60 | - if(is_array($translations[$this->text])) { |
|
61 | - $fn = $this->l10n->getPluralFormFunction(); |
|
62 | - $id = $fn($this->count); |
|
63 | - $text = $translations[$this->text][$id]; |
|
64 | - } |
|
65 | - else{ |
|
66 | - $text = $translations[$this->text]; |
|
67 | - } |
|
68 | - } |
|
58 | + $text = $this->text; |
|
59 | + if(array_key_exists($this->text, $translations)) { |
|
60 | + if(is_array($translations[$this->text])) { |
|
61 | + $fn = $this->l10n->getPluralFormFunction(); |
|
62 | + $id = $fn($this->count); |
|
63 | + $text = $translations[$this->text][$id]; |
|
64 | + } |
|
65 | + else{ |
|
66 | + $text = $translations[$this->text]; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // Replace %n first (won't interfere with vsprintf) |
|
71 | - $text = str_replace('%n', $this->count, $text); |
|
72 | - return vsprintf($text, $this->parameters); |
|
73 | - } |
|
70 | + // Replace %n first (won't interfere with vsprintf) |
|
71 | + $text = str_replace('%n', $this->count, $text); |
|
72 | + return vsprintf($text, $this->parameters); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - public function jsonSerialize() { |
|
77 | - return $this->__toString(); |
|
78 | - } |
|
76 | + public function jsonSerialize() { |
|
77 | + return $this->__toString(); |
|
78 | + } |
|
79 | 79 | } |
@@ -56,13 +56,13 @@ |
||
56 | 56 | $translations = $this->l10n->getTranslations(); |
57 | 57 | |
58 | 58 | $text = $this->text; |
59 | - if(array_key_exists($this->text, $translations)) { |
|
60 | - if(is_array($translations[$this->text])) { |
|
59 | + if (array_key_exists($this->text, $translations)) { |
|
60 | + if (is_array($translations[$this->text])) { |
|
61 | 61 | $fn = $this->l10n->getPluralFormFunction(); |
62 | 62 | $id = $fn($this->count); |
63 | 63 | $text = $translations[$this->text][$id]; |
64 | 64 | } |
65 | - else{ |
|
65 | + else { |
|
66 | 66 | $text = $translations[$this->text]; |
67 | 67 | } |
68 | 68 | } |
@@ -61,8 +61,7 @@ |
||
61 | 61 | $fn = $this->l10n->getPluralFormFunction(); |
62 | 62 | $id = $fn($this->count); |
63 | 63 | $text = $translations[$this->text][$id]; |
64 | - } |
|
65 | - else{ |
|
64 | + } else{ |
|
66 | 65 | $text = $translations[$this->text]; |
67 | 66 | } |
68 | 67 | } |
@@ -35,35 +35,35 @@ |
||
35 | 35 | /** |
36 | 36 | * {@inheritdoc} |
37 | 37 | */ |
38 | - public function isLocked($path, $type) { |
|
39 | - return false; |
|
40 | - } |
|
38 | + public function isLocked($path, $type) { |
|
39 | + return false; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * {@inheritdoc} |
44 | 44 | */ |
45 | - public function acquireLock($path, $type) { |
|
46 | - // do nothing |
|
47 | - } |
|
45 | + public function acquireLock($path, $type) { |
|
46 | + // do nothing |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
49 | + /** |
|
50 | 50 | * {@inheritdoc} |
51 | - */ |
|
52 | - public function releaseLock($path, $type) { |
|
53 | - // do nothing |
|
54 | - } |
|
51 | + */ |
|
52 | + public function releaseLock($path, $type) { |
|
53 | + // do nothing |
|
54 | + } |
|
55 | 55 | |
56 | - /**1 |
|
56 | + /**1 |
|
57 | 57 | * {@inheritdoc} |
58 | 58 | */ |
59 | - public function releaseAll() { |
|
60 | - // do nothing |
|
61 | - } |
|
59 | + public function releaseAll() { |
|
60 | + // do nothing |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function changeLock($path, $targetType) { |
|
67 | - // do nothing |
|
68 | - } |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function changeLock($path, $targetType) { |
|
67 | + // do nothing |
|
68 | + } |
|
69 | 69 | } |
@@ -29,95 +29,95 @@ |
||
29 | 29 | * to release any left over locks at the end of the request |
30 | 30 | */ |
31 | 31 | abstract class AbstractLockingProvider implements ILockingProvider { |
32 | - const TTL = 3600; // how long until we clear stray locks in seconds |
|
32 | + const TTL = 3600; // how long until we clear stray locks in seconds |
|
33 | 33 | |
34 | - protected $acquiredLocks = [ |
|
35 | - 'shared' => [], |
|
36 | - 'exclusive' => [] |
|
37 | - ]; |
|
34 | + protected $acquiredLocks = [ |
|
35 | + 'shared' => [], |
|
36 | + 'exclusive' => [] |
|
37 | + ]; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Check if we've locally acquired a lock |
|
41 | - * |
|
42 | - * @param string $path |
|
43 | - * @param int $type |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - protected function hasAcquiredLock($path, $type) { |
|
47 | - if ($type === self::LOCK_SHARED) { |
|
48 | - return isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 0; |
|
49 | - } else { |
|
50 | - return isset($this->acquiredLocks['exclusive'][$path]) && $this->acquiredLocks['exclusive'][$path] === true; |
|
51 | - } |
|
52 | - } |
|
39 | + /** |
|
40 | + * Check if we've locally acquired a lock |
|
41 | + * |
|
42 | + * @param string $path |
|
43 | + * @param int $type |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + protected function hasAcquiredLock($path, $type) { |
|
47 | + if ($type === self::LOCK_SHARED) { |
|
48 | + return isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 0; |
|
49 | + } else { |
|
50 | + return isset($this->acquiredLocks['exclusive'][$path]) && $this->acquiredLocks['exclusive'][$path] === true; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Mark a locally acquired lock |
|
56 | - * |
|
57 | - * @param string $path |
|
58 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
59 | - */ |
|
60 | - protected function markAcquire($path, $type) { |
|
61 | - if ($type === self::LOCK_SHARED) { |
|
62 | - if (!isset($this->acquiredLocks['shared'][$path])) { |
|
63 | - $this->acquiredLocks['shared'][$path] = 0; |
|
64 | - } |
|
65 | - $this->acquiredLocks['shared'][$path]++; |
|
66 | - } else { |
|
67 | - $this->acquiredLocks['exclusive'][$path] = true; |
|
68 | - } |
|
69 | - } |
|
54 | + /** |
|
55 | + * Mark a locally acquired lock |
|
56 | + * |
|
57 | + * @param string $path |
|
58 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
59 | + */ |
|
60 | + protected function markAcquire($path, $type) { |
|
61 | + if ($type === self::LOCK_SHARED) { |
|
62 | + if (!isset($this->acquiredLocks['shared'][$path])) { |
|
63 | + $this->acquiredLocks['shared'][$path] = 0; |
|
64 | + } |
|
65 | + $this->acquiredLocks['shared'][$path]++; |
|
66 | + } else { |
|
67 | + $this->acquiredLocks['exclusive'][$path] = true; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Mark a release of a locally acquired lock |
|
73 | - * |
|
74 | - * @param string $path |
|
75 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
76 | - */ |
|
77 | - protected function markRelease($path, $type) { |
|
78 | - if ($type === self::LOCK_SHARED) { |
|
79 | - if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) { |
|
80 | - $this->acquiredLocks['shared'][$path]--; |
|
81 | - if ($this->acquiredLocks['shared'][$path] === 0) { |
|
82 | - unset($this->acquiredLocks['shared'][$path]); |
|
83 | - } |
|
84 | - } |
|
85 | - } else if ($type === self::LOCK_EXCLUSIVE) { |
|
86 | - unset($this->acquiredLocks['exclusive'][$path]); |
|
87 | - } |
|
88 | - } |
|
71 | + /** |
|
72 | + * Mark a release of a locally acquired lock |
|
73 | + * |
|
74 | + * @param string $path |
|
75 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
76 | + */ |
|
77 | + protected function markRelease($path, $type) { |
|
78 | + if ($type === self::LOCK_SHARED) { |
|
79 | + if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) { |
|
80 | + $this->acquiredLocks['shared'][$path]--; |
|
81 | + if ($this->acquiredLocks['shared'][$path] === 0) { |
|
82 | + unset($this->acquiredLocks['shared'][$path]); |
|
83 | + } |
|
84 | + } |
|
85 | + } else if ($type === self::LOCK_EXCLUSIVE) { |
|
86 | + unset($this->acquiredLocks['exclusive'][$path]); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Change the type of an existing tracked lock |
|
92 | - * |
|
93 | - * @param string $path |
|
94 | - * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | - */ |
|
96 | - protected function markChange($path, $targetType) { |
|
97 | - if ($targetType === self::LOCK_SHARED) { |
|
98 | - unset($this->acquiredLocks['exclusive'][$path]); |
|
99 | - if (!isset($this->acquiredLocks['shared'][$path])) { |
|
100 | - $this->acquiredLocks['shared'][$path] = 0; |
|
101 | - } |
|
102 | - $this->acquiredLocks['shared'][$path]++; |
|
103 | - } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
104 | - $this->acquiredLocks['exclusive'][$path] = true; |
|
105 | - $this->acquiredLocks['shared'][$path]--; |
|
106 | - } |
|
107 | - } |
|
90 | + /** |
|
91 | + * Change the type of an existing tracked lock |
|
92 | + * |
|
93 | + * @param string $path |
|
94 | + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | + */ |
|
96 | + protected function markChange($path, $targetType) { |
|
97 | + if ($targetType === self::LOCK_SHARED) { |
|
98 | + unset($this->acquiredLocks['exclusive'][$path]); |
|
99 | + if (!isset($this->acquiredLocks['shared'][$path])) { |
|
100 | + $this->acquiredLocks['shared'][$path] = 0; |
|
101 | + } |
|
102 | + $this->acquiredLocks['shared'][$path]++; |
|
103 | + } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
104 | + $this->acquiredLocks['exclusive'][$path] = true; |
|
105 | + $this->acquiredLocks['shared'][$path]--; |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * release all lock acquired by this instance which were marked using the mark* methods |
|
111 | - */ |
|
112 | - public function releaseAll() { |
|
113 | - foreach ($this->acquiredLocks['shared'] as $path => $count) { |
|
114 | - for ($i = 0; $i < $count; $i++) { |
|
115 | - $this->releaseLock($path, self::LOCK_SHARED); |
|
116 | - } |
|
117 | - } |
|
109 | + /** |
|
110 | + * release all lock acquired by this instance which were marked using the mark* methods |
|
111 | + */ |
|
112 | + public function releaseAll() { |
|
113 | + foreach ($this->acquiredLocks['shared'] as $path => $count) { |
|
114 | + for ($i = 0; $i < $count; $i++) { |
|
115 | + $this->releaseLock($path, self::LOCK_SHARED); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - foreach ($this->acquiredLocks['exclusive'] as $path => $hasLock) { |
|
120 | - $this->releaseLock($path, self::LOCK_EXCLUSIVE); |
|
121 | - } |
|
122 | - } |
|
119 | + foreach ($this->acquiredLocks['exclusive'] as $path => $hasLock) { |
|
120 | + $this->releaseLock($path, self::LOCK_EXCLUSIVE); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |