Skip to content

Instantly share code, notes, and snippets.

@sstok
Created February 12, 2018 15:33
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 sstok/a3050a96a4df852cfd3edc976d7d9f3d to your computer and use it in GitHub Desktop.
Save sstok/a3050a96a4df852cfd3edc976d7d9f3d to your computer and use it in GitHub Desktop.
  • API-platform:
    • Separate Resource Entity (Read/Write model DTO; Decouple Model Entity from API-Platform)
    • Write:
      • Field (property) -> Command
        • Only changed fields
          • Detect related fields (field1, field2 -> Command; handle interconnected requirements)
          • BoolOperation(true=command1, false=command2)
        • Commands -> TransactionalCommand (Command1, Command2) -> Handler dispatches back CommandBus (same transaction)
      • method to convert DTO Create/Delete command
      • Handle child entities?
        • For a collection all items must be present, any items omitted are removed this works similar to handling a Fork operation.
/**
 * @var string The name of the item.
 *
 * @Assert\Type(type="string")
 * @Assert\NotNull
 * @Domain\Command("CommandName", "argument-name")
 */
private $firsName;

/**
 * @var string The name of the item.
 *
 * @Assert\Type(type="string")
 * @Assert\NotNull
 *
 * If command-name is already queued the argument-name is added to the Command constructor,
 * to dispatch the command as one operation.
 *
 * @Domain\Command("CommandName", "argument-name")
 */
private $lastName;

/**
 * @var bool The name of the item.
 *
 * @Assert\Type(type="bool")
 * @Domain\BoolCommand("OnTrueCommandName", "OnFalseCommandName")
 */
private $enabled;

/**
 * One generator type allowed (all shown for details)
 *
 * @Assert\NotNull
 * @Domain\IdGenerator(
 *    method="method on this class", 
 *    service="generator-service"
 *    class="StandardizedIdClass::generate" # default method name
 *    class="StandardizedIdClass::customMethodName"
 * )
 */
private $id;

public function toCreateCommand()
{
    return new RegisterUser($this->id, );
}

Example with child (collection) items:

/**
 * @var string The name of the item.
 *
 * @Assert\Type(type="string")
 * @Assert\NotNull
 * @Domain\Command("CommandName", "argument-name")
 */
private $firsName;

/**
 * @var string The name of the item.
 *
 * @Assert\Type(type="string")
 * @Assert\NotNull
 *
 * If command-name is already queued the argument-name is added to the Command constructor,
 * to dispatch the command as one operation.
 *
 * @Domain\Command("CommandName", "argument-name")
 */
private $lastName;

/**
 * @var bool The name of the item.
 *
 * @Assert\Type(type="bool")
 * @Domain\BoolCommand("OnTrueCommandName", "OnFalseCommandName")
 */
private $enabled;

/**
 * One generator type allowed (all shown for details)
 *
 * @Assert\NotNull
 * @Domain\IdGenerator(
 *    method="method on this class", 
 *    service="generator-service"
 *    class="StandardizedIdClass::generate" # default method name
 *    class="StandardizedIdClass::customMethodName"
 * )
 */
private $id;

public function toCreateCommand()
{
    return new RegisterUser($this->id, );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment