2017 © Pedro Peláez
 

library payload

The simple infrastructure component for create payload message

image

gpslab/payload

The simple infrastructure component for create payload message

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License, (*1)

The simple infrastructure component for create payload message

Installation

Pretty simple with Composer, run:, (*2)

composer require gpslab/payload

Usage

This library automatically fill the properties of the object with payload data., (*3)

For example, create a simple message, (*4)

class SimpleMessage extends PayloadMessage
{
    public $id = 0;

    public $name = '';
}

Fill the message, (*5)

$message = new SimpleMessage([
    'id' => 123,
    'name' => 'foo',
]);

$message->id; // 123
$message->name; // foo
$message->payload(); // ['id' => 123, 'name' => 'foo']

Note, (*6)

All fields specified in the payload must exist., (*7)

Protected properties

You can use protected properties for data. It's convenient to make the properties as read-only., (*8)

class SimpleMessage extends PayloadMessage
{
    protected $id = 0;

    protected $name = '';

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

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

Fill the message, (*9)

$message = new SimpleMessage([
    'id' => 123,
    'name' => 'foo',
]);

$message->id(); // 123
$message->name(); // foo
$message->payload(); // ['id' => 123, 'name' => 'foo']

Note, (*10)

For fill private properties you must use setters., (*11)

Property setters

You can mark properties as private and use setters for fill it. This will ensure the security of data and control their type. You can mark the setters as protected to close the class from changes from the outside., (*12)

class SimpleMessage extends PayloadMessage
{
    private $id = 0;

    private $name = '';

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

    protected function setId(integer $id)
    {
        $this->id = $id;
    }

    public function name(): string
    {
        return $this->name;
    }

    protected function setName(string $name)
    {
        $this->name = $name;
    }
}

Fill the message, (*13)

$message = new SimpleMessage([
    'id' => 123,
    'name' => 'foo',
]);

$message->id(); // 123
$message->name(); // foo
$message->payload(); // ['id' => 123, 'name' => 'foo']

CQRS

You can use payload in CQRS infrastructure., (*14)

Command to rename contact:, (*15)

class RenameContactCommand extends PayloadCommand
{
    public $contact_id = 0;

    public $new_name = '';
}

Query for get contact by identity:, (*16)

class ContactByIdentityQuery extends PayloadQuery
{
    public $id = 0;
}

Domain Events

You can use payload in Domain Events., (*17)

Event, contact was renamed:, (*18)

class RenamedContactEvent extends PayloadDomainEvent
{
    public $contact_id = 0;

    public $old_name = '';

    public $new_name = '';
}

Serialize

You can serialize messages with Symfony serializer component. For do it you can use PayloadNormalizer or TypedPayloadNormalizer and encode result to JSON, XML, YAML, CSV, etc., (*19)

  • PayloadNormalizer - can be used only for one class because he does not distinguish messages;
  • TypedPayloadNormalizer - adds to the normalized data the type of message received from MessageTypeResolver service.

You can use ClassNameMessageTypeResolver as a simplify resolver. It use the last part of class name as a messages type., (*20)

  • \Acme\Demo\SomeMessage converted to SomeMessage
  • \Acme_Demo_SomeMessage converted to SomeMessage

Be careful with the use of this resolver and do not named message classes equally in different namespace., (*21)

License

This bundle is under the MIT license. See the complete license in the file: LICENSE, (*22)

The Versions

29/09 2017

dev-master

9999999-dev https://github.com/gpslab/payload

The simple infrastructure component for create payload message

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

cqrs infrastructure payload domain-event payload-message

11/07 2017

v1.1.0

1.1.0.0 https://github.com/gpslab/payload

The simple infrastructure component for create payload message

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

cqrs infrastructure payload domain-event payload-message

23/06 2017

v1.0.0

1.0.0.0 https://github.com/gpslab/payload

The simple infrastructure component for create payload message

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

cqrs infrastructure payload domain-event payload-message