Skip to content

Commit

Permalink
Merge pull request #18 from ecentria/EXP-5463
Browse files Browse the repository at this point in the history
EXP-5463 - improving bundle
  • Loading branch information
githoober authored Mar 24, 2023
2 parents 7bd4adb + 28c5cbf commit 7a6cce5
Show file tree
Hide file tree
Showing 26 changed files with 462 additions and 85 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
/.idea
composer.lock
composer.phar
/Tests/Controller/App/cache/*
/Tests/Controller/App/logs/*
/tests/Integration/App/var/
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache

php: ~

matrix:
fast_finish: true
include:
- php: 7.0
env: SYMFONY_VERSION=^3.4 JMS_SERIALIZER=^1.1
- php: 7.0
env: SYMFONY_VERSION=^3.4 JMS_SERIALIZER=^2.0
- php: 7.2
env: SYMFONY_VERSION=^3.4 JMS_SERIALIZER=^3.0
- php: 7.3
env: SYMFONY_VERSION=^4.4 JMS_SERIALIZER=^2.0
- php: 7.3
env: SYMFONY_VERSION=^4.4 JMS_SERIALIZER=^3.0


before_script:
- phpenv config-rm xdebug.ini
- if [[ "$SYMFONY_VERSION" != "" ]]; then composer require --dev --no-update symfony/symfony=$SYMFONY_VERSION jms/serializer-bundle=$JMS_SERIALIZER; fi
- COMPOSER_MEMORY_LIMIT=-1 composer update ${COMPOSER_FLAGS} --no-interaction

script:
- vendor/bin/phpunit --coverage-clover clover


4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Generic consumer and standard event message model meanth to pull in a domain eve
Documentation
-------------

Documentation for Ecentria Rest Bundle is in [Resources/doc/index.md](Resources/doc/index.md)
Documentation for Ecentria Rest Bundle is in [Resources/doc/index.md](src/Resources/doc/index.md)

Installation
------------

Installation instructions can be found in the [documentation](Resources/doc/setup.md)
Installation instructions can be found in the [documentation](src/Resources/doc/setup.md)

License
-------
Expand Down
23 changes: 9 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ecentria/ecentria-apievents-bundle",
"type": "symfony-bundle",
"minimum-stability": "dev",
"minimum-stability": "stable",
"description": "Generic consumer and standard event message model meant to pull in a domain event message from rabbitmq and repeat it as a symfony event to all listening services",
"keywords": ["ecentria", "library", "events", "rabbitmq"],
"homepage": "https://github.com/ecentria/EcentriaAPIEventsBundle",
Expand All @@ -12,25 +12,20 @@
"email": "justin.shanks@opticsplant.com"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/ecentria/EcentriaAPIEventsBundle"
}
],
"require": {
"php": ">=5.3.2",
"symfony/event-dispatcher": "~2.5 | ~3.0 | ~4.0",
"php": ">=7.0",
"symfony/event-dispatcher": "^3.0|^4.0|^5.0",
"php-amqplib/rabbitmq-bundle": "1.*",
"jms/serializer-bundle": "~0.13 | ~1.1 | ~2.0"
"jms/serializer-bundle": "^1.1|^2.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*"
"phpunit/phpunit": "^6.5",
"symfony/framework-bundle": "^3.4|^4.0"
},
"autoload": {
"psr-4": { "Ecentria\\Libraries\\EcentriaAPIEventsBundle\\": "" }
"psr-4": { "Ecentria\\Libraries\\EcentriaAPIEventsBundle\\": "src/" }
},
"branch-alias": {
"dev-master": "0.0.x-dev"
"autoload-dev": {
"psr-4": { "Ecentria\\Libraries\\EcentriaAPIEventsBundle\\Tests\\": "tests/" }
}
}
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
33 changes: 0 additions & 33 deletions phpunit.xml.dist

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand All @@ -15,7 +16,7 @@
use JMS\Serializer\SerializerInterface;
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Message\AMQPMessage;
use Ecentria\Libraries\EcentriaAPIEventsBundle\Services\MessageDispatcher;
use Ecentria\Libraries\EcentriaAPIEventsBundle\Services\MessageDispatcher;

/**
* Message Consumer
Expand Down Expand Up @@ -70,21 +71,21 @@ public function __construct(MessageDispatcher $messageDispatcher, SerializerInte
* @param AMQPMessage $msg The message
* @throws \InvalidArgumentException
*
* @return mixed Message status
* @return bool|int Message status
*/
public function execute(AMQPMessage $msg)
{
if (is_null($this->messageClassName)) {
if ($this->messageClassName === null) {
throw new \InvalidArgumentException('You have to specify Domain class name');
}

/** @var MessageInterface $message */
try {
$message = $this->serializer
->deserialize($msg->body, $this->messageClassName, 'json');
$message = $this->serializer->deserialize($msg->body, $this->messageClassName, 'json');
$this->messageDispatcher->dispatchMessage($message);
} catch (ResponseException $e) {
if ($e->stopConsuming()) {
$msg->delivery_info['channel']->basic_cancel($msg->delivery_info['consumer_tag']);
if ($e->stopConsuming() && ($channel = $msg->getChannel())) {
$channel->basic_cancel($msg->getConsumerTag());
}
return $e->getFlag();
}
Expand All @@ -98,7 +99,7 @@ public function execute(AMQPMessage $msg)
*
* @return void
*/
public function setMessageClassName($messageClassName)
public function setMessageClassName(string $messageClassName)
{
$this->messageClassName = $messageClassName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand All @@ -12,6 +13,7 @@

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Ecentria\Libraries\EcentriaAPIEventsBundle\Model\Message;

/**
* This is the class that validates and merges configuration from your app/config files
Expand All @@ -25,7 +27,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritDoc}
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
Expand All @@ -43,14 +45,10 @@ public function getConfigTreeBuilder()
$rootNode
->children()
->scalarNode('domain_message_prefix')->defaultValue('domain.')->end()
->scalarNode('domain_message_serializer')->cannotBeEmpty()->end()
->scalarNode('domain_message_class_name')
->defaultValue('Ecentria\Libraries\EcentriaAPIEventsBundle\Model\Message')
->end()
->scalarNode('domain_message_serializer')->cannotBeEmpty()->isRequired()->end()
->scalarNode('domain_message_class_name')->defaultValue(Message::class)->end()
->end();



return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand All @@ -20,8 +21,6 @@
* This is the class that loads and manages your bundle configuration
*
* @author Justin Shanks <justin.shanks@opticsplanet.com>
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class EcentriaAPIEventsExtension extends Extension
{
Expand All @@ -39,11 +38,13 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter($this->getAlias() . '.domain_message_prefix', $config['domain_message_prefix']);

$container->getDefinition('ecentria.api.domain_message.manager')
->addMethodCall('setEventPrefix', [$config['domain_message_prefix']]);
->addMethodCall('setEventPrefix', [$config['domain_message_prefix']])
->setPublic(true);

$container->getDefinition('ecentria.api.domain_message_consumer.service')
->addArgument(new Reference($config['domain_message_serializer']))
->addMethodCall('setMessageClassName', [$config['domain_message_class_name']]);
->addMethodCall('setMessageClassName', [$config['domain_message_class_name']])
->setPublic(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand All @@ -20,5 +21,4 @@
*/
class EcentriaAPIEventsBundle extends Bundle
{

}
1 change: 1 addition & 0 deletions Event/MessageEvent.php → src/Event/MessageEvent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand Down
5 changes: 4 additions & 1 deletion Model/Message.php → src/Model/Message.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand All @@ -10,6 +11,7 @@

namespace Ecentria\Libraries\EcentriaAPIEventsBundle\Model;

use DateTime;
use JMS\Serializer\Annotation\Type;

/**
Expand Down Expand Up @@ -112,7 +114,8 @@ class Message implements MessageInterface
* Message datetime
*
* the datetime that the message was generated
* @var datetime
*
* @var DateTime
*
* @Type("DateTime")
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* This file is part of the ecentria group, inc. software.
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7a6cce5

Please sign in to comment.