Skip to content

Commit 64dca11

Browse files
committed
Merge branch 'psr-event-dispatcher'
2 parents be72bcc + 9988fe7 commit 64dca11

40 files changed

+533
-195
lines changed

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"composer-runtime-api": "^2.2",
99
"lkrms/dice": "^4.1.6",
1010
"psr/container": "^2",
11+
"psr/event-dispatcher": "^1",
1112
"psr/log": "^1"
1213
},
1314
"suggest": {
@@ -18,7 +19,7 @@
1819
"clue/phar-composer": "Simplifies creation of phar archives"
1920
},
2021
"require-dev": {
21-
"adodb/adodb-php": "^5.22",
22+
"adodb/adodb-php": "^5",
2223
"analog/analog": "^1",
2324
"clue/phar-composer": "^1",
2425
"firebase/php-jwt": "^6",
@@ -29,6 +30,9 @@
2930
"phpunit/phpunit": "^9",
3031
"sebastian/diff": "^4 || ^5"
3132
},
33+
"provide": {
34+
"psr/event-dispatcher-implementation": "^1"
35+
},
3236
"autoload": {
3337
"psr-4": {
3438
"Lkrms\\": "src/"

lk-util/Command/Generate/GenerateTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function run(string ...$args)
135135
$extendsGenerality = $generality;
136136
}
137137
}
138-
};
138+
}
139139
}
140140

141141
$this->Extends[] = $classPrefix . (

src/Cli/CliCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ final public function setName(array $name): void
207207
}
208208

209209
/**
210-
* Get the command name as a string of space-delimited subcommands
210+
* @inheritDoc
211211
*/
212212
final public function name(): string
213213
{

src/Cli/Contract/ICliCommandNode.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
use Lkrms\Cli\Catalog\CliHelpSectionName;
66
use Lkrms\Cli\CliCommand;
7-
use Lkrms\Contract\ReturnsContainer;
8-
use Lkrms\Contract\ReturnsDescription;
9-
use Lkrms\Contract\ReturnsEnvironment;
7+
use Lkrms\Contract\HasContainer;
8+
use Lkrms\Contract\HasDescription;
9+
use Lkrms\Contract\HasEnvironment;
1010
use LogicException;
1111

1212
/**
1313
* A node in a CLI command tree
1414
*
15-
* @extends ReturnsContainer<ICliApplication>
15+
* @extends HasContainer<ICliApplication>
1616
*
1717
* @see CliCommand
1818
*/
19-
interface ICliCommandNode extends ReturnsContainer, ReturnsEnvironment, ReturnsDescription
19+
interface ICliCommandNode extends HasContainer, HasEnvironment, HasDescription
2020
{
2121
/**
2222
* Get the command name as a string of space-delimited subcommands

src/Concept/Facade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Lkrms\Contract\ReceivesFacade;
99
use Lkrms\Facade\Event;
1010
use Lkrms\Support\EventDispatcher;
11+
use Lkrms\Support\ServiceEvent;
1112
use RuntimeException;
1213

1314
/**
@@ -58,12 +59,14 @@ private static function _load()
5859
? $instance
5960
: Event::getInstance();
6061
$id = $dispatcher->listen(
61-
'container.global.set',
62-
function (?IContainer $container) use ($service, $instance): void {
62+
function (ServiceEvent $event) use ($service, $instance): void {
63+
/** @var IContainer|null */
64+
$container = $event->service();
6365
if ($container) {
6466
$container->instanceIf($service, $instance);
6567
}
66-
}
68+
},
69+
Container::EVENT_GLOBAL_CONTAINER_SET,
6770
);
6871
self::$ListenerIds[static::class] = $id;
6972

src/Concept/Provider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ abstract protected function getDateFormatter(): IDateFormatter;
4343
/**
4444
* @inheritDoc
4545
*/
46-
public function description(): ?string
46+
public function description(): string
4747
{
48-
return null;
48+
throw new MethodNotImplementedException(
49+
static::class,
50+
__FUNCTION__,
51+
IProvider::class
52+
);
4953
}
5054

5155
/**

src/Container/Container.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Lkrms\Contract\ReceivesContainer;
1515
use Lkrms\Contract\ReceivesService;
1616
use Lkrms\Facade\Event;
17+
use Lkrms\Support\ServiceEvent;
1718
use Psr\Container\ContainerInterface;
1819
use Closure;
1920
use ReflectionClass;
@@ -27,6 +28,8 @@
2728
*/
2829
class Container extends FluentInterface implements IContainer
2930
{
31+
public const EVENT_GLOBAL_CONTAINER_SET = self::class . '::globalContainerSet';
32+
3033
private static ?IContainer $GlobalContainer = null;
3134

3235
private Dice $Dice;
@@ -149,7 +152,7 @@ final public static function requireGlobalContainer(): IContainer
149152
*/
150153
final public static function setGlobalContainer(?IContainer $container): ?IContainer
151154
{
152-
Event::dispatch('container.global.set', $container);
155+
Event::dispatch(new ServiceEvent(self::EVENT_GLOBAL_CONTAINER_SET, $container));
153156

154157
self::$GlobalContainer = $container;
155158

src/Contract/HasContainer.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lkrms\Contract;
4+
5+
/**
6+
* @template T of IContainer
7+
*/
8+
interface HasContainer
9+
{
10+
/**
11+
* Get the object's service container
12+
*
13+
* @return T
14+
*/
15+
public function app(): IContainer;
16+
17+
/**
18+
* Get the object's service container
19+
*
20+
* @return T
21+
*/
22+
public function container(): IContainer;
23+
}

src/Contract/HasDescription.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lkrms\Contract;
4+
5+
interface HasDescription extends HasName
6+
{
7+
/**
8+
* Get a description of the object
9+
*/
10+
public function description(): string;
11+
}

src/Contract/ReturnsEnvironment.php renamed to src/Contract/HasEnvironment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Returns a shared instance of Lkrms\Utility\Env
99
*/
10-
interface ReturnsEnvironment
10+
interface HasEnvironment
1111
{
1212
/**
1313
* Get a shared instance of Lkrms\Utility\Env

0 commit comments

Comments
 (0)