-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathfunctions.php
More file actions
53 lines (45 loc) · 1.22 KB
/
functions.php
File metadata and controls
53 lines (45 loc) · 1.22 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
<?php
namespace React\Filesystem;
use Exception;
/**
* @param AdapterInterface $adapter
* @param array $options
* @param string $key
* @param string $fallback
* @return CallInvokerInterface
*/
function getInvoker(AdapterInterface $adapter, array $options, $key, $fallback)
{
if (isset($options[$key]) && $options[$key] instanceof CallInvokerInterface) {
return $options[$key];
}
return new $fallback($adapter);
}
/**
* @param array $options
* @return int
*/
function getOpenFileLimit(array $options)
{
if (isset($options['open_file_limit'])) {
return (int)$options['open_file_limit'];
}
return OpenFileLimiter::DEFAULT_LIMIT;
}
/**
* @param array $typeDetectors
* @param array $node
* @return \React\Promise\PromiseInterface
*/
function detectType(array $typeDetectors, array $node)
{
$promiseChain = \React\Promise\reject(new Exception('Unknown type'));
foreach ($typeDetectors as $detector) {
$promiseChain = $promiseChain->otherwise(function () use ($node, $detector) {
return $detector->detect($node);
});
}
return $promiseChain->then(function ($callable) use ($node) {
return \React\Promise\resolve($callable($node['path']));
});
}