@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @throws \Exception |
| 68 | 68 | */ |
| 69 | 69 | public function fetchFileOrFolder($path, array $properties = null) { |
| 70 | - $fetchFileFunc = function ($path, $props) { return $this->fetchFile($path, $props);}; |
|
| 71 | - $fetchFolderFunc = function ($path, $props) { return $this->fetchFolder($path, $props);}; |
|
| 72 | - $fetchers = [ $fetchFileFunc, $fetchFolderFunc ]; |
|
| 73 | - if(strpos($path, '.') === false) { |
|
| 70 | + $fetchFileFunc = function($path, $props) { return $this->fetchFile($path, $props); }; |
|
| 71 | + $fetchFolderFunc = function($path, $props) { return $this->fetchFolder($path, $props); }; |
|
| 72 | + $fetchers = [$fetchFileFunc, $fetchFolderFunc]; |
|
| 73 | + if (strpos($path, '.') === false) { |
|
| 74 | 74 | $fetchers = array_reverse($fetchers); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $instance = call_user_func_array($fetchFunction, [$path, $properties]); |
| 80 | 80 | return $instance; |
| 81 | 81 | } catch (\Exception $e) { |
| 82 | - if(preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1 |
|
| 82 | + if (preg_match('/^The file \/.* does not exist\.$/', $e->getMessage()) !== 1 |
|
| 83 | 83 | && $e->getMessage() !== 'Unknown Error' |
| 84 | 84 | && $e->getMessage() !== 'File Not Found.' |
| 85 | 85 | ) { |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $serverUrlParts = explode('/', $relativeServerPath); |
| 122 | 122 | $newFolderName = array_pop($serverUrlParts); |
| 123 | - $parentUrl = implode('/', $serverUrlParts); |
|
| 123 | + $parentUrl = implode('/', $serverUrlParts); |
|
| 124 | 124 | |
| 125 | 125 | $parentFolder = $this->context->getWeb()->getFolderByServerRelativeUrl($parentUrl); |
| 126 | 126 | $parentFolder->getFolders()->add($newFolderName); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function fetchFolderContents($relativeServerPath, $properties = null, Folder $folder = null) { |
| 143 | 143 | $this->ensureConnection(); |
| 144 | - if($folder === null) { |
|
| 144 | + if ($folder === null) { |
|
| 145 | 145 | $folder = $this->context->getWeb()->getFolderByServerRelativeUrl($relativeServerPath); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -159,20 +159,20 @@ discard block |
||
| 159 | 159 | public function isHidden(ClientObject $file) { |
| 160 | 160 | // ClientObject itself does not have getListItemAllFields but is |
| 161 | 161 | // the common denominator of File and Folder |
| 162 | - if(!$file instanceof File && !$file instanceof Folder) { |
|
| 162 | + if (!$file instanceof File && !$file instanceof Folder) { |
|
| 163 | 163 | throw new \InvalidArgumentException('File or Folder expected'); |
| 164 | 164 | } |
| 165 | - if($file instanceof File) { |
|
| 165 | + if ($file instanceof File) { |
|
| 166 | 166 | // it's expensive, we only check folders |
| 167 | 167 | return false; |
| 168 | 168 | } |
| 169 | 169 | $fields = $file->getListItemAllFields(); |
| 170 | - if($fields->getProperties() === []) { |
|
| 170 | + if ($fields->getProperties() === []) { |
|
| 171 | 171 | $this->loadAndExecute($fields, ['Id', 'Hidden']); |
| 172 | 172 | } |
| 173 | 173 | $id = $fields->getProperty('Id'); |
| 174 | 174 | $hidden = $fields->getProperty('Hidden'); // TODO: get someone to test this in SP 2013 |
| 175 | - if($hidden === false || $id !== null) { |
|
| 175 | + if ($hidden === false || $id !== null) { |
|
| 176 | 176 | // avoids listing hidden "Forms" folder (and its contents). |
| 177 | 177 | // Have not found a different mechanism to detect whether |
| 178 | 178 | // a file or folder is hidden. There used to be a Hidden |
@@ -192,11 +192,11 @@ discard block |
||
| 192 | 192 | * @throws NotFoundException |
| 193 | 193 | */ |
| 194 | 194 | private function getDocumentLibrary() { |
| 195 | - if(!is_null($this->documentLibrary)) { |
|
| 195 | + if (!is_null($this->documentLibrary)) { |
|
| 196 | 196 | return $this->documentLibrary; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - $lists = $this->context->getWeb()->getLists()->filter('Title eq \'' . $this->documentLibraryTitle . '\'')->top(1); |
|
| 199 | + $lists = $this->context->getWeb()->getLists()->filter('Title eq \''.$this->documentLibraryTitle.'\'')->top(1); |
|
| 200 | 200 | $this->context->load($lists)->executeQuery(); |
| 201 | 201 | if ($lists->getCount() === 1 && $lists->getData()[0] instanceof SPList) { |
| 202 | 202 | $this->documentLibrary = $lists->getData()[0]; |
@@ -212,18 +212,18 @@ discard block |
||
| 212 | 212 | * @throws \InvalidArgumentException |
| 213 | 213 | */ |
| 214 | 214 | private function ensureConnection() { |
| 215 | - if($this->context instanceof ClientContext) { |
|
| 215 | + if ($this->context instanceof ClientContext) { |
|
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if(!is_string($this->credentials['user']) || empty($this->credentials['user'])) { |
|
| 219 | + if (!is_string($this->credentials['user']) || empty($this->credentials['user'])) { |
|
| 220 | 220 | throw new \InvalidArgumentException('No user given'); |
| 221 | 221 | } |
| 222 | - if(!is_string($this->credentials['password']) || empty($this->credentials['password'])) { |
|
| 222 | + if (!is_string($this->credentials['password']) || empty($this->credentials['password'])) { |
|
| 223 | 223 | throw new \InvalidArgumentException('No password given'); |
| 224 | 224 | } |
| 225 | 225 | $this->authContext = $this->contextsFactory->getAuthContext($this->credentials['user'], $this->credentials['password']); |
| 226 | - $this->authContext->AuthType = CURLAUTH_NTLM; # Basic auth does not work somehow… |
|
| 226 | + $this->authContext->AuthType = CURLAUTH_NTLM; # Basic auth does not work somehow… |
|
| 227 | 227 | $this->createClientContext(); |
| 228 | 228 | # Auth is not triggered yet. This will happen when something is requested from SharePoint (on demand), e.g.: |
| 229 | 229 | } |
@@ -66,14 +66,14 @@ discard block |
||
| 66 | 66 | $this->server = $parameters['host']; |
| 67 | 67 | $this->documentLibrary = $parameters['documentLibrary']; |
| 68 | 68 | |
| 69 | - if(strpos($this->documentLibrary, '"') !== false) { |
|
| 69 | + if (strpos($this->documentLibrary, '"') !== false) { |
|
| 70 | 70 | // they are, amongst others, not allowed and we use it in the filter |
| 71 | 71 | // cf. https://support.microsoft.com/en-us/kb/2933738 |
| 72 | 72 | // TODO: verify, it talks about files and folders mostly |
| 73 | 73 | throw new \InvalidArgumentException('Illegal character in Document Library Name'); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if(!isset($parameters['user']) || !isset($parameters['password'])) { |
|
| 76 | + if (!isset($parameters['user']) || !isset($parameters['password'])) { |
|
| 77 | 77 | throw new \UnexpectedValueException('No user or password given'); |
| 78 | 78 | } |
| 79 | 79 | $this->authUser = $parameters['user']; |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @since 6.0.0 |
| 92 | 92 | */ |
| 93 | 93 | public function getId() { |
| 94 | - return 'SharePoint::' . $this->server . '::' . $this->documentLibrary . '::' . $this->authUser; |
|
| 94 | + return 'SharePoint::'.$this->server.'::'.$this->documentLibrary.'::'.$this->authUser; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $items = $collection->getData(); |
| 145 | 145 | foreach ($items as $item) { |
| 146 | 146 | /** @var ListItem $fields */ |
| 147 | - if(!$this->spClient->isHidden($item)) { |
|
| 147 | + if (!$this->spClient->isHidden($item)) { |
|
| 148 | 148 | $files[] = $item->getProperty('Name'); |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | 'atime' => time(), |
| 185 | 185 | ]; |
| 186 | 186 | |
| 187 | - if(!is_null($stat['mtime'])) { |
|
| 187 | + if (!is_null($stat['mtime'])) { |
|
| 188 | 188 | return $stat; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | } catch (NotFoundException $e) { |
| 209 | 209 | return false; |
| 210 | 210 | } |
| 211 | - if($object instanceof File) { |
|
| 211 | + if ($object instanceof File) { |
|
| 212 | 212 | return 'file'; |
| 213 | - } else if($object instanceof Folder) { |
|
| 213 | + } else if ($object instanceof Folder) { |
|
| 214 | 214 | return 'dir'; |
| 215 | 215 | } else { |
| 216 | 216 | return false; |
@@ -248,15 +248,15 @@ discard block |
||
| 248 | 248 | public function unlink($path) { |
| 249 | 249 | // FIXME:: all is totally wrong |
| 250 | 250 | $path = trim($path); |
| 251 | - if($path === '/' || $path === '') { |
|
| 251 | + if ($path === '/' || $path === '') { |
|
| 252 | 252 | return false; |
| 253 | 253 | } |
| 254 | - foreach([true, false] as $asFile) { |
|
| 254 | + foreach ([true, false] as $asFile) { |
|
| 255 | 255 | try { |
| 256 | 256 | $fsObject = $this->spClient->fetchFileOrFolder($path, $asFile); |
| 257 | 257 | $fsObject->deleteObject(); |
| 258 | 258 | return true; |
| 259 | - } catch(\Exception $e) { |
|
| 259 | + } catch (\Exception $e) { |
|
| 260 | 260 | // NOOP |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @param array $parameters |
| 298 | 298 | */ |
| 299 | 299 | private function fixDI(array $parameters) { |
| 300 | - if(isset($parameters['contextFactory']) |
|
| 300 | + if (isset($parameters['contextFactory']) |
|
| 301 | 301 | && $parameters['contextFactory'] instanceof ContextsFactory) |
| 302 | 302 | { |
| 303 | 303 | $this->contextsFactory = $parameters['contextFactory']; |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | $this->contextsFactory = new ContextsFactory(); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if(isset($parameters['sharePointClientFactory']) |
|
| 308 | + if (isset($parameters['sharePointClientFactory']) |
|
| 309 | 309 | && $parameters['sharePointClientFactory'] instanceof SharePointClientFactory) |
| 310 | 310 | { |
| 311 | 311 | $spcFactory = $parameters['sharePointClientFactory']; |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | $this->spClient = $spcFactory->getClient( |
| 316 | 316 | $this->contextsFactory, |
| 317 | 317 | $this->server, |
| 318 | - [ 'user' => $this->authUser, 'password' => $this->authPwd], |
|
| 318 | + ['user' => $this->authUser, 'password' => $this->authPwd], |
|
| 319 | 319 | $this->documentLibrary |
| 320 | 320 | ); |
| 321 | 321 | |
| 322 | - if(isset($parameters['cappedMemoryCache'])) { |
|
| 322 | + if (isset($parameters['cappedMemoryCache'])) { |
|
| 323 | 323 | $this->fileCache = $parameters['cappedMemoryCache']; |
| 324 | 324 | } else { |
| 325 | 325 | $this->fileCache = new CappedMemoryCache('256'); |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | private function getFolderContents($serverUrl) { |
| 334 | 334 | $entry = $this->fileCache->get($serverUrl); |
| 335 | - if($entry === null || !isset($entry['children'])) { |
|
| 335 | + if ($entry === null || !isset($entry['children'])) { |
|
| 336 | 336 | $folder = isset($entry['instance']) ? $entry['instance'] : null; |
| 337 | 337 | $contents = $this->spClient->fetchFolderContents($serverUrl, null, $folder); |
| 338 | 338 | $cacheItem = $entry ?: []; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | $url = $item->getProperty(self::SP_PROPERTY_URL); |
| 347 | 347 | $itemEntry = $this->fileCache->get($url); |
| 348 | 348 | $itemEntry = $itemEntry ?: []; |
| 349 | - if(!isset($itemEntry['instance'])) { |
|
| 349 | + if (!isset($itemEntry['instance'])) { |
|
| 350 | 350 | $itemEntry['instance'] = $item; |
| 351 | 351 | $this->fileCache->set($url, $itemEntry); |
| 352 | 352 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | private function getFileOrFolder($serverUrl) { |
| 366 | 366 | $entry = $this->fileCache->get($serverUrl); |
| 367 | - if($entry === null || !isset($entry['instance'])) { |
|
| 367 | + if ($entry === null || !isset($entry['instance'])) { |
|
| 368 | 368 | $file = $this->spClient->fetchFileOrFolder($serverUrl, [self::SP_PROPERTY_SIZE, self::SP_PROPERTY_MTIME]); |
| 369 | 369 | $cacheItem = $entry ?: []; |
| 370 | 370 | $cacheItem['instance'] = $file; |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | */ |
| 384 | 384 | private function formatPath($path) { |
| 385 | 385 | $path = trim($path, '/'); |
| 386 | - $serverUrl = '/' . $this->documentLibrary; |
|
| 387 | - if($path !== '') { |
|
| 388 | - $serverUrl .= '/' . $path; |
|
| 386 | + $serverUrl = '/'.$this->documentLibrary; |
|
| 387 | + if ($path !== '') { |
|
| 388 | + $serverUrl .= '/'.$path; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | $pathParts = explode('/', $serverUrl); |
| 392 | 392 | $filename = array_pop($pathParts); |
| 393 | - if($filename === '.') { |
|
| 393 | + if ($filename === '.') { |
|
| 394 | 394 | // remove /. from the end of the path |
| 395 | 395 | $serverUrl = mb_substr($serverUrl, 0, mb_strlen($serverUrl) - 2); |
| 396 | 396 | } |