for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace WZRD\Messaging;
use ArrayIterator;
use DateTime;
use WZRD\Contracts\Messaging\Message as MessageContract;
abstract class Message implements MessageContract
{
/**
* Get message id.
*
* @return string
*/
public function getId()
if (empty($this->id)) {
$this->id = uniqid();
id
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
return $this->id;
* Get payload.
* @return array
public function getPayload()
$iterator = new ArrayIterator(array_filter((array) $this, function ($k) {
return $k != 'id' && $k != 'recorded_date';
}, ARRAY_FILTER_USE_KEY));
return (array) $iterator;
* Get the recorded date.
* @return Datetime
public function getRecordedDate()
if (empty($this->recorded_date)) {
$this->recorded_date = new DateTime();
recorded_date
return $this->recorded_date;
* Get the message name (e.g. the type).
public function getName()
return get_class($this);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: