Skip to content

Commit c686119

Browse files
Anton Shabovtazloyuser
authored andcommitted
Rename things
1 parent 877ced2 commit c686119

File tree

10 files changed

+156
-214
lines changed

10 files changed

+156
-214
lines changed

examples/events.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Amp\Delayed;
44
use PHPinnacle\Ensign\Dispatcher;
5-
use PHPinnacle\Ensign\Kernel;
5+
use PHPinnacle\Ensign\Processor;
66

77
require __DIR__ . '/../vendor/autoload.php';
88

@@ -20,12 +20,12 @@ public function __construct(string $signal, ...$arguments)
2020

2121
class Publisher
2222
{
23-
private $kernel;
23+
private $processor;
2424
private $listeners = [];
2525

26-
public function __construct(Kernel $kernel)
26+
public function __construct(Processor $processor)
2727
{
28-
$this->kernel = $kernel;
28+
$this->processor = $processor;
2929
}
3030

3131
public function listen(string $signal, callable $listener): self
@@ -38,16 +38,16 @@ public function listen(string $signal, callable $listener): self
3838
public function __invoke(Publish $message)
3939
{
4040
$actions = \array_map(function ($listener) use ($message) {
41-
return $this->kernel->execute($listener, $message->arguments);
41+
return $this->processor->execute($listener, $message->arguments);
4242
}, $this->listeners[$message->signal] ?? []);
4343

4444
yield $actions;
4545
}
4646
}
4747

4848
Amp\Loop::run(function () {
49-
$kernel = new Kernel();
50-
$publisher = new Publisher($kernel);
49+
$processor = new Processor();
50+
$publisher = new Publisher($processor);
5151
$publisher
5252
->listen('print', function ($num) {
5353
for ($i = 0; $i < $num; $i++) {
@@ -72,7 +72,7 @@ public function __invoke(Publish $message)
7272
})
7373
;
7474

75-
$dispatcher = new Dispatcher($kernel);
75+
$dispatcher = new Dispatcher($processor);
7676
$dispatcher
7777
->register(Publish::class, $publisher)
7878
;

examples/parallel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
use PHPinnacle\Ensign\Dispatcher;
4-
use PHPinnacle\Ensign\Kernel;
54
use PHPinnacle\Ensign\Processor;
5+
use PHPinnacle\Ensign\Executor;
66

77
require __DIR__ . '/../vendor/autoload.php';
88

@@ -12,8 +12,8 @@
1212
}
1313

1414
Amp\Loop::run(function () {
15-
$processor = new Processor\ParallelProcessor();
16-
$dispatcher = new Dispatcher(new Kernel($processor));
15+
$executor = new Executor\ParallelExecutor();
16+
$dispatcher = new Dispatcher(new Processor($executor));
1717
$dispatcher->register('load', function ($url) {
1818
echo "Start getting: {$url}" . \PHP_EOL;
1919

@@ -27,5 +27,5 @@
2727
$actionThree = $dispatcher->dispatch('load', 'https://amphp.org');
2828

2929
yield [$actionOne, $actionTwo, $actionThree];
30-
yield $processor->shutdown();
30+
yield $executor->shutdown();
3131
});

src/Dispatcher.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
final class Dispatcher
1616
{
1717
/**
18-
* @var Kernel
18+
* @var Processor
1919
*/
20-
private $kernel;
20+
private $processor;
2121

2222
/**
2323
* @var callable[]
2424
*/
2525
private $handlers = [];
2626

2727
/**
28-
* @param Kernel $kernel
28+
* @param Processor $processor
2929
*/
30-
public function __construct(Kernel $kernel = null)
30+
public function __construct(Processor $processor = null)
3131
{
32-
$this->kernel = $kernel ?: new Kernel();
32+
$this->processor = $processor ?: new Processor();
3333
}
3434

3535
/**
@@ -42,7 +42,7 @@ public function register(string $signal, callable $handler): self
4242
{
4343
$this->handlers[$signal] = $handler;
4444

45-
$this->kernel->interrupt($signal, function (...$arguments) use ($signal) {
45+
$this->processor->interrupt($signal, function (...$arguments) use ($signal) {
4646
return $this->dispatch($signal, ...$arguments);
4747
});
4848

@@ -64,6 +64,6 @@ public function dispatch($signal, ...$arguments): Action
6464
throw new Exception\UnknownSignal($signal);
6565
};
6666

67-
return $this->kernel->execute($handler, $arguments);
67+
return $this->processor->execute($handler, $arguments);
6868
}
6969
}

src/Exception/ActionTimeout.php renamed to src/Executor.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
declare(strict_types = 1);
1212

13-
namespace PHPinnacle\Ensign\Exception;
13+
namespace PHPinnacle\Ensign;
1414

15-
final class ActionTimeout extends EnsignException
15+
interface Executor
1616
{
1717
/**
18-
* @param string $id
18+
* @param callable $handler
19+
* @param array $arguments
20+
*
21+
* @return mixed
1922
*/
20-
public function __construct(string $id)
21-
{
22-
parent::__construct(sprintf('Action "%s" timed out.', $id));
23-
}
23+
public function execute(callable $handler, array $arguments);
2424
}

src/Processor/ParallelProcessor.php renamed to src/Executor/ParallelExecutor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
declare(strict_types = 1);
1212

13-
namespace PHPinnacle\Ensign\Processor;
13+
namespace PHPinnacle\Ensign\Executor;
1414

1515
use Amp\Parallel\Worker\DefaultPool;
1616
use Amp\Parallel\Worker\Pool;
1717
use Amp\ParallelFunctions;
1818
use Amp\Promise;
19-
use PHPinnacle\Ensign\Processor;
19+
use PHPinnacle\Ensign\Executor;
2020

21-
final class ParallelProcessor implements Processor
21+
final class ParallelExecutor implements Executor
2222
{
2323
/**
2424
* @var Pool

src/Processor/SimpleProcessor.php renamed to src/Executor/SimpleExecutor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
declare(strict_types = 1);
1212

13-
namespace PHPinnacle\Ensign\Processor;
13+
namespace PHPinnacle\Ensign\Executor;
1414

15-
use PHPinnacle\Ensign\Processor;
15+
use PHPinnacle\Ensign\Executor;
1616

17-
final class SimpleProcessor implements Processor
17+
final class SimpleExecutor implements Executor
1818
{
1919
/**
2020
* {@inheritdoc}

src/Kernel.php

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)