Skip to content

Instantly share code, notes, and snippets.

@cbergau
Created September 2, 2014 08:46
Show Gist options
  • Save cbergau/3e2d676820234efa83ad to your computer and use it in GitHub Desktop.
Save cbergau/3e2d676820234efa83ad to your computer and use it in GitHub Desktop.
Rule Engine Clean Architecture
<?php
class ChangeLogisticPartnerInteractor
{
/** @var ChangeLogisticPartnerValidator */
private $changeLogisticPartnerValidator;
public function execute($changeToId)
{
// High level Policy
if (!$this->changeLogisticPartnerValidator->isValid($changeToId)) {
// Error
}
// Success
}
}
interface ChangeLogisticPartnerValidator
{
public function isValid($changeToId);
}
// Low level detail
class RuleEngineChangeLogisticPartnerValidator implements ChangeLogisticPartnerValidator
{
private $ruleEngine;
public function isValid($changeToId) {
return $this->ruleEngine->execute(/*...*/);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment