From cf935f285d62d9c09744d9824d53459943df0999 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 24 May 2025 11:46:35 +0200 Subject: [PATCH 1/4] fix readme --- README.md | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d3b5199..bb96c82 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,10 @@ $os = Factory::build(); ```php use Innmind\Url\Path; -$adapter = $os->filesystem()->mount(Path::of('/var/data/')); +$adapter = $os + ->filesystem() + ->mount(Path::of('/var/data/')) + ->unwrap(); ``` `$adater` is an instance of [`Innmind\Filesystem\Adapter`](http://innmind.github.io/Filesystem/). @@ -55,7 +58,8 @@ use Innmind\Server\Control\Server\Command; $process = $os ->control() ->processes() - ->execute(Command::foreground('echo foo')); + ->execute(Command::foreground('echo foo')) + ->unwrap(); ``` `$process` is an instance of [`Innmind\Server\Control\Server\Process`](https://github.com/innmind/servercontrol#usage). @@ -74,13 +78,10 @@ $server = $os IPv4::localhost(), Port::of(1337), ) - ->match( - static fn($server) => $server->unwrap(), - static fn() => throw new \RuntimeException('Cannot open the socket'), - ); + ->unwrap(); ``` -`$server` is an instance of [`Innmind\Socket\Server`](https://github.com/innmind/socket#internet-socket). +`$server` is an instance of [`Innmind\IO\Sockets\Servers\Server`](https://innmind.org/io/sockets/). ### Want to open a local socket ? @@ -88,25 +89,25 @@ $server = $os # process A use Innmind\Socket\Address\Unix; -$server = $os->sockets()->open(Unix::of('/tmp/foo.sock'))->match( - static fn($server) => $server->unwrap(), - static fn() => throw new \RuntimeException('Cannot open the socket'), -); +$server = $os + ->sockets() + ->open(Unix::of('/tmp/foo.sock')) + ->unwrap(); ``` -`$server` is an instance of [`Innmind\Socket\Server`](https://github.com/innmind/socket#unix-socket). +`$server` is an instance of [`Innmind\IO\Sockets\Servers\Server`](https://innmind.org/io/sockets/). ```php # process B use Innmind\Socket\Address\Unix; -$client = $os->sockets()->connectTo(Unix::of('/tmp/foo.sock'))->match( - static fn($client) => $client->unwrap(), - static fn() => throw new \RuntimeException('Cannot connect to the socket'), -); +$client = $os + ->sockets() + ->connectTo(Unix::of('/tmp/foo.sock')) + ->unwrap(); ``` -`$client` is an instance of `Innmind\Socket\Client`. +`$client` is an instance of [`Innmind\IO\Sockets\Clients\Client`](https://innmind.org/io/sockets/#clients). ### Want to execute commands on a remote server ? @@ -118,7 +119,8 @@ $process = $os ->remote() ->ssh(Url::of('ssh://user@server-address:1337')) ->processes() - ->execute(Command::foreground('ls')); + ->execute(Command::foreground('ls')) + ->unwrap(); ``` `$process` is an instance of [`Innmind\Server\Control\Server\Process`](https://github.com/innmind/servercontrol#usage). @@ -127,15 +129,15 @@ $process = $os ```php use Innmind\Http\{ - Message\Request\Request, - Message\Method, + Request, + Method, ProtocolVersion, }; use Innmind\Url\Url; $response = $os ->remote() - ->http()(new Request( + ->http()(Request::of( Url::of('http://example.com'), Method::get, ProtocolVersion::v20, @@ -145,15 +147,15 @@ $response = $os ### Want to access current process id ? ```php -$os->process()->id(); +$os->process()->id()->unwrap(); ``` ### Want to pause the current process ? ```php -use Innmind\TimeContinuum\Earth\Period\Minute; +use Innmind\TimeContinuum\Period; -$os->process()->halt(new Minute(1)); +$os->process()->halt(Period::minute(1)); ``` ### Want to listen for a signal ? From 8def69c4f0f0d223cf7768babc8676806e0d0f28 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 24 May 2025 13:29:36 +0200 Subject: [PATCH 2/4] update documentation with new APIs --- documentation/advanced/logging.md | 10 +-- documentation/use_cases/filesystem.md | 41 ++++++++++-- documentation/use_cases/http.md | 8 +-- documentation/use_cases/ipc.md | 95 ++++++++++++++------------- documentation/use_cases/processes.md | 67 ++++++++++++------- documentation/use_cases/signals.md | 20 +++--- documentation/use_cases/socket.md | 29 ++++---- documentation/use_cases/time.md | 6 +- 8 files changed, 159 insertions(+), 117 deletions(-) diff --git a/documentation/advanced/logging.md b/documentation/advanced/logging.md index 71860c2..8f10a68 100644 --- a/documentation/advanced/logging.md +++ b/documentation/advanced/logging.md @@ -2,16 +2,12 @@ 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. -!!! note "" - 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). - ```php -use Innmind\OperatingSystem\OperatingSystem\Logger; +use Innmind\OperatingSystem\Config\Logger; use Psr\Log\LoggerInterface; -$os = Logger::psr( - $os, - /* any instance of LoggerInterface */ +$os = $os->map( + Logger::psr(/* any instance of LoggerInterface */), ); ``` diff --git a/documentation/use_cases/filesystem.md b/documentation/use_cases/filesystem.md index 2f7fe93..0e097d3 100644 --- a/documentation/use_cases/filesystem.md +++ b/documentation/use_cases/filesystem.md @@ -17,8 +17,14 @@ $backup = function(Adapter $source, Adapter $target): void { }); }; $backup( - $os->filesystem()->mount(Path::of('/path/to/source/')), - $os->filesystem()->mount(Path::of('/path/to/target/')), + $os + ->filesystem() + ->mount(Path::of('/path/to/source/')) + ->unwrap(), + $os + ->filesystem() + ->mount(Path::of('/path/to/target/')) + ->unwrap(), ); ``` @@ -53,7 +59,10 @@ $addUserPicture = function( ); }; $addUserPicture( - $os->filesystem()->mount(Path::of('/path/to/users/data/')), + $os + ->filesystem() + ->mount(Path::of('/path/to/users/data/')) + ->unwrap(), 'some-unique-id', File::named( 'picture.png', @@ -94,10 +103,18 @@ use Innmind\Url\Path; $path = Path::of('/path/to/some/required/folder/'); if (!$os->filesystem()->contains($path)) { - $os->control()->processes()->execute($mkdirCommand); + $os + ->control() + ->processes() + ->execute($mkdirCommand) + ->unwrap(); } -$os->control()->processes()->execute($subProcessCommand); +$os + ->control() + ->processes() + ->execute($subProcessCommand) + ->unwrap(); ``` 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 ```php use Innmind\Filesystem\Adapter; -$tmp = $os->filesystem()->mount($os->status()->tmp()); +$tmp = $os + ->filesystem() + ->mount($os->status()->tmp()) + ->unwrap(); $tmp instanceof Adapter; // true ``` @@ -131,10 +151,17 @@ $count = $runTests( return $continuation->stop($count); } - $os->control()->processes()->execute($phpunitCommand); + $os + ->control() + ->processes() + ->execute($phpunitCommand) + ->unwrap(); return $continuation->continue(++$count); }, +)->match( + static fn(int $count) => $count, // always 42 as it's the stopping value + static fn(\Throwable $e) => throw $e, ); ``` diff --git a/documentation/use_cases/http.md b/documentation/use_cases/http.md index 13e2d0b..9a430a8 100644 --- a/documentation/use_cases/http.md +++ b/documentation/use_cases/http.md @@ -36,10 +36,10 @@ All elements of a request/response call is built using objects to enforce correc One of the first things taught when working with distributed systems is that they will intermittently fail. To prevent your app to crash for an occasional failure a common pattern is the _retry pattern_ with a backoff strategy allowing the client to retry safe requests a certain amount of time before giving up. You can use this pattern like so: ```php -use Innmind\OperatingSystem\OperatingSystem\Resilient; +use Innmind\OperatingSystem\Config\Resilient; use Innmind\HttpTransport\ExponentialBackoff; -$os = Resilient::of($os); +$os = $os->map(Resilient::new()); $http = $os->remote()->http(); $http instanceof ExponentialBackoff; // true ``` @@ -48,12 +48,12 @@ Another strategy you can add on top of that is the [circuit breaker pattern](htt ```php use Innmind\HttpTransport\CircuitBreaker; -use Innmind\TimeContinuum\Earth\Period\Minute; +use Innmind\TimeContinuum\Period; $http = CircuitBreaker::of( $http, $os->clock(), - new Minute(1), + Period::minute(1), ); $request = Request::of(/* ...args */) $response = $http($request); diff --git a/documentation/use_cases/ipc.md b/documentation/use_cases/ipc.md index db2d5cf..8e042fd 100644 --- a/documentation/use_cases/ipc.md +++ b/documentation/use_cases/ipc.md @@ -7,57 +7,60 @@ The later is the safest of the two (but not exempt of problems) and you will fin !!! tip "" 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). -```php -# process acting as a server -use Innmind\Socket\Address\Unix as Address; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; -use Innmind\Immutable\{ - Sequence, - Str, -}; +=== "Server" + ```php + use Innmind\IO\Sockets\Unix\Address; + use Innmind\Url\Path; + use Innmind\TimeContinuum\Period; + use Innmind\Immutable\{ + Sequence, + Str, + }; -$server = $os->sockets()->open(Address::of('/tmp/foo'))->match( - static fn($server) => $server, - static fn() => throw new \RuntimeException('Unable to start the server'), -); -$watch = $os->sockets()->watch(new ElapsedPeriod(1000))->forRead($server); + $server = $os + ->sockets() + ->open(Address::of(Path::of('/tmp/foo'))) + ->unwrap(); + ->timeoutAfter(Period::second(1)); -while (true) { - $_ = $server - ->timeoutAfter(ElapsedPeriod::of(1_000)) - ->accept() - ->match( - static fn($client) => $client - ->send(Sequence::of(Str::of('Hello'))) - ->flatMap(static fn() => $client->close()) - ->match( - static fn() => null, // everyhting is ok - static fn() => throw new \RuntimeException('Unable to send data or close the connection'), - ), - static fn() => null, // no new connection available - ), -} -``` + while (true) { + $_ = $server + ->accept() + ->match( + static fn($client) => $client + ->sink(Sequence::of(Str::of('Hello'))) + ->flatMap(static fn() => $client->close()) + ->match( + static fn() => null, // everyhting is ok + static fn(\Throwable $e) => throw $e, + ), + static fn() => null, // no new connection available + ), + } + ``` -```php -# process acting as client -use Innmind\Socket\Address\Unix as Address; -use Innmind\IO\Readable\Frame; +=== "Client" + ```php + use Innmind\IO\{ + Sockets\Unix\Address, + Frame, + }; + use Innmind\Url\Path; -$client = $os->sockets()->connectTo(Address::of('/tmp/foo'))->match( - static fn($client) => $client, - static fn() => throw new \RuntimeException('Unable to connect to the server'), -); + $client = $os + ->sockets() + ->connectTo(Address::of(Path::of('/tmp/foo'))) + ->unwrap(); -echo $client - ->watch() - ->frames(Frame\Chunk::of(5)) - ->one() - ->match( - static fn($data) => $data->toString(), - static fn() => 'unable to read the stream', - ); -``` + echo $client + ->watch() + ->frames(Frame::chunk(5)->strict()) + ->one() + ->match( + static fn($data) => $data->toString(), + static fn() => 'unable to read the stream', + ); + ``` In the case the server is started first then the client would print `Hello`. diff --git a/documentation/use_cases/processes.md b/documentation/use_cases/processes.md index 9d9b9eb..87abaaf 100644 --- a/documentation/use_cases/processes.md +++ b/documentation/use_cases/processes.md @@ -12,12 +12,23 @@ use Innmind\Server\Control\Server\{ Signal, }; -$webserver = $os->control()->processes()->execute( - Command::foreground('php') - ->withShortOption('S', 'localhost:8080'), -); +$webserver = $os + ->control() + ->processes() + ->execute( + Command::foreground('php') + ->withShortOption('S', 'localhost:8080'), + ) + ->unwrap(); // do some stuff -$os->control()->processes()->kill($webserver->pid(), Signal::kill); +$webserver->pid()->match( + static fn($pid) => $os + ->control() + ->processes() + ->kill($pid, Signal::kill) + ->unwrap(), + static fn() => null, // background processes don't have a pid +); ``` Here we start the PHP builtin webserver and perform some imaginary action before killing it, but you could also wait the process to finish (see below) instead of killing it (in the case of the webserver it never finishes unless with a crash). @@ -25,10 +36,14 @@ Here we start the PHP builtin webserver and perform some imaginary action before ```php use Innmind\Server\Control\Server\Command; -$webserver = $os->control()->processes()->execute( - Command::foreground('php') - ->withShortOption('S', 'localhost:8080'), -); +$webserver = $os + ->control() + ->processes() + ->execute( + Command::foreground('php') + ->withShortOption('S', 'localhost:8080'), + ) + ->unwrap(); $webserver->wait(); ``` @@ -37,10 +52,14 @@ Or you could start the process as an independent one (meaning you can't control ```php use Innmind\Server\Control\Server\Command; -$os->control()->processes()->execute( - Command::background('php') - ->withShortOption('S', 'localhost:8080'), -); +$os + ->control() + ->processes() + ->execute( + Command::background('php') + ->withShortOption('S', 'localhost:8080'), + ) + ->unwrap(); ``` ## Executing processes on a remote machine @@ -63,7 +82,7 @@ $installMariadb($os->remote()->ssh(Url::of('ssh://user@replication2'))); ```php use Innmind\Server\Status\Server\Process; -use Innmind\TimeContinuum\Earth\Format\ISO8601; +use Innmind\TimeContinuum\Format; $os->status()->processes()->all()->foreach(function(Process $process): void { \printf( @@ -71,7 +90,7 @@ $os->status()->processes()->all()->foreach(function(Process $process): void { $process->command()->toString(), $process->user()->toString(), $process->start()->match( - static fn($date) => $date->format(new ISO8601), + static fn($date) => $date->format(Format::iso8601()), static fn() => 'unknown start date', ), ); @@ -97,9 +116,13 @@ $backupRunning = $os ); if (!$backupRunning) { - $os->control()->processes()->execute( - Command::background('my-backup-tool'), - ); + $os + ->control() + ->processes() + ->execute( + Command::background('my-backup-tool'), + ) + ->unwrap(); } ``` @@ -108,8 +131,8 @@ if (!$backupRunning) { ```php use Innmind\Url\Url; -$os->control()->reboot(); -$os->control()->shutdown(); -$os->remote()->ssh(Url::of('ssh://user@remote-server'))->reboot(); -$os->remote()->ssh(Url::of('ssh://user@remote-server'))->shutdown(); +$os->control()->reboot()->unwrap(); +$os->control()->shutdown()->unwrap(); +$os->remote()->ssh(Url::of('ssh://user@remote-server'))->reboot()->unwrap(); +$os->remote()->ssh(Url::of('ssh://user@remote-server'))->shutdown()->unwrap(); ``` diff --git a/documentation/use_cases/signals.md b/documentation/use_cases/signals.md index e8b9666..3200f7d 100644 --- a/documentation/use_cases/signals.md +++ b/documentation/use_cases/signals.md @@ -10,9 +10,11 @@ This is a reuse of the [socket example](socket.md). ```php use Innmind\Url\Url; -use Innmind\IO\Readable\Frame; -use Innmind\Socket\Internet\Transport; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\IO\{ + Sockets\Internet\Transport, + Frame, +}; +use Innmind\TimeContinuum\Period; use Innmind\Signals\Signal; use Innmind\Immutable\{ Sequence, @@ -22,11 +24,7 @@ use Innmind\Immutable\{ $client = $os ->remote() ->socket(Transport::tcp(), Url::of('tcp://127.0.0.1:8080')->authority()) - ->match( - static fn($client) => $client, - static fn() => throw new \RuntimeException('Unable to connect to the server'), - ); -$watch = $os->sockets()->watch(new ElapsedPeriod(1000))->forRead($client); + ->unwrap(); $signaled = true; $os ->process() @@ -36,13 +34,13 @@ $os }); $receivedData = $client - ->timeoutAfter(ElapsedPeriod::of(1_000)) + ->timeoutAfter(Period::second(1)) // it sends this every second to keep the connection alive ->heartbeatWith(static fn() => Sequence::of(Str::of('foo'))) ->abortWhen(function() use (&$signaled) { return $signaled; }) - ->frames(Frame\Chunk::of(1)) + ->frames(Frame::chunk(1)->strict()) ->one() ->match( static fn() => true, @@ -53,7 +51,7 @@ if ($receivedData) { echo 'Server has responded'. } -$client->unwrap()->close(); +$client->close()->unwrap(); ``` 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. diff --git a/documentation/use_cases/socket.md b/documentation/use_cases/socket.md index 41c3894..165c73d 100644 --- a/documentation/use_cases/socket.md +++ b/documentation/use_cases/socket.md @@ -3,6 +3,7 @@ This topic is similar to the [Inter Process Communication](ipc.md) but address talking to a socket through a specific network port (either locally or remotely). As you'll see below working with sockets ([`.sock`](ipc.md) or a port) is always the same workflow: + - open a socket (client or server) - watch for them to be ready to read - perform an action on the socket when ready @@ -13,21 +14,18 @@ The use case is not very common as you need to define a protocol and implement s ```php use Innmind\Url\Authority\Port; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\Sockets\Internet\Transport; use Innmind\IP\IPv4; -use Innmind\TimeContinuum\Earth\ElapsedPeriod; +use Innmind\TimeContinuum\Period; $server = $os ->ports() ->open(Transport::tcp(), IPv4::localhost(), Port::of(8080)) - ->match( - static fn($server) => $server, - static fn() => throw new \RuntimeException('Unable to start the server'), - ); + ->unwrap() + ->timeoutAfter(Period::second(1)); while (true) { $server - ->timeoutAfter(ElapsedPeriod::of(1_000)) ->accept() ->match( static fn($client) => /* talk to the client */, @@ -44,20 +42,17 @@ This example will open a connection to the server defined above but can be chang ```php use Innmind\Url\Url; -use Innmind\IO\Readable\Frame; -use Innmind\Socket\Internet\Transport; +use Innmind\IO\{ + Sockets\Internet\Transport, + Frame, +}; -$client = $os +$receivedData = $os ->remote() ->socket(Transport::tcp(), Url::of('tcp://127.0.0.1:8080')->authority()) - ->match( - static fn($client) => $client, - static fn() => throw new \RuntimeException('Unable to connect to the client'), - ); - -$receivedData = $client + ->unwrap() ->watch() - ->frames(Frame\Chunk::of(1)) + ->frames(Frame::chunk(1)->strict()) ->one() ->match( static fn() => true, diff --git a/documentation/use_cases/time.md b/documentation/use_cases/time.md index debe5ca..2ac2b16 100644 --- a/documentation/use_cases/time.md +++ b/documentation/use_cases/time.md @@ -11,7 +11,7 @@ Directly accessing time in a PHP code is straightforward (either via `DateTime` use Innmind\TimeContinuum\PointInTime; $isItMonday = function(PointInTime $point): bool { - return $point->day()->weekNumber() === 1; // 0 for sunday + return $point->day()->ofWeek()->toInt() === 1; // 0 for sunday }; $now = $os->clock()->now(); @@ -29,7 +29,7 @@ In some cases you may want your program to wait for a certain amount of time bef ```php use Innmind\OperatingSystem\CurrentProcess; -use Innmind\TimeContinuum\Earth\Period\Second; +use Innmind\TimeContinuum\Period; $crawl = function(CurrentProcess $process, string ...$urls): void { foreach ($urls as $url) { @@ -38,7 +38,7 @@ $crawl = function(CurrentProcess $process, string ...$urls): void { // here for the sake of simplicity we specify 1 second but it can be // any instance of Innmind\TimeContinuum\Period and you could build // it from a robots.txt Crawler-Delay directive - $process->halt(new Second(1)); + $process->halt(Period::second(1)); } }; $crawl($os->process(), 'http://google.com', 'http://github.com'); From 394d5fc6ded697a62e01d5aa306b3c6d7bcd907f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 24 May 2025 13:40:46 +0200 Subject: [PATCH 3/4] remove irrelevant changelog entry --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 524e3e5..b1df7c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,6 @@ - Requires `innmind/time-warp:~4.0` - Requires `innmind/io:~3.2` - Requires `innmind/immutable:~5.15` -- `Innmind\OperatingSystem\Config::withHttpHeartbeat()` period is now expressed with a `Innmind\TimeContinuum\Period` - `Innmind\OperatingSystem\CurrentProcess::id()` now returns an `Innmind\Immutable\Attempt` - `Innmind\OperatingSystem\CurrentProcess::halt()` now returns `Innmind\Immutable\Attempt` - `Innmind\OperatingSystem\Filesystem::mount()` now returns an `Innmind\Immutable\Attempt` From e5264de7852cbabf2991c8ed043a59660e74463b Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sat, 24 May 2025 13:55:36 +0200 Subject: [PATCH 4/4] add upgrade doc for the next major release --- documentation/upgrade/v5-to-v6.md | 165 ++++++++++++++++++++++++++++++ mkdocs.yml | 2 + 2 files changed, 167 insertions(+) create mode 100644 documentation/upgrade/v5-to-v6.md diff --git a/documentation/upgrade/v5-to-v6.md b/documentation/upgrade/v5-to-v6.md new file mode 100644 index 0000000..1aa0946 --- /dev/null +++ b/documentation/upgrade/v5-to-v6.md @@ -0,0 +1,165 @@ +# V5 to V6 + +### Resilient decorator + +=== "Before" + ```php + use Innmind\OperatingSystem\OperatingSystem\Resilient; + + $os = Resilient::of($os); + ``` +=== "After" + ```php + use Innmind\OperatingSystem\Config\Resilient; + + $os = $os->map(Resilient::new()); + ``` + +### Logger decorator + +=== "Before" + ```php + use Innmind\OperatingSystem\OperatingSystem\Logger; + use Psr\Log\LoggerInterface + + $os = Logger::psr($os, /* instance of LoggerInterface */); + ``` +=== "After" + ```php + use Innmind\OperatingSystem\Config\Logger; + + $os = $os->map(Logger::psr(/* instance of LoggerInterface */)); + ``` + +### HTTP client config + +=== "Before" + ```php + use Innmind\OperatingSystem\{ + Factory, + Config, + }; + use Innmind\TimeContinuum\Earth\ElapsedPeriod; + + $os = Factory::build( + Config::of() + ->disableSSLVerification() + ->limitHttpConcurrencyTo(10) + ->withHttpHeartbeat( + ElapsedPeriod::of(1_000), + static fn() => 'heartbeat', + ), + ); + ``` + +=== "After" + ```php + use Innmind\OperatingSystem\{ + Factory, + Config, + }; + use Innmind\HttpTransport\Curl; + use Innmind\TimeContinuum\Period; + + $config = Config::new(); + $os = Factory::build( + $config->useHttpTransport( + Curl::of($config->clock(), $config->io()) + ->disableSSLVerification() + ->maxConcurrency(10) + ->heartbeat( + Period::second(1), + static fn() => 'heartbeat', + ), + ), + ); + ``` + +### Filesystem config + +=== "Before" + ```php + use Innmind\OperatingSystem\{ + Factory, + Config, + }; + use Innmind\Filesystem\CaseSensitivity; + + $os = Factory::build( + Config::of()->caseInsensitiveFilesystem( + CaseSensitivity::insensitive, + ), + ); + ``` + +=== "After" + ```php + use Innmind\OperatingSystem\{ + Factory, + Config, + }; + use Innmind\Filesystem\{ + Adapter\Filesystem, + CaseSensitivity, + }; + + $os = Factory::build( + Config::new()->mountFilesystemVia( + static fn(Path $path, Config $config) => Filesystem::mount( + $path, + $config->io(), + )->withCaseSentitivity( + CaseSensitivity::insensitive, + ), + ), + ); + ``` + +### Current process id + +=== "Before" + ```php + $os->process()->id(); + ``` + +=== "After" + ```php + $os->process()->id()->unwrap(); + ``` + +### Halt current process + +=== "Before" + ```php + use Innmind\TimeContinuum\Earth\Period\Second; + + $os->process()->halt(new Second(1)); + ``` + +=== "After" + ```php + use Innmind\TimeContinuum\Period; + + $os->process()->halt(Period::second(1))->unwrap(); + ``` + +### Mount filesystem + +=== "Before" + ```php + use Innmind\Url\Path; + + $adapter = $os + ->filesystem() + ->mount(Path::of('somewhere/')); + ``` + +=== "After" + ```php + use Innmind\Url\Path; + + $adapter = $os + ->filesystem() + ->mount(Path::of('somewhere/')) + ->unwrap(); + ``` diff --git a/mkdocs.yml b/mkdocs.yml index 544c185..6376964 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -16,6 +16,8 @@ nav: - Advanced usage: - Logging all operations: advanced/logging.md - Extensions: advanced/extensions.md + - Upgrade: + - upgrade/v5-to-v6.md theme: name: material