dhii/cqrs-resource-model-interface

Interfaces for a CQRS approach to resource models.

v0.2-alpha1 2018-06-25 16:35 UTC

This package is auto-updated.

Last update: 2024-10-07 03:14:51 UTC


README

Build Status Code Climate Test Coverage Latest Stable Version This package complies with Dhii standards

Details

Interfaces for a CQRS approach to resource models.

Interfaces

  • SelectCapableInterface - Interface for objects that can retrieve records from storage, optionally limiting the result to only records that satisfy a given condition represented as an arbitrary tree of expressions.
  • InsertCapableInterface - Interface for objects that can insert one or more records into storage. Various container types are supported.
  • UpdateCapableInterface - Interface for objects that can update records in storage, optionally limited to records that satisfy a given condition represented as an arbitrary tree of expressions.
  • DeleteCapableInterface - Interface for objects that can delete records from storage, optionally limited to records that satisfy a given condition represented as an arbitrary tree of expressions.

Usage

use Dhii\Storage\Resource\SelectCapableInterface;
use Dhii\Collection\MapInterface;

/* @var $select SelectCapableInterface */
$results = $select->select();

/* The below would go through each element of the result set, and,
 * if the 'age' field is greater than 18, output all of the names
 * and values of all fields.
 */
foreach ($results as $_result) {
  /* @var $_result MapInterface */
  if ((int) $_result->get('age') < 18) {
    continue;
  }
  
  foreach ($_result as $_field => $_value) {
    echo sprintf('%1$s: %2$s', $_field, $_value) . "\n";
  }
  
  echo "---' . "\n";
}