Skip to content

Commit

Permalink
Merge pull request #8 from Jeckel-Lab/command-bus
Browse files Browse the repository at this point in the history
Command bus
  • Loading branch information
jeckel authored Feb 14, 2020
2 parents 18a4272 + 1dd8cb0 commit cda77fb
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ before_script:

script:
# - ./vendor/bin/phpunit --coverage-clover=coverage.xml
- ./vendor/bin/phpmd src text cleancode,codesize,design,naming,unusedcode
- ./vendor/bin/phpmd src text ./ruleset.xml
- ./vendor/bin/phpcs
# - ./vendor/bin/phpstan analyse
- ./vendor/bin/psalm
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
"php": "^7.2",
"symfony/dependency-injection": "^4.3 || ^5.0",
"symfony/http-kernel": "^4.3 || ^5.0",
"jeckel-lab/command-dispatcher": "^0.1",
"symfony/config": "^4.3 || ^5.0"
"jeckel-lab/command-dispatcher": "^0.2",
"symfony/config": "^4.3 || ^5.0",
"symfony/doctrine-bridge": "^4.3 || ^5.0",
"doctrine/orm": "^2.7"
}
,
"require-dev": {
"roave/security-advisories": "dev-master",
"vimeo/psalm": "^3.8",
"phpmd/phpmd": "^2.8",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5",
"phpro/grumphp": "^0.17.2"
},
"license": "MIT",
"authors": [
Expand Down
19 changes: 19 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
tasks:
phpcs: null
phpmd:
whitelist_patterns:
- /^src\/(.*)/
ruleset:
- ./ruleset.xml
psalm:
config: psalm.xml
no_cache: true
report: ~
# ignore_patterns:
# - /^tests/
threads: 1
triggered_by: ['php']
show_info: true

phpunit: null
21 changes: 21 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
My custom rule set that checks my code...
</description>

<rule ref="rulesets/cleancode.xml">
<exclude name="IfStatementAssignment" />
</rule>

<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/unusedcode.xml" />
</ruleset>
52 changes: 52 additions & 0 deletions src/CommandBus/Decorator/EntityFlushDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @author Julien Mercier-Rojas <[email protected]>
* Created at : 03/02/2020
*/

declare(strict_types=1);

namespace JeckelLab\CommandDispatcherBundle\CommandBus\Decorator;

use Doctrine\ORM\EntityManagerInterface;
use JeckelLab\CommandDispatcher\Command\CommandInterface;
use JeckelLab\CommandDispatcher\CommandBus\CommandBusInterface;
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponseInterface;

/**
* Class EntityFlushDecorator
* @package App\Core\CommandBus
*/
class EntityFlushDecorator implements CommandBusInterface
{
/** @var CommandBusInterface */
protected $next;

/** @var EntityManagerInterface */
protected $entityManager;

/**
* EntityFlushDecorator constructor.
* @param CommandBusInterface $next
* @param EntityManagerInterface $entityManager
*/
public function __construct(CommandBusInterface $next, EntityManagerInterface $entityManager)
{
$this->next = $next;
$this->entityManager = $entityManager;
}

/**
* @param CommandInterface $command
* @return CommandResponseInterface
*/
public function dispatch(CommandInterface $command): CommandResponseInterface
{
$response = $this->next->dispatch($command);

$this->entityManager->flush();

return $response;
}
}
15 changes: 14 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@
<argument type="service" id="jeckellab.command.handler.resolver" />
<argument type="service" id="event_dispatcher" />
</service>
<service id="jeckellab.command.bus.command_dispatcher" class="JeckelLab\CommandDispatcher\CommandBus\CommandDispatcher">
<argument type="service" id="jeckellab.command.handler.resolver" />
</service>
<service id="jeckellab.command.bus.entity_flush_decorator" class="JeckelLab\CommandDispatcherBundle\CommandBus\Decorator\EntityFlushDecorator">
<argument type="service" id="jeckellab.command.bus.command_dispatcher" />
<argument type="service" id="doctrine.orm.default_entity_manager" />
</service>
<service id="jeckellab.command.bus.event_dispatcher_decorator" class="JeckelLab\CommandDispatcher\CommandBus\EventDispatcherDecorator">
<argument type="service" id="event_dispatcher" />
<argument type="service" id="jeckellab.command.bus.entity_flush_decorator" />
</service>

<service id="jeckellab.command.handler.resolver" class="JeckelLab\CommandDispatcher\Resolver\CommandHandlerResolver" public="false">
<argument>%command_handler.handlers.map%</argument>
<argument type="service" id="service_container" />
</service>

<service id="JeckelLab\CommandDispatcher\CommandDispatcherInterface" alias="jeckellab.command.dispatcher"/>
<service id="JeckelLab\CommandDispatcher\CommandDispatcherInterface" alias="jeckellab.command.bus.event_dispatcher_decorator"/>
<service id="JeckelLab\CommandDispatcher\CommandBus\CommandBusInterface" alias="jeckellab.command.bus.event_dispatcher_decorator"/>
</services>
</container>

0 comments on commit cda77fb

Please sign in to comment.