-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathOptions.php
More file actions
49 lines (41 loc) Β· 1.25 KB
/
Options.php
File metadata and controls
49 lines (41 loc) Β· 1.25 KB
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
<?php
namespace LanguageServer;
class Options
{
/**
* Filetypes the indexer should process
*
* @var string[]
*/
public $fileTypes = ['.php'];
/**
* Validate/Filter input and set options for file types
*
* @param array $fileTypes List of file types
*/
public function setFileTypes(array $fileTypes)
{
$fileTypes = filter_var_array($fileTypes, FILTER_SANITIZE_STRING);
$fileTypes = filter_var($fileTypes, FILTER_CALLBACK, ['options' => [$this, 'filterFileTypes']]); // validate file type format
$fileTypes = array_filter($fileTypes, 'strlen'); // filter empty items
$fileTypes = array_values($fileTypes); //rebase indexes
$this->fileTypes = !empty($fileTypes) ? $fileTypes : $this->fileTypes;
}
/**
* Filter valid file type
*
* @param string $fileType The file type to filter
* @return string|bool If valid it returns the file type, otherwise false
*/
private function filterFileTypes(string $fileType)
{
$fileType = trim($fileType);
if (empty($fileType)) {
return $fileType;
}
if (substr($fileType, 0, 1) !== '.') {
return false;
}
return $fileType;
}
}