Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
### Changed

- #5: Preserve and restore previous signal handler. Refactored event dispatcher.

### Removed

- #5: Removed the method `addListener` from the `ProcessManager` class. Add
  signal/normal listeners through the event dispatcher on the process manager.

### Fixed

- #7: Fixed missing null terminator handling on shared memory blocks.
- #8: Fixed parent's shutdown function being executed in child processes.
  • Loading branch information
TheLevti committed Feb 1, 2020
2 parents 1f5ed45 + 2f9bc7d commit c6ca782
Show file tree
Hide file tree
Showing 25 changed files with 1,590 additions and 201 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.github export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/coverage export-ignore
/php_cs.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.php_cs
/.phpunit.result.cache
/composer.lock
/coverage
/phpstan.neon
/phpunit.xml
/vendor
396 changes: 396 additions & 0 deletions .phan/config.php

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ php:
- 7.4
- nightly

env:
matrix:
- PREFER_LOWEST="--prefer-lowest"
- PREFER_LOWEST=""

matrix:
fast_finish: true
allow_failures:
- php: nightly

install:
- composer install --no-progress --no-scripts --no-suggest --no-interaction
- composer update --no-progress --no-scripts --no-suggest --no-interaction --prefer-stable $PREFER_LOWEST

script:
- vendor/bin/phpcs --standard=PSR12 src/ tests/
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.0] - 2019-11-29

### Changed

- #5: Preserve and restore previous signal handler. Refactored event dispatcher.

### Removed

- #5: Removed the method `addListener` from the `ProcessManager` class. Add
signal/normal listeners through the event dispatcher on the process manager.

### Fixed

- #7: Fixed missing null terminator handling on shared memory blocks.
- #8: Fixed parent's shutdown function being executed in child processes.

## [1.0.0] - 2019-11-29

### Added
Expand Down Expand Up @@ -38,5 +54,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added serializable objects for exit and error messages.

[Unreleased]: https://github.com/TheLevti/spork/compare/0.3.0...HEAD
[2.0.0]: https://github.com/TheLevti/spork/releases/2.0.0
[1.0.0]: https://github.com/TheLevti/spork/releases/1.0.0
[0.3.0]: https://github.com/TheLevti/spork/releases/0.3.0
27 changes: 22 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@
"rss": "https://github.com/TheLevti/spork/commits/master.atom"
},
"require": {
"php": ">=7.2.0",
"symfony/event-dispatcher": ">=3.0.0"
"php": "^7.2.0",
"symfony/event-dispatcher": "^4.0.0 || ^5.0.0"
},
"require-dev": {
"ext-pcntl": "*",
"ext-posix": "*",
"ext-shmop": "*",
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.11.19",
"phpunit/phpunit": "^8.4",
"squizlabs/php_codesniffer": "^3.5"
"phan/phan": "^2.4",
"phpstan/phpstan": "^0.12.4",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5",
"symfony/var-dumper": "^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -68,6 +70,7 @@
"/.github",
"/.gitignore",
"/.travis.yml",
"/coverage",
"/php_cs.dist",
"/phpstan.neon.dist",
"/phpunit.xml.dist",
Expand All @@ -76,5 +79,19 @@
},
"config": {
"sort-packages": true
},
"scripts": {
"all": [
"composer cs",
"composer csf",
"composer static",
"composer test",
"composer coverage"
],
"cs": "vendor/bin/phpcs --standard=PSR12 src/ tests/",
"csf": "vendor/bin/php-cs-fixer fix",
"static": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit",
"coverage": "vendor/bin/phpunit --coverage-html coverage"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: max
level: 5
paths:
- src
- tests
Expand Down
39 changes: 0 additions & 39 deletions src/Spork/EventDispatcher/EventDispatcher.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Spork/EventDispatcher/EventDispatcherInterface.php

This file was deleted.

103 changes: 103 additions & 0 deletions src/Spork/EventDispatcher/SignalEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

/*
* This file is part of the thelevti/spork package.
*
* (c) Petr Levtonov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Spork\EventDispatcher;

use Symfony\Contracts\EventDispatcher\Event as BaseEvent;

/**
* Holds the signal information.
*/
class SignalEvent extends BaseEvent
{
/**
* Event prefix used to construct the full event name, which contains the
* signal number.
*
* @var string PREFIX
*/
private const PREFIX = 'spork.signal.';

/**
* The signal being handled.
*
* @var int $signo
*/
private $signo;

/**
* If operating systems supports siginfo_t structures, this will be an array
* of signal information dependent on the signal.
*
* @var mixed
*/
private $signinfo;

/**
* Gets the event name for a signal number.
*
* @param int $signo A signal number.
* @return string The event name for a signal number.
*/
public static function getEventName(int $signo): string
{
return self::PREFIX . $signo;
}

/**
* Constructs a new instance of the Event class.
*
* @param int $signo The signal being handled.
* @param mixed $signinfo If operating systems supports siginfo_t
* structures, this will be an array of signal
* information dependent on the signal.
*/
public function __construct(int $signo, $signinfo)
{
$this->signo = $signo;
$this->signinfo = $signinfo;
}

/**
* Gets the signal being handled.
*
* @return int The signal being handled.
*/
public function getSigno(): int
{
return $this->signo;
}

/**
* If operating systems supports siginfo_t structures, this will get the
* array of signal information dependent on the signal.
*
* @return mixed If operating systems supports siginfo_t structures, this
* will be an array of signal information dependent on the
* signal.
*/
public function getSigninfo()
{
return $this->signinfo;
}

/**
* Gets the event name of the signal being handled.
*
* @return string The event name of the signal being handled.
*/
public function getName(): string
{
return static::getEventName($this->getSigno());
}
}
26 changes: 26 additions & 0 deletions src/Spork/EventDispatcher/SignalEventDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the thelevti/spork package.
*
* (c) Petr Levtonov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Spork\EventDispatcher;

use Symfony\Component\EventDispatcher\EventDispatcher;

/**
* Extends the core event dispatcher with signal handling capabilities. Add and
* remove signal listeners or dispatch a signal directly.
*/
class SignalEventDispatcher extends EventDispatcher implements
SignalEventDispatcherInterface
{
use SignalEventDispatcherTrait;
}
59 changes: 59 additions & 0 deletions src/Spork/EventDispatcher/SignalEventDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the thelevti/spork package.
*
* (c) Petr Levtonov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Spork\EventDispatcher;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Extends the core event dispatcher interface with signal handling
* capabilities. Add and remove signal listeners or dispatch a signal directly.
*/
interface SignalEventDispatcherInterface extends EventDispatcherInterface
{
/**
* Signal handler that dispatches events.
*
* @param int $signo The signal being handled.
* @param mixed $signinfo If operating systems supports siginfo_t
* structures, this will be an array of signal
* information dependent on the signal.
* @return \Spork\EventDispatcher\SignalEvent Holds the signal information.
*/
public function dispatchSignal(int $signo, $signinfo): SignalEvent;

/**
* Adds a signal listener that listens on the specified signal.
*
* @param int $signo The signal number.
* @param callable $listener The listener.
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain
* (defaults to 0)
* @return void
*/
public function addSignalListener(
int $signo,
callable $listener,
int $priority = 0
): void;

/**
* Removes a signal listener from the specified signal.
*
* @param int $signo The signal to remove a listener from.
* @param callable $listener The listener to remove.
* @return void
*/
public function removeSignalListener(int $signo, callable $listener): void;
}
Loading

0 comments on commit c6ca782

Please sign in to comment.