Skip to content

Commit 642a2be

Browse files
authored
Merge pull request #16 from Innmind/documentation
Update documentation for the new APIs
2 parents 2234f95 + e5264de commit 642a2be

12 files changed

Lines changed: 352 additions & 142 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
- Requires `innmind/time-warp:~4.0`
3030
- Requires `innmind/io:~3.2`
3131
- Requires `innmind/immutable:~5.15`
32-
- `Innmind\OperatingSystem\Config::withHttpHeartbeat()` period is now expressed with a `Innmind\TimeContinuum\Period`
3332
- `Innmind\OperatingSystem\CurrentProcess::id()` now returns an `Innmind\Immutable\Attempt`
3433
- `Innmind\OperatingSystem\CurrentProcess::halt()` now returns `Innmind\Immutable\Attempt<Innmind\Immutable\SideEffect>`
3534
- `Innmind\OperatingSystem\Filesystem::mount()` now returns an `Innmind\Immutable\Attempt`

README.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ $os = Factory::build();
3838
```php
3939
use Innmind\Url\Path;
4040

41-
$adapter = $os->filesystem()->mount(Path::of('/var/data/'));
41+
$adapter = $os
42+
->filesystem()
43+
->mount(Path::of('/var/data/'))
44+
->unwrap();
4245
```
4346

4447
`$adater` is an instance of [`Innmind\Filesystem\Adapter`](http://innmind.github.io/Filesystem/).
@@ -55,7 +58,8 @@ use Innmind\Server\Control\Server\Command;
5558
$process = $os
5659
->control()
5760
->processes()
58-
->execute(Command::foreground('echo foo'));
61+
->execute(Command::foreground('echo foo'))
62+
->unwrap();
5963
```
6064

6165
`$process` is an instance of [`Innmind\Server\Control\Server\Process`](https://github.com/innmind/servercontrol#usage).
@@ -74,39 +78,36 @@ $server = $os
7478
IPv4::localhost(),
7579
Port::of(1337),
7680
)
77-
->match(
78-
static fn($server) => $server->unwrap(),
79-
static fn() => throw new \RuntimeException('Cannot open the socket'),
80-
);
81+
->unwrap();
8182
```
8283

83-
`$server` is an instance of [`Innmind\Socket\Server`](https://github.com/innmind/socket#internet-socket).
84+
`$server` is an instance of [`Innmind\IO\Sockets\Servers\Server`](https://innmind.org/io/sockets/).
8485

8586
### Want to open a local socket ?
8687

8788
```php
8889
# process A
8990
use Innmind\Socket\Address\Unix;
9091

91-
$server = $os->sockets()->open(Unix::of('/tmp/foo.sock'))->match(
92-
static fn($server) => $server->unwrap(),
93-
static fn() => throw new \RuntimeException('Cannot open the socket'),
94-
);
92+
$server = $os
93+
->sockets()
94+
->open(Unix::of('/tmp/foo.sock'))
95+
->unwrap();
9596
```
9697

97-
`$server` is an instance of [`Innmind\Socket\Server`](https://github.com/innmind/socket#unix-socket).
98+
`$server` is an instance of [`Innmind\IO\Sockets\Servers\Server`](https://innmind.org/io/sockets/).
9899

99100
```php
100101
# process B
101102
use Innmind\Socket\Address\Unix;
102103

103-
$client = $os->sockets()->connectTo(Unix::of('/tmp/foo.sock'))->match(
104-
static fn($client) => $client->unwrap(),
105-
static fn() => throw new \RuntimeException('Cannot connect to the socket'),
106-
);
104+
$client = $os
105+
->sockets()
106+
->connectTo(Unix::of('/tmp/foo.sock'))
107+
->unwrap();
107108
```
108109

109-
`$client` is an instance of `Innmind\Socket\Client`.
110+
`$client` is an instance of [`Innmind\IO\Sockets\Clients\Client`](https://innmind.org/io/sockets/#clients).
110111

111112
### Want to execute commands on a remote server ?
112113

@@ -118,7 +119,8 @@ $process = $os
118119
->remote()
119120
->ssh(Url::of('ssh://user@server-address:1337'))
120121
->processes()
121-
->execute(Command::foreground('ls'));
122+
->execute(Command::foreground('ls'))
123+
->unwrap();
122124
```
123125

124126
`$process` is an instance of [`Innmind\Server\Control\Server\Process`](https://github.com/innmind/servercontrol#usage).
@@ -127,15 +129,15 @@ $process = $os
127129

128130
```php
129131
use Innmind\Http\{
130-
Message\Request\Request,
131-
Message\Method,
132+
Request,
133+
Method,
132134
ProtocolVersion,
133135
};
134136
use Innmind\Url\Url;
135137

136138
$response = $os
137139
->remote()
138-
->http()(new Request(
140+
->http()(Request::of(
139141
Url::of('http://example.com'),
140142
Method::get,
141143
ProtocolVersion::v20,
@@ -145,15 +147,15 @@ $response = $os
145147
### Want to access current process id ?
146148

147149
```php
148-
$os->process()->id();
150+
$os->process()->id()->unwrap();
149151
```
150152

151153
### Want to pause the current process ?
152154

153155
```php
154-
use Innmind\TimeContinuum\Earth\Period\Minute;
156+
use Innmind\TimeContinuum\Period;
155157

156-
$os->process()->halt(new Minute(1));
158+
$os->process()->halt(Period::minute(1));
157159
```
158160

159161
### Want to listen for a signal ?

documentation/advanced/logging.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
If you want to trace everything that is done on your operating system you can use the logger decorator that will automatically write to your log file (almost) all operations.
44

5-
!!! note ""
6-
Data and actions done on a socket are not logged as well as processes output to prevent logging too much data (at least for now).
7-
85
```php
9-
use Innmind\OperatingSystem\OperatingSystem\Logger;
6+
use Innmind\OperatingSystem\Config\Logger;
107
use Psr\Log\LoggerInterface;
118

12-
$os = Logger::psr(
13-
$os,
14-
/* any instance of LoggerInterface */
9+
$os = $os->map(
10+
Logger::psr(/* any instance of LoggerInterface */),
1511
);
1612
```
1713

documentation/upgrade/v5-to-v6.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# V5 to V6
2+
3+
### Resilient decorator
4+
5+
=== "Before"
6+
```php
7+
use Innmind\OperatingSystem\OperatingSystem\Resilient;
8+
9+
$os = Resilient::of($os);
10+
```
11+
=== "After"
12+
```php
13+
use Innmind\OperatingSystem\Config\Resilient;
14+
15+
$os = $os->map(Resilient::new());
16+
```
17+
18+
### Logger decorator
19+
20+
=== "Before"
21+
```php
22+
use Innmind\OperatingSystem\OperatingSystem\Logger;
23+
use Psr\Log\LoggerInterface
24+
25+
$os = Logger::psr($os, /* instance of LoggerInterface */);
26+
```
27+
=== "After"
28+
```php
29+
use Innmind\OperatingSystem\Config\Logger;
30+
31+
$os = $os->map(Logger::psr(/* instance of LoggerInterface */));
32+
```
33+
34+
### HTTP client config
35+
36+
=== "Before"
37+
```php
38+
use Innmind\OperatingSystem\{
39+
Factory,
40+
Config,
41+
};
42+
use Innmind\TimeContinuum\Earth\ElapsedPeriod;
43+
44+
$os = Factory::build(
45+
Config::of()
46+
->disableSSLVerification()
47+
->limitHttpConcurrencyTo(10)
48+
->withHttpHeartbeat(
49+
ElapsedPeriod::of(1_000),
50+
static fn() => 'heartbeat',
51+
),
52+
);
53+
```
54+
55+
=== "After"
56+
```php
57+
use Innmind\OperatingSystem\{
58+
Factory,
59+
Config,
60+
};
61+
use Innmind\HttpTransport\Curl;
62+
use Innmind\TimeContinuum\Period;
63+
64+
$config = Config::new();
65+
$os = Factory::build(
66+
$config->useHttpTransport(
67+
Curl::of($config->clock(), $config->io())
68+
->disableSSLVerification()
69+
->maxConcurrency(10)
70+
->heartbeat(
71+
Period::second(1),
72+
static fn() => 'heartbeat',
73+
),
74+
),
75+
);
76+
```
77+
78+
### Filesystem config
79+
80+
=== "Before"
81+
```php
82+
use Innmind\OperatingSystem\{
83+
Factory,
84+
Config,
85+
};
86+
use Innmind\Filesystem\CaseSensitivity;
87+
88+
$os = Factory::build(
89+
Config::of()->caseInsensitiveFilesystem(
90+
CaseSensitivity::insensitive,
91+
),
92+
);
93+
```
94+
95+
=== "After"
96+
```php
97+
use Innmind\OperatingSystem\{
98+
Factory,
99+
Config,
100+
};
101+
use Innmind\Filesystem\{
102+
Adapter\Filesystem,
103+
CaseSensitivity,
104+
};
105+
106+
$os = Factory::build(
107+
Config::new()->mountFilesystemVia(
108+
static fn(Path $path, Config $config) => Filesystem::mount(
109+
$path,
110+
$config->io(),
111+
)->withCaseSentitivity(
112+
CaseSensitivity::insensitive,
113+
),
114+
),
115+
);
116+
```
117+
118+
### Current process id
119+
120+
=== "Before"
121+
```php
122+
$os->process()->id();
123+
```
124+
125+
=== "After"
126+
```php
127+
$os->process()->id()->unwrap();
128+
```
129+
130+
### Halt current process
131+
132+
=== "Before"
133+
```php
134+
use Innmind\TimeContinuum\Earth\Period\Second;
135+
136+
$os->process()->halt(new Second(1));
137+
```
138+
139+
=== "After"
140+
```php
141+
use Innmind\TimeContinuum\Period;
142+
143+
$os->process()->halt(Period::second(1))->unwrap();
144+
```
145+
146+
### Mount filesystem
147+
148+
=== "Before"
149+
```php
150+
use Innmind\Url\Path;
151+
152+
$adapter = $os
153+
->filesystem()
154+
->mount(Path::of('somewhere/'));
155+
```
156+
157+
=== "After"
158+
```php
159+
use Innmind\Url\Path;
160+
161+
$adapter = $os
162+
->filesystem()
163+
->mount(Path::of('somewhere/'))
164+
->unwrap();
165+
```

documentation/use_cases/filesystem.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ $backup = function(Adapter $source, Adapter $target): void {
1717
});
1818
};
1919
$backup(
20-
$os->filesystem()->mount(Path::of('/path/to/source/')),
21-
$os->filesystem()->mount(Path::of('/path/to/target/')),
20+
$os
21+
->filesystem()
22+
->mount(Path::of('/path/to/source/'))
23+
->unwrap(),
24+
$os
25+
->filesystem()
26+
->mount(Path::of('/path/to/target/'))
27+
->unwrap(),
2228
);
2329
```
2430

@@ -53,7 +59,10 @@ $addUserPicture = function(
5359
);
5460
};
5561
$addUserPicture(
56-
$os->filesystem()->mount(Path::of('/path/to/users/data/')),
62+
$os
63+
->filesystem()
64+
->mount(Path::of('/path/to/users/data/'))
65+
->unwrap(),
5766
'some-unique-id',
5867
File::named(
5968
'picture.png',
@@ -94,10 +103,18 @@ use Innmind\Url\Path;
94103
$path = Path::of('/path/to/some/required/folder/');
95104

96105
if (!$os->filesystem()->contains($path)) {
97-
$os->control()->processes()->execute($mkdirCommand);
106+
$os
107+
->control()
108+
->processes()
109+
->execute($mkdirCommand)
110+
->unwrap();
98111
}
99112

100-
$os->control()->processes()->execute($subProcessCommand);
113+
$os
114+
->control()
115+
->processes()
116+
->execute($subProcessCommand)
117+
->unwrap();
101118
```
102119

103120
See [processes](processes.md) section on how to execute commands on your operating system.
@@ -109,7 +126,10 @@ Sometimes you want to use the `tmp` folder to write down files such as cache tha
109126
```php
110127
use Innmind\Filesystem\Adapter;
111128

112-
$tmp = $os->filesystem()->mount($os->status()->tmp());
129+
$tmp = $os
130+
->filesystem()
131+
->mount($os->status()->tmp())
132+
->unwrap();
113133
$tmp instanceof Adapter; // true
114134
```
115135

@@ -131,10 +151,17 @@ $count = $runTests(
131151
return $continuation->stop($count);
132152
}
133153

134-
$os->control()->processes()->execute($phpunitCommand);
154+
$os
155+
->control()
156+
->processes()
157+
->execute($phpunitCommand)
158+
->unwrap();
135159

136160
return $continuation->continue(++$count);
137161
},
162+
)->match(
163+
static fn(int $count) => $count, // always 42 as it's the stopping value
164+
static fn(\Throwable $e) => throw $e,
138165
);
139166
```
140167

0 commit comments

Comments
 (0)