Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add psr/container bridge #7

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ $chief = new Chief(new SynchronousCommandBus, [new LoggingDecorator($logger)]);

Now, whenever `Chief::execute()` is called, the command will be passed to `LoggingDecorator::execute()`, which will perform some log action, and then pass the command to the relevant `CommandHandler`.

Chief provides you with two decorators out-the-box:
Chief provides you with some decorators out-the-box:

- *LoggingDecorator*: Log before and after all executions to a `Psr\Log\LoggerInterface`
- *EventDispatchingDecorator*: Dispatch an event to a `Chief\Decorators\EventDispatcher` after every command execution.
Expand Down Expand Up @@ -368,6 +368,13 @@ $resolver = new NativeCommandHandlerResolver(new \Chief\Bridge\League\LeagueCont
$chief = new Chief(new \Chief\Busses\SynchronousCommandBus($resolver));
```

`Psr\Container` compatible container:

```php
$resolver = new NativeCommandHandlerResolver(new \Chief\Bridge\Psr\PsrContainer($psrContainer));
$chief = new Chief(new \Chief\Busses\SynchronousCommandBus($resolver));
```

## Contributing

We welcome any contributions to Chief. They can be made via GitHub issues or pull requests.
Expand Down
18 changes: 18 additions & 0 deletions src/Bridge/Psr/PsrContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Chief\Bridge\Psr;

use Chief\Container;

class PsrContainer implements Container
{
public function __construct(\Psr\Container\ContainerInterface $container)
{
$this->container = $container;
}

public function make($class)
{
return $this->container->get($class);
}
}
27 changes: 27 additions & 0 deletions tests/Bridge/Psr/PsrContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Chief\Bridge\Psr;

use Chief\ChiefTestCase;
use Illuminate\Container\Container;
use Psr\Container\ContainerInterface;

class PsrContainerTest extends ChiefTestCase
{
public function testMakeHitsInnerContainer()
{
$inner = $this->prophesize(ContainerInterface::class);
$container = new PsrContainer($inner->reveal());
$inner->get('stdClass')->shouldBeCalled()->willReturn(new \stdClass());

$made = $container->make('stdClass');
$this->assertTrue($made instanceof \stdClass);
}

public function testMakeReturnsExpectedInstance()
{
$container = new PsrContainer(new Container());
$made = $container->make('stdClass');
$this->assertTrue($made instanceof \stdClass);
}
}