Code Monkey home page Code Monkey logo

domaincomponent's People

Contributors

athos7933 avatar awkan avatar babeou avatar dimitriseguinbiig avatar mcsky avatar nek- avatar pborreli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

domaincomponent's Issues

Integration to Symfony WebProfiler

Today the DomainEventDispatcher is not traced in any way. It would be great to have information about triggered domain events. I suggest to add an extension for the webprofiler of Symfony (in the bundle)

Symfony 4 integration

@Nek- I can't seem to get it to work with Symfony 4.1.
I've added the following config/packages/biig_domain.yaml:

biig_domain:
    # It modifies the DoctrineBundle configuration to register a new
    # ClassMetadataInfo class so the instantiator now set the domain event
    # dispatcher to your models automatically
    override_doctrine_instantiator: true

    # By default it will override the doctrine instantiator only for
    # the "default" entity manager of your application. You can specify
    # many entity managers if you want.
    entity_managers: []

    # Post persist events are not activated by default, you need to enable the post persist listeners
    persist_listeners:
        # As doctrine supports many connections, you need to enable your connections one by one
        doctrine: ['default']

My Listener:

<?php
namespace App\Application\EventListeners;

use Biig\Component\Domain\Event\DomainEvent;
use Biig\Component\Domain\Rule\PostPersistDomainRuleInterface;

class VerificationCreatedListener implements PostPersistDomainRuleInterface {

	/**
	 * Returns an array of event or a string it listen on.
	 *
	 * @return array|string
	 */
	public function after() {
		return 'vc.created';
	}

	/**
	 * @param DomainEvent $event
	 */
	public function execute( DomainEvent $event ) {
		var_dump( $event ); die;
	}
}

My Entity:

<?php
namespace App\Application\Entity;

use App\Application\Entity\VerificationCode\MobileNumber;
use App\Application\Entity\VerificationCode\SecretCode;
use Biig\Component\Domain\Event\DomainEvent;
use Biig\Component\Domain\Model\DomainModel;

class VerificationCode extends DomainModel {
	/**
	 * @var int
	 */
	private $id;

	/**
	 * @var MobileNumber
	 */
	private $mobileNumber;

	/**
	 * @var SecretCode
	 */
	private $code;

	public function __construct( $id, MobileNumber $mobileNumber, SecretCode $code ) {
		$this->id = $id;
		$this->mobileNumber = $mobileNumber;
		$this->code = $code;

		$this->dispatch('vc.created', new DomainEvent($this));
	}

	public function id() {
		return $this->id;
	}

	public function mobileNumber(): MobileNumber {
		return $this->mobileNumber;
	}

	public function code(): SecretCode {
		return $this->code;
	}

	public function shouldSendNewCode(): bool {
		return !$this->code->isSent() || $this->code->isExpired();
	}
}

The execute method is never called. It seems the instantiator is not being set. Am I missing something in the configuration?

Release 1.4.1

Things to do:

  • Modify the CHANGELOG.md
  • Tag

This is due before the 17th April.

Release v1.2.0

Things to do:

  • Modify the CHANGELOG.md
  • Modify the composer.json (so the master become the 1.2.x branch)
  • Tag

This is due before the 28th February.

Domain component config management is wrong

The DomainExtension is not tested for entity_manager configuration. It attempt to retrieve the following:

[
    "entity_managers": ['default', 'another']
]

But in reality it's more something like that:

[
    [
        "entity_managers": ['default', 'another']
    ]
]

Something may be wrong in this configuration. Luckily the default case will work. This really needs a unit test.

execute method should expect an interface

Currently to have a good code in rules, we need to check if the event is an instance of the event we expect. (required at least by phpstan)

We could improve the situation by replacing DomainEvent by DomainEventInterface, because we can use children interface as type afterwards.

Potential issue following the documentation

usage defined here: https://github.com/biig-io/DomainComponent/blob/master/docs/domain_event_dispatcher.md#symfony-integration potentially fail because no event is specified

This is not normal (because the rule is actually a subscriber and return the event it's bound on) and should be fix.

Related lines:

private function addListenerForEventsInDefinition(string $id, string $class, array $attribute, Definition $definition)
{
// Rules may not implement the
$method = $attribute['method'] ?? null;
$event = $attribute['event'] ?? null;
$priority = $attribute['priority'] ?? 0;
if (!class_exists($class, false)) {
throw new InvalidArgumentException(
sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)
);
}
if (null === $method || null === $event) {
throw new InvalidArgumentException(sprintf(
'Impossible to register class "%s" as domain rule: the service configuration is wrong.',
$class
));
}
$definition->addMethodCall('addListener', [
$event,
[new ServiceClosureArgument(new Reference($id)), $method],
$priority,
]);
}

Release v1.3.0

Things to do:

  • Modify the CHANGELOG.md
  • Modify the composer.json (so the dev-master become the 1.3.x-dev branch)
  • Tag

This is due before the 9th March.

About deprecations in Symfony 4.3

We are aware than Symfony 4.3 changed the API of the dispatcher you know today, this impact us directly. We will not provide a fix that would look like that (ugly, isn't it ?).

What we are going to do is release a new major version of the domain component compatible only with Symfony >= 4.3.

This will obviously come before Symfony 5.0. If you really want a change on the current version, PR are open.

Integration to Melodiia

In Melodiia, it exists a class named DomainObjectsDataMapper that build objects. Adding a decorator that adds the dispatcher inside the object would be a nice improvement.

Allow to know when the domainevent is delayed or not

Delayed events happen in the case you want it to happen after a flush. In some case you may want to implement both DomainRuleInterface and PostPersistRuleInterface, in that case having a possibility to know in what case you are is interesting.

To do: add a new method isDelayed to the domain event.

PostPersistRule configuration is not documented well

For PostPersistRules to work, we need to configure the domain component. It's not a feature available by default.

This is documented in the reference but it's not enough:

  • We should add it when the post persist rule is documented
  • We should add a recipe for the bundle

Release 1.4.0

Things to do:

  • Modify the CHANGELOG.md
  • Modify the composer.json (so the dev-master become the 1.4.x-dev branch)
  • Tag

This is due before the 6th April.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.