-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathWorkspaceService.php
50 lines (41 loc) · 1000 Bytes
/
WorkspaceService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Text\Service;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Files\StorageInvalidException;
use OCP\IL10N;
class WorkspaceService {
private IL10N $l10n;
private const SUPPORTED_STATIC_FILENAMES = [
'Readme.md',
'README.md',
'readme.md'
];
public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
}
public function getFile(Folder $folder): ?File {
foreach ($this->getSupportedFilenames() as $filename) {
try {
$file = $folder->get($filename);
if ($file instanceof File) {
return $file;
}
} catch (NotFoundException|StorageInvalidException) {
continue;
}
}
return null;
}
/** @return string[] */
public function getSupportedFilenames(): array {
return array_merge([
$this->l10n->t('Readme') . '.md'
], self::SUPPORTED_STATIC_FILENAMES);
}
}