Skip to content

Instantly share code, notes, and snippets.

@shochdoerfer
Last active November 10, 2015 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shochdoerfer/79969ed33afa5982e9e5 to your computer and use it in GitHub Desktop.
Save shochdoerfer/79969ed33afa5982e9e5 to your computer and use it in GitHub Desktop.
DomainPayloadInterface.php
<?php
/**
* The domain payload object represents the domain's data it's state and type
*
* @api
*/
class DomainPayload implements DomainPayloadInterface
{
/**
* @var mixed
*/
private $status;
/**
* @var mixed
*/
private $type;
/**
* @var array
*/
private $data;
/**
* Creates a new {@link \bitExpert\Adroit\Domain\DomainPayload}.
*
* @param mixed $type
* @param array $data
*/
public function __construct($type, array $data = array())
{
$this->type = $type;
$this->data = $data;
}
/**
* {@inheritdoc}
*/
public function getValue($key = null, $default = null)
{
if (null === $key) {
return $this->data;
}
return (isset($this->data[$key])) ? $this->data[$key] : $default;
}
/**
* {@inheritdoc}
*/
public function getValues()
{
return $this->data;
}
/**
* {@inheritdoc}
*/
public function withValue($key, $value = null)
{
$new = clone $this;
$new->data[$key] = $value;
return $new;
}
/**
* {@inheritdoc}
*/
public function withValues(array $values)
{
$new = clone $this;
foreach ($values as $property => $value) {
$new->data[$property] = $value;
}
return $new;
}
/**
* {@inheritdoc}
*/
public function withStatus($status)
{
$new = clone($this);
$new->status = $status;
return $new;
}
/**
* {@inheritdoc}
*/
public function getStatus()
{
return $this->status;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return $this->type;
}
}
<?php
/**
* The domain payload object represents the domain's data it's state and type
*
* @api
*/
interface DomainPayloadInterface
{
/**
* Returns the type of the payload
*
* @return string
*/
public function getType();
/**
* Sets a model attribute. Will overwrite existing key => value pairs, if
* the key already exists. If you use an array as key, the given attributes will
* be set accordingly
*
* Note that this method can be chained, so you may use it comfortably like
* $model->set('attr1', 'value1')
* ->set('attr2', 'value2')
* ...
*
* @param string|array $key
* @param mixed $value
* @return DomainPayloadInterface
*/
public function withValue($key, $value = null);
/**
* Returns a model attribute in case the given key exists. If the key does
* not exist null will be returned.
*
* @param string|null $key the key to retrieve the value for
* @param mixed $default the default value to return if the given key was not found
* @return mixed
*/
public function getValue($key, $default = null);
/**
* Returns all attributes as an associative key->value array
*
* @return array
*/
public function getValues();
/**
* Sets the status information about the payload and returns
* the whole object for chainable use
*
* @param mixed $status
* @return \bitExpert\Adroit\Domain\DomainPayload
*/
public function withStatus($status);
/**
* Returns the status information about the payload
*
* @return mixed
*/
public function getStatus();
}
@shochdoerfer
Copy link
Author

$type is the identifier we use for the Responder-Lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment