Skip to content

Commit e765bd8

Browse files
committed
styling
1 parent 5d61e8d commit e765bd8

File tree

10 files changed

+84
-65
lines changed

10 files changed

+84
-65
lines changed

documentation/advanced/logging.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
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).
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).
77

88
```php
99
use Innmind\OperatingSystem\OperatingSystem\Logger;

documentation/index.md

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
hide:
3+
- navigation
4+
- toc
5+
---
6+
17
# Getting started
28

39
This library is here to help abstract all the operations that involve the operating system the PHP code run on.
@@ -8,8 +14,8 @@ The other advantage to use higher level abstractions is to enable end user to bu
814

915
For concrete examples have a look at the use cases available in the sidebar.
1016

11-
> [!NOTE]
12-
> this library is a small overlay on top of a set of individual libraries that contain the concrete abstractions. So you can start using only a subset of abstractions in your code as a starting point.
17+
!!! note ""
18+
This library is a small overlay on top of a set of individual libraries that contain the concrete abstractions. So you can start using only a subset of abstractions in your code as a starting point.
1319

1420
## Installation
1521

@@ -27,21 +33,5 @@ $os = Factory::build();
2733

2834
There's nothing more to add to start using this abstraction. Head toward the use cases to understand all the things you can do with it.
2935

30-
> [!WARNING]
31-
> This library doesn't work on windows environments.
32-
33-
## Use cases
34-
35-
- [Manipulating time](use_cases/time.md)
36-
- [Filesystem](use_cases/filesystem.md)
37-
- [HTTP Client](use_cases/http.md)
38-
- [Processes](use_cases/processes.md)
39-
- [Inter Process Communication](use_cases/ipc.md)
40-
- [Socket communication](use_cases/socket.md)
41-
- [Handling process signals](use_cases/signals.md)
42-
- [SQL connection](use_cases/sql.md)
43-
44-
## Advanced usage
45-
46-
- [Logging all operations](advanced/logging.md)
47-
- [Extensions](advanced/extensions.md)
36+
!!! warning ""
37+
This library doesn't work on windows environments.

documentation/use_cases/filesystem.md

+23-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ use Innmind\Filesystem\{
3737
use Innmind\Url\Path;
3838
use Innmind\Immutable\Predicate\Instance;
3939

40-
$addUserPicture = function(Adapter $filesystem, string $userId, File $picture): void {
40+
$addUserPicture = function(
41+
Adapter $filesystem,
42+
string $userId,
43+
File $picture,
44+
): void {
4145
$filesystem
4246
->get(Name::of($userId))
4347
->keep(Instance::of(Directory::class))
@@ -73,7 +77,9 @@ Example of checking if a `maintenance.lock` exist to prevent your webapp from ru
7377
```php
7478
use Innmind\Url\Path;
7579

76-
if ($os->filesystem()->contains(Path::of('/path/to/project/maintenance.lock'))) {
80+
$path = Path::of('/path/to/project/maintenance.lock');
81+
82+
if ($os->filesystem()->contains($path)) {
7783
throw new \RuntimeException('Application still in maintenance');
7884
}
7985

@@ -85,7 +91,9 @@ Or you could check the existence of a directory that is required for another sub
8591
```php
8692
use Innmind\Url\Path;
8793

88-
if (!$os->filesystem()->contains(Path::of('/path/to/some/required/folder/'))) {
94+
$path = Path::of('/path/to/some/required/folder/');
95+
96+
if (!$os->filesystem()->contains($path)) {
8997
$os->control()->processes()->execute($mkdirCommand);
9098
}
9199

@@ -116,20 +124,23 @@ use Innmind\FileWatch\Continuation;
116124

117125
$runTests = $os->filesystem()->watch(Path::of('/path/to/project/src/'));
118126

119-
$count = $runTests(0, function(int $count, Continuation $continuation) use ($os): Continuation {
120-
if ($count === 42) {
121-
return $continuation->stop($count);
122-
}
127+
$count = $runTests(
128+
0,
129+
function(int $count, Continuation $continuation) use ($os): Continuation {
130+
if ($count === 42) {
131+
return $continuation->stop($count);
132+
}
123133

124-
$os->control()->processes()->execute($phpunitCommand);
134+
$os->control()->processes()->execute($phpunitCommand);
125135

126-
return $continuation->continue(++$count);
127-
});
136+
return $continuation->continue(++$count);
137+
},
138+
);
128139
```
129140

130141
Here it will run phpunit tests every time the `src/` folder changes. Concrete examples of this pattern can be found in [`innmind/lab-station`](https://github.com/Innmind/LabStation/blob/develop/src/Agent/WatchSources.php#L38) to run a suite of tools when sources change.
131142

132143
This operation is a bit like an `array_reduce` as you can keep a state record between each calls of the callable via the first argument (here `0`, but it can be anything) and the argument of your callable will be the previous value returned by `$continuation->continue()`.
133144

134-
> [!WARNING]
135-
> since there is no builtin way to watch for changes in a directory it checks the directory every second, so use it with care. Watching an individual file is a bit safer as it uses the `tail` command so there is no `sleep()` used.
145+
!!! warning ""
146+
Since there is no builtin way to watch for changes in a directory it checks the directory every second, so use it with care. Watching an individual file is a bit safer as it uses the `tail` command so there is no `sleep()` used.

documentation/use_cases/http.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ $response instanceof Response; // true
2828

2929
All elements of a request/response call is built using objects to enforce correctness of the formatted messages.
3030

31-
> [!NOTE]
32-
> since request and responses messages can be viewed either from a client or a server the model is abstracted in the standalone [`innmind/http` library](https://github.com/innmind/http).
31+
!!! note ""
32+
Since request and responses messages can be viewed either from a client or a server the model is abstracted in the standalone [`innmind/http` library](https://github.com/innmind/http).
3333

3434
## Resiliency in a distributed system
3535

@@ -63,5 +63,5 @@ $response = $http($request);
6363
$response = $http($request);
6464
```
6565

66-
> [!NOTE]
67-
> the circuit breaker works on host per host basis meaning if `server1.com` fails then calls to `server2.com` will still be sent.
66+
!!! note ""
67+
The circuit breaker works on host per host basis meaning if `server1.com` fails then calls to `server2.com` will still be sent.

documentation/use_cases/ipc.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ To communicate between processes on a same system there is 2 approaches: sharing
44

55
The later is the safest of the two (but not exempt of problems) and you will find here the building blocks to communicate via a socket.
66

7-
> [!TIP]
8-
> the adage `share state through messages and not messages through state` is a pillar of the [actor model](https://en.wikipedia.org/wiki/Actor_model) and [initially of object oriented programming](https://www.youtube.com/watch?v=7erJ1DV_Tlo).
7+
!!! tip ""
8+
The adage `share state through messages and not messages through state` is a pillar of the [actor model](https://en.wikipedia.org/wiki/Actor_model) and [initially of object oriented programming](https://www.youtube.com/watch?v=7erJ1DV_Tlo).
99

1010
```php
1111
# process acting as a server
@@ -61,5 +61,5 @@ echo $client
6161

6262
In the case the server is started first then the client would print `Hello`.
6363

64-
> [!WARNING]
65-
> this is a very rough implementation of communication between processes. **DO NOT** use this simple implementation in your code, instead use a higher level API such as [`innmind/ipc`](https://github.com/innmind/ipc).
64+
!!! warning ""
65+
This is a very rough implementation of communication between processes. **DO NOT** use this simple implementation in your code, instead use a higher level API such as [`innmind/ipc`](https://github.com/innmind/ipc).

documentation/use_cases/processes.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ $backupRunning = $os
9090
->status()
9191
->processes()
9292
->all()
93-
->any(fn($process): bool => $process->command()->matches(RegExp::of('~my-backup-tool~')));
93+
->any(
94+
fn($process): bool => $process
95+
->command()
96+
->matches(RegExp::of('~my-backup-tool~')),
97+
);
9498

9599
if (!$backupRunning) {
96100
$os->control()->processes()->execute(

documentation/use_cases/signals.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ use Innmind\Immutable\{
1919
Str,
2020
};
2121

22-
$client = $os->remote()->socket(Transport::tcp(), Ur::of('tcp://127.0.0.1:8080')->authority())->match(
23-
static fn($client) => $client,
24-
static fn() => throw new \RuntimeException('Unable to connect to the server'),
25-
);
22+
$client = $os
23+
->remote()
24+
->socket(Transport::tcp(), Url::of('tcp://127.0.0.1:8080')->authority())
25+
->match(
26+
static fn($client) => $client,
27+
static fn() => throw new \RuntimeException('Unable to connect to the server'),
28+
);
2629
$watch = $os->sockets()->watch(new ElapsedPeriod(1000))->forRead($client);
2730
$signaled = true;
28-
$os->process()->signals()->listen(Signal::terminate, function() use (&$signaled) {
29-
$signaled = false;
30-
});
31+
$os
32+
->process()
33+
->signals()
34+
->listen(Signal::terminate, function() use (&$signaled) {
35+
$signaled = false;
36+
});
3137

3238
$receivedData = $client
3339
->timeoutAfter(ElapsedPeriod::of(1_000))
@@ -52,8 +58,8 @@ $client->unwrap()->close();
5258

5359
When the process receive the `SIGTERM` signal it will be paused then the anonymous function will be called and the process will then be resumed.
5460

55-
> [!NOTE]
56-
> signal handling is already performed when using [`innmind/ipc`](https://github.com/innmind/ipc) or [`innmind/amqp`](https://github.com/innmind/amqp) so you don't have to think about it.
61+
!!! note ""
62+
Signal handling is already performed when using [`innmind/ipc`](https://github.com/innmind/ipc) or [`innmind/amqp`](https://github.com/innmind/amqp) so you don't have to think about it.
5763

5864
## Prevent process from being stopped
5965

documentation/use_cases/socket.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ use Innmind\Socket\Internet\Transport;
1717
use Innmind\IP\IPv4;
1818
use Innmind\TimeContinuum\Earth\ElapsedPeriod;
1919

20-
$server = $os->ports()->open(Transport::tcp(), IPv4::localhost(), Port::of(8080))->match(
21-
static fn($server) => $server,
22-
static fn() => throw new \RuntimeException('Unable to start the server'),
23-
);
20+
$server = $os
21+
->ports()
22+
->open(Transport::tcp(), IPv4::localhost(), Port::of(8080))
23+
->match(
24+
static fn($server) => $server,
25+
static fn() => throw new \RuntimeException('Unable to start the server'),
26+
);
2427

2528
while (true) {
2629
$server
@@ -44,10 +47,13 @@ use Innmind\Url\Url;
4447
use Innmind\IO\Readable\Frame;
4548
use Innmind\Socket\Internet\Transport;
4649

47-
$client = $os->remote()->socket(Transport::tcp(), Url::of('tcp://127.0.0.1:8080')->authority())->match(
48-
static fn($client) => $client,
49-
static fn() => throw new \RuntimeException('Unable to connect to the client'),
50-
);
50+
$client = $os
51+
->remote()
52+
->socket(Transport::tcp(), Url::of('tcp://127.0.0.1:8080')->authority())
53+
->match(
54+
static fn($client) => $client,
55+
static fn() => throw new \RuntimeException('Unable to connect to the client'),
56+
);
5157

5258
$receivedData = $client
5359
->watch()

documentation/use_cases/sql.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ You can build a connection to a SQL server like so:
66
use Innmind\Url\Url;
77
use Formal\AccessLayer\Connection;
88

9-
$connection = $os->remote()->sql(Url::of('mysql://127.0.0.1:3306/database_name'));
9+
$connection = $os
10+
->remote()
11+
->sql(Url::of('mysql://127.0.0.1:3306/database_name'));
1012

1113
$connection instanceof Connection; // true
1214
```

documentation/use_cases/time.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Directly accessing time in a PHP code is straightforward (either via `DateTime` or time functions) but it prevents you to build testable code or require to use some hard to understand hacks. Instead it is simpler to think of time as another dependency that you need to inject in your code, thus easier to change the implementation when testing.
44

5-
> [!TIP]
6-
> for a more in length presentation of why directly accessing time is problematic you can watch this [talk](https://www.youtube.com/watch?v=T_I6HhP9-6w) (in french).
5+
??? tip
6+
For a more in length presentation of why directly accessing time is problematic you can watch this [talk](https://www.youtube.com/watch?v=T_I6HhP9-6w) (in french).
77

88
## Accessing time
99

@@ -36,8 +36,8 @@ $crawl = function(CurrentProcess $process, string ...$urls): void {
3636
// crawl the $url and do something with the result
3737

3838
// here for the sake of simplicity we specify 1 second but it can be
39-
// any instance of Innmind\TimeContinuum\Period and you could build it
40-
// from a robots.txt Crawler-Delay directive
39+
// any instance of Innmind\TimeContinuum\Period and you could build
40+
// it from a robots.txt Crawler-Delay directive
4141
$process->halt(new Second(1));
4242
}
4343
};

0 commit comments

Comments
 (0)