Skip to content

Commit ab165c7

Browse files
committed
Command locator event
1 parent cde559f commit ab165c7

File tree

10 files changed

+317
-0
lines changed

10 files changed

+317
-0
lines changed

src/CommandLocatorEvent.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Foundation;
4+
5+
use League\Event\AbstractEvent;
6+
use WyriHaximus\Tactician\CommandHandler\Mapper;
7+
8+
final class CommandLocatorEvent extends AbstractEvent
9+
{
10+
const NAME = 'api-clients.foundation.command-locator';
11+
12+
/**
13+
* @var array
14+
*/
15+
private $map = [];
16+
17+
/**
18+
* @return CommandLocatorEvent
19+
*/
20+
public static function create(): CommandLocatorEvent
21+
{
22+
return new self();
23+
}
24+
25+
private function __construct()
26+
{
27+
}
28+
29+
/**
30+
* @return string
31+
*/
32+
public function getName()
33+
{
34+
return self::NAME;
35+
}
36+
37+
/**
38+
* @param string $path
39+
* @param string $namespace
40+
*/
41+
public function add(string $path, string $namespace)
42+
{
43+
$this->map += Mapper::map($path, $namespace);
44+
}
45+
46+
/**
47+
* @return array
48+
*/
49+
public function getMap(): array
50+
{
51+
return $this->map;
52+
}
53+
}

test_app/CommandBus/Command.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandBus;
4+
5+
use ApiClients\Foundation\CommandInterface;
6+
use function React\Promise\resolve;
7+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler as HandlerAnnotation;
8+
9+
10+
/**
11+
* @HandlerAnnotation("ApiClients\TestApp\Foundation\CommandBus\Handler")
12+
*/
13+
final class Command
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $array;
19+
20+
/**
21+
* @param array $array
22+
*/
23+
public function __construct(array $array)
24+
{
25+
$this->array = $array;
26+
}
27+
28+
/**
29+
* @return array
30+
*/
31+
public function getArray(): array
32+
{
33+
return $this->array;
34+
}
35+
}

test_app/CommandBus/Handler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandBus;
4+
5+
use React\Promise\PromiseInterface;
6+
use function React\Promise\resolve;
7+
8+
final class Handler
9+
{
10+
public function handle(): PromiseInterface
11+
{
12+
return resolve([
13+
'follow' => 'https://twitter.com/another_clue',
14+
]);
15+
}
16+
}

test_app/CommandPlane/Command.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandPlane;
4+
5+
use ApiClients\Foundation\CommandInterface;
6+
use function React\Promise\resolve;
7+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler as HandlerAnnotation;
8+
9+
10+
/**
11+
* @HandlerAnnotation("ApiClients\TestApp\Foundation\CommandPlane\Handler")
12+
*/
13+
final class Command
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $array;
19+
20+
/**
21+
* @param array $array
22+
*/
23+
public function __construct(array $array)
24+
{
25+
$this->array = $array;
26+
}
27+
28+
/**
29+
* @return array
30+
*/
31+
public function getArray(): array
32+
{
33+
return $this->array;
34+
}
35+
}

test_app/CommandPlane/Handler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandPlane;
4+
5+
use React\Promise\PromiseInterface;
6+
use function React\Promise\resolve;
7+
8+
final class Handler
9+
{
10+
public function handle(): PromiseInterface
11+
{
12+
return resolve([
13+
'follow' => 'https://twitter.com/another_clue',
14+
]);
15+
}
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandSubmarine;
4+
5+
use ApiClients\Foundation\CommandInterface;
6+
use function React\Promise\resolve;
7+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler as HandlerAnnotation;
8+
9+
10+
/**
11+
* @HandlerAnnotation("ApiClients\TestApp\Foundation\CommandSubmarine\Handler")
12+
*/
13+
final class Command
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $array;
19+
20+
/**
21+
* @param array $array
22+
*/
23+
public function __construct(array $array)
24+
{
25+
$this->array = $array;
26+
}
27+
28+
/**
29+
* @return array
30+
*/
31+
public function getArray(): array
32+
{
33+
return $this->array;
34+
}
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandSubmarine;
4+
5+
use React\Promise\PromiseInterface;
6+
use function React\Promise\resolve;
7+
8+
final class Handler
9+
{
10+
public function handle(): PromiseInterface
11+
{
12+
return resolve([
13+
'follow' => 'https://twitter.com/another_clue',
14+
]);
15+
}
16+
}

test_app/CommandTruck/Command.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandTruck;
4+
5+
use ApiClients\Foundation\CommandInterface;
6+
use function React\Promise\resolve;
7+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler as HandlerAnnotation;
8+
9+
10+
/**
11+
* @HandlerAnnotation("ApiClients\TestApp\Foundation\CommandTruck\Handler")
12+
*/
13+
final class Command
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $array;
19+
20+
/**
21+
* @param array $array
22+
*/
23+
public function __construct(array $array)
24+
{
25+
$this->array = $array;
26+
}
27+
28+
/**
29+
* @return array
30+
*/
31+
public function getArray(): array
32+
{
33+
return $this->array;
34+
}
35+
}

test_app/CommandTruck/Handler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\TestApp\Foundation\CommandTruck;
4+
5+
use React\Promise\PromiseInterface;
6+
use function React\Promise\resolve;
7+
8+
final class Handler
9+
{
10+
public function handle(): PromiseInterface
11+
{
12+
return resolve([
13+
'follow' => 'https://twitter.com/another_clue',
14+
]);
15+
}
16+
}

tests/CommandLocatorEventTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Tests\Foundation;
4+
5+
use ApiClients\Foundation\CommandLocatorEvent;
6+
use ApiClients\Tools\TestUtilities\TestCase;
7+
8+
final class CommandLocatorEventTest extends TestCase
9+
{
10+
public function testName()
11+
{
12+
$this->assertSame(CommandLocatorEvent::NAME, CommandLocatorEvent::create()->getName());
13+
}
14+
15+
public function testEvent()
16+
{
17+
$event = CommandLocatorEvent::create();
18+
19+
$this->assertSame([], $event->getMap());
20+
21+
$event->add(
22+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'test_app' . DIRECTORY_SEPARATOR . 'CommandBus',
23+
'ApiClients\TestApp\Foundation\CommandBus'
24+
);
25+
$this->assertSame([
26+
'ApiClients\TestApp\Foundation\CommandBus\Command' => 'ApiClients\TestApp\Foundation\CommandBus\Handler',
27+
], $event->getMap());
28+
29+
$event->add(
30+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'test_app' . DIRECTORY_SEPARATOR . 'CommandTruck',
31+
'ApiClients\TestApp\Foundation\CommandTruck'
32+
);
33+
$this->assertSame([
34+
'ApiClients\TestApp\Foundation\CommandBus\Command' => 'ApiClients\TestApp\Foundation\CommandBus\Handler',
35+
'ApiClients\TestApp\Foundation\CommandTruck\Command' => 'ApiClients\TestApp\Foundation\CommandTruck\Handler',
36+
], $event->getMap());
37+
38+
$event->add(
39+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'test_app' . DIRECTORY_SEPARATOR . 'CommandPlane',
40+
'ApiClients\TestApp\Foundation\CommandPlane'
41+
);
42+
$this->assertSame([
43+
'ApiClients\TestApp\Foundation\CommandBus\Command' => 'ApiClients\TestApp\Foundation\CommandBus\Handler',
44+
'ApiClients\TestApp\Foundation\CommandTruck\Command' => 'ApiClients\TestApp\Foundation\CommandTruck\Handler',
45+
'ApiClients\TestApp\Foundation\CommandPlane\Command' => 'ApiClients\TestApp\Foundation\CommandPlane\Handler',
46+
], $event->getMap());
47+
48+
$event->add(
49+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'test_app' . DIRECTORY_SEPARATOR . 'CommandSubmarine',
50+
'ApiClients\TestApp\Foundation\CommandSubmarine'
51+
);
52+
$this->assertSame([
53+
'ApiClients\TestApp\Foundation\CommandBus\Command' => 'ApiClients\TestApp\Foundation\CommandBus\Handler',
54+
'ApiClients\TestApp\Foundation\CommandTruck\Command' => 'ApiClients\TestApp\Foundation\CommandTruck\Handler',
55+
'ApiClients\TestApp\Foundation\CommandPlane\Command' => 'ApiClients\TestApp\Foundation\CommandPlane\Handler',
56+
'ApiClients\TestApp\Foundation\CommandSubmarine\Command' => 'ApiClients\TestApp\Foundation\CommandSubmarine\Handler',
57+
], $event->getMap());
58+
59+
}
60+
}

0 commit comments

Comments
 (0)