Business Rule Class


Class Biz

{

    Public $Rules;

    Public $Condations;

    private $Inputs;

    Public $Default;




    function __construct()

    {

        $this->Default = 'Default';

    }


    public Function PushInput($value)

    {

        $this->Inputs[] = $value;

    }


    public Function GetRule()

    {

        $Key = "";

        $i = 0;

        foreach ($this->Inputs as $Condation) {

            if ($this->Condations[$i] == 'Bit') {

                $Key .= ($Condation) ? 'Y' : 'N';

                $i++;

                continue;

            }

            $s = '$Key.= (' . $Condation . $this->Condations[$i] . ')?"Y":"N";';

            eval($s);

            $i++;

        }

        if (!isset($this->Rule[$Key])) {

            return $this->Default;

        }

        return $this->Rule[$Key];

    }

}

use


$o = new Biz();


$o->Rule = ['YYY' => 'Action1', 'YNN' => 'Action2', 'YYY' => "Action3", 'NYN' => 'Action4', 'YYN' => 'Action6'];

$o->Condations = ['>200', '==1', 'Bit', '>200'];




$OrdeTotal = 300;

$CustomerType = 1;

$IsExp = false;

$o->PushInput($OrdeTotal);

$o->PushInput($CustomerType);

$o->PushInput($IsExp);


echo $o->GetRule();

Question oder Snippet?