-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextDocumentContentChangeFullEvent.php
More file actions
99 lines (83 loc) · 2.69 KB
/
TextDocumentContentChangeFullEvent.php
File metadata and controls
99 lines (83 loc) · 2.69 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php // Auto-generated from vscode-languageserver-protocol (typescript)
namespace Phpactor\LanguageServerProtocol;
use DTL\Invoke\Invoke;
use Exception;
use RuntimeException;
class TextDocumentContentChangeFullEvent
{
/**
* The new text of the whole document.
*
* @var string
*/
public $text;
/**
* @param string $text
*/
public function __construct(string $text)
{
$this->text = $text;
}
/**
* @param array<string,mixed> $array
* @return self
*/
public static function fromArray(array $array, bool $allowUnknownKeys = false)
{
$map = [
'text' => ['names' => [], 'iterable' => false],
];
foreach ($array as $key => &$value) {
if (!isset($map[$key])) {
if ($allowUnknownKeys) {
unset($array[$key]);
continue;
}
throw new RuntimeException(sprintf(
'Parameter "%s" on class "%s" not known, known parameters: "%s"',
$key,
self::class,
implode('", "', array_keys($map))
));
}
// from here we only care about arrays that can be transformed into
// objects
if (!is_array($value)) {
continue;
}
if (empty($map[$key]['names'])) {
continue;
}
if ($map[$key]['iterable']) {
$value = array_map(function ($object) use ($map, $key, $allowUnknownKeys) {
if (!is_array($object)) {
return $object;
}
return self::invokeFromNames($map[$key]['names'], $object, $allowUnknownKeys) ?: $object;
}, $value);
continue;
}
$names = $map[$key]['names'];
$value = self::invokeFromNames($names, $value, $allowUnknownKeys) ?: $value;
}
return Invoke::new(self::class, $array);
}
/**
* @param array<string> $classNames
* @param array<string,mixed> $object
*/
private static function invokeFromNames(array $classNames, array $object, bool $allowUnknownKeys): ?object
{
$lastException = null;
foreach ($classNames as $className) {
try {
// @phpstan-ignore-next-line
return call_user_func_array($className . '::fromArray', [$object, $allowUnknownKeys]);
} catch (Exception $exception) {
$lastException = $exception;
continue;
}
}
throw $lastException;
}
}