Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  update documentation
  remove useless annotations
  use the Config to specify the way to halt the process
  add OperatingSystem::map()
  force using the clock from the config
  inject the IO abstraction everywhere possible
  remove unused dependency
  force injecting the Config
  simplify the factory arguments
  remove OS\Unix::config()
  use http and filesystem 7
  test against php 8.3
  drop php 8.1 support
  use blackbox 5
  use psalm 5
  remove deprecated code
  • Loading branch information
Baptouuuu committed Oct 22, 2023
2 parents 32a9f99 + 1b3e2da commit 5d896d7
Show file tree
Hide file tree
Showing 37 changed files with 308 additions and 799 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.1', '8.2']
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
steps:
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2']
php-version: ['8.2', '8.3']
dependencies: ['lowest', 'highest']
name: 'Psalm'
steps:
Expand All @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1']
php-version: ['8.2']
name: 'CS'
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor
.phpunit.result.cache
.phpunit.cache
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 4.0.0 - 2023-10-22

### Added

- `Innmind\OperatingSystem\OperatingSystem::map()`
- `Innmind\OperatingSystem\Config::haltProcessVia()`

### Changed

- `Innmind\OperatingSystem\Factory::build()` now only accept a `Config` object, use `Config::withClock()` to change the default clock

### Removed

- `Innmind\OperatingSystem\CurrentProcess::fork()`
- `Innmind\OperatingSystem\CurrentProcess::children()`
- `Innmind\OperatingSystem\CurrentProcess\Children`
- `Innmind\OperatingSystem\CurrentProcess\Child`
- `Innmind\OperatingSystem\CurrentProcess\ForkFailed`
- Support for PHP `8.1`

## 3.8.0 - 2023-09-10

### Deprecated
Expand Down
54 changes: 1 addition & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $adapter = $os->filesystem()->mount(Path::of('/var/data/'));

### Want to list processes running on the system ?

`$os->status()->processes()->all()` will return a map of [`Inmmind\Immutable\Map<int, Innmind\Server\Status\Server\Process>`](https://github.com/innmind/serverstatus#usage).
`$os->status()->processes()->all()` will return a map of [`Inmmind\Immutable\Set<Innmind\Server\Status\Server\Process>`](https://github.com/innmind/serverstatus#usage).

### Want to run a command on the system ?

Expand Down Expand Up @@ -140,54 +140,6 @@ $response = $os
$os->process()->id();
```

### Want to fork the current process ?

```php
use Innmind\OperatingSystem\CurrentProcess\{
Child,
ForkFailed,
};

$childSide = static function(): void {
try {
// do something in the child process
exit(0);
} catch (\Throwable $e) {
exit(1);
}
};
$parentSide = static function(Child $child): void {
// do something with the child
};
$os
->process()
->fork()
->match(
static fn() => $childSide(),
static fn($left) => match (true) {
$left instanceof Child => $parentSide($left),
$left instanceof ForkFailed => throw new \RuntimeException('Unable to fork the process'),
},
);
```

### Want to wait for child process to finish ?

```php
use Innmind\OperatingSystem\CurrentProcess\Child;

$os
->process()
->fork()
->match(
static fn() => \sleep(10), // child side
static fn($left) => match (true) {
$left instanceof Child => $left->wait(),
default => null,
},
);
```

### Want to pause the current process ?

```php
Expand All @@ -205,7 +157,3 @@ $os->process()->signals()->listen(Signal::terminate, function() {
// handle the signal here
});
```

**Note**: when forking the process the child will have all listeners resetted to avoid having the listener called twice (in the parent and the child).

**Important**: beware when sending a signal right after a fork, there is a [case](tests/CurrentProcess/GenericTest.php#L126) where the listeners can still be called in the child.
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
"issues": "http://github.com/Innmind/OperatingSystem/issues"
},
"require": {
"php": "~8.1",
"php": "~8.2",
"innmind/time-continuum": "~3.0",
"innmind/server-status": "~4.0",
"innmind/server-control": "~5.0",
"innmind/filesystem": "~6.2",
"innmind/filesystem": "~7.1",
"innmind/socket": "~6.0",
"innmind/http-transport": "~6.4",
"innmind/http-transport": "~7.0",
"innmind/time-warp": "~3.0",
"innmind/signals": "~3.0",
"innmind/file-watch": "~3.1",
"innmind/stream": "~4.0",
"formal/access-layer": "^2.0"
"formal/access-layer": "^2.0",
"innmind/io": "~2.2"
},
"autoload": {
"psr-4": {
Expand All @@ -39,11 +40,11 @@
}
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"phpunit/phpunit": "~10.2",
"innmind/url": "~4.0",
"innmind/ip": "~3.0",
"vimeo/psalm": "~4.30",
"innmind/black-box": "^4.8",
"vimeo/psalm": "~5.15",
"innmind/black-box": "~5.5",
"innmind/coding-standard": "~2.0"
}
}
13 changes: 7 additions & 6 deletions documentation/use_cases/filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ use Innmind\Filesystem\{
Name,
};
use Innmind\Url\Path;
use Innmind\Immutable\Predicate\Instance;

$addUserPicture = function(Adapter $filesystem, string $userId, File $picture): void {
$filesystem
->get(new Name($userId))
->filter(static fn($file) => $file instanceof Directory)
->otherwise(static fn() => Directory\Directory::named($userId))
->get(Name::of($userId))
->keep(Instance::of(Directory::class))
->otherwise(static fn() => Directory::named($userId))
->map(static fn($directory) => $directory->add($picture))
->match(
static fn($directory) => $filesystem->add($directory),
Expand All @@ -50,10 +51,10 @@ $addUserPicture = function(Adapter $filesystem, string $userId, File $picture):
$addUserPicture(
$os->filesystem()->mount(Path::of('/path/to/users/data/')),
'some-unique-id',
File\File::named(
File::named(
'picture.png',
Content\AtPath::of(
Path::of($_FILES['some_file']['tmp_name']),
Content::ofString(
\file_get_contents($_FILES['some_file']['tmp_name']),
),
),
);
Expand Down
12 changes: 6 additions & 6 deletions documentation/use_cases/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

```php
use Innmind\Http\{
Message\Request\Request,
Message\Method,
Message\Response,
Request,
Method,
Response,
ProtocolVersion,
};
use Innmind\Url\Url;

$http = $os->remote()->http();

$response = $http(new Request(
$response = $http(Request::of(
Url::of('https://github.com'),
Method::get,
ProtocolVersion::v20,
Expand All @@ -38,7 +38,7 @@ One of the first things taught when working with distributed systems is that the
use Innmind\OperatingSystem\OperatingSystem\Resilient;
use Innmind\HttpTransport\ExponentialBackoff;

$os = new Resilient($os);
$os = Resilient::of($os);
$http = $os->remote()->http();
$http instanceof ExponentialBackoff; // true
```
Expand All @@ -54,7 +54,7 @@ $http = CircuitBreaker::of(
$os->clock(),
new Minute(1),
);
$request = new Request(/* ...args */)
$request = Request::of(/* ...args */)
$response = $http($request);
// if the previous call failed then the next call wil not even be sent to the
// server and the client will respond immediately unless 1 minute has elapsed
Expand Down
21 changes: 13 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" printerClass="Innmind\BlackBox\PHPUnit\ResultPrinterV9" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory=".phpunit.cache">
<extensions>
<bootstrap class="Innmind\BlackBox\PHPUnit\Extension">
</bootstrap>
</extensions>
<coverage/>
<testsuites>
<testsuite name="Test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>.</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedCode="false"
findUnusedBaselineEntry="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
Loading

0 comments on commit 5d896d7

Please sign in to comment.