-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfauxton-config
83 lines (73 loc) · 2.13 KB
/
fauxton-config
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
#!/usr/bin/env php
<?php
/**
*
* fauxton-config script
*
* @author Lochemem Bruno Michael
* @license Apache-2.0
*/
foreach (
[
__DIR__ . '/../autoload.php',
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../../vendor/autoload.php'
] as $file
) {
if (file_exists($file)) {
define('AUTOLOAD_PHP_FILE', $file);
break;
}
}
if (!defined('AUTOLOAD_PHP_FILE')) {
fwrite(STDERR,
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'wget http://getcomposer.org/composer.phar' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
die(1);
}
require AUTOLOAD_PHP_FILE;
use \React\Filesystem\Filesystem;
use \React\Promise\Promise;
use \Chemem\Fauxton\Http;
use \Chemem\Fauxton\Config\State;
use function \Chemem\Bingo\Functional\Functors\Monads\IO\_print;
use function \Chemem\Bingo\Functional\Functors\Monads\IO\IO;
use function \Chemem\Bingo\Functional\Algorithms\compose;
use function \Chemem\Bingo\Functional\Algorithms\partialRight;
function _create($loop) : Promise
{
return Filesystem::create($loop)->file(State::CLIENT_CONFIG_FILE)->open('cw');
}
function main($loop) : Promise
{
return Http\_readConfig($loop)->then(
function (string $content) use ($loop) {
return \React\Promise\resolve(
_create($loop)->then(
function ($stream) use ($content) {
$stream->write($content);
$stream->end();
return IO('Data written to file');
},
function ($error) {
return IO($error->getMessage());
}
)
);
}
);
}
$loop = \React\EventLoop\Factory::create();
$result = main($loop)->then(
function ($result) {
_print($result);
},
function ($error) {
echo $error->getMessage();
}
);
$loop->run();