This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(boot-manager): Don't boot not bootable objects
- Service decorators `K911\Swoole\Server\RequestHandler\RequestHandlerInterface` were autoconfigured with `swoole_bundle.bootable_service` tag, due to base service being bootable - Move most logic of boot manager to happen at compile time Fixes #19
- Loading branch information
Showing
6 changed files
with
67 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace K911\Swoole\Server\Runtime; | ||
|
||
use Assert\Assertion; | ||
use K911\Swoole\Component\GeneratedCollection; | ||
|
||
final class CallableBootManagerFactory | ||
{ | ||
public function make(iterable $bootableCollection, BootableInterface ...$bootables): CallableBootManager | ||
{ | ||
$objectRegistry = []; | ||
$isAlreadyRegistered = function (int $id) use (&$objectRegistry): bool { | ||
$result = !isset($objectRegistry[$id]); | ||
$objectRegistry[$id] = true; | ||
|
||
return $result; | ||
}; | ||
|
||
return new CallableBootManager( | ||
(new GeneratedCollection($bootableCollection, ...$bootables)) | ||
->filter(function ($bootable) use ($isAlreadyRegistered): bool { | ||
Assertion::isInstanceOf($bootable, BootableInterface::class); | ||
|
||
return $isAlreadyRegistered(\spl_object_id($bootable)); | ||
}) | ||
->map(function (BootableInterface $bootable): callable { | ||
return [$bootable, 'boot']; | ||
}) | ||
); | ||
} | ||
} |