Skip to content

Commit

Permalink
Version25
Browse files Browse the repository at this point in the history
Adding command bus and separate out command handling from domain.

I opted for <a href="https://github.com/SimpleBus"
target="_blank">SimpleBus</a> because I liked the simplicity and have a lot of
respect for it's maintainer Mathias.

I did have <a href="SimpleBus/CommandBus#2"
target="_blank">some misgivings over the use of a type hint for
commands</a>, but
generally it suited what I needed to do well, it also forced me to
create an explicit CommandHandling layer, which I think works quite
well. It's been completely changed in version 2 now anyway, and is <a
href="https://github.com/SimpleBus/MessageBus" target="_blank">more
of a generic 'MessageBus' now</a>.

There are quite a few command buses that have popped up recently, I
created <a href="https://github.com/jenkoian/CommandBusCommandBus"
target="_blank">CommandBusCommandBus</a> as a case in point. Anyway the
point is I wanted to introduce a command bus to make my example
complete.

Here you can see how I've moved all the command handling bits to the
CommandHandling later I spoke about above. It just means that rather
than passing command to handlers directly, I can just 'throw' them on to
the command bus now. This has the advantages of being able to decorate
the command bus to be able to perform additional tasks against commands
should I want to; I can make the command bus handle commands
asynchronously should I choose; plus other niceities that arise when
delegating message handling in this way.
  • Loading branch information
jenkoian committed Jan 20, 2015
1 parent 4fdc5ed commit a9ca03a
Show file tree
Hide file tree
Showing 16 changed files with 406 additions and 64 deletions.
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle(),

// House Bundles
new Jenko\HouseBundle\JenkoHouseBundle(),
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"phpspec/phpspec": "~2.0@RC"
"phpspec/phpspec": "~2.0@RC",
"simple-bus/symfony-bridge": "~1.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3",
Expand Down
313 changes: 312 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace spec\Jenko\House\Handler;
namespace spec\Jenko\HouseCommandHandlingHandler;

use Jenko\House\Command\EnterRoomCommand;
use Jenko\House\Event\EventDispatcherInterface;
use Jenko\House\Factory\HomeAloneHouseFactory;
use Jenko\HouseCommandHandling\Command\EnterRoomCommand;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

Expand All @@ -17,7 +17,7 @@ function let(EventDispatcherInterface $dispatcher)

function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Handler\EnterRoomHandler');
$this->shouldHaveType('Jenko\HouseCommandHandling\Handler\EnterRoomHandler');
}

function it_dispatches_events(EventDispatcherInterface $dispatcher)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace spec\Jenko\House\Handler;
namespace spec\Jenko\HouseCommandHandling\Handler;

use Jenko\House\Command\ExitRoomCommand;
use Jenko\HouseCommandHandling\Command\ExitRoomCommand;
use Jenko\House\Event\EventDispatcherInterface;
use Jenko\House\Factory\HomeAloneHouseFactory;
use PhpSpec\ObjectBehavior;
Expand All @@ -17,7 +17,7 @@ function let(EventDispatcherInterface $dispatcher)

function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Handler\ExitRoomHandler');
$this->shouldHaveType('Jenko\HouseCommandHandling\Handler\ExitRoomHandler');
}

function it_dispatches_events(EventDispatcherInterface $dispatcher)
Expand Down
8 changes: 0 additions & 8 deletions src/Jenko/House/Command/EnterRoomCommand.php

This file was deleted.

Loading

0 comments on commit a9ca03a

Please sign in to comment.