abstract class InvoiceValidation
{
protected function phoneValidate()
{
...
}
//執行驗證
abstract public function run();
}
class EmailInvoiceValidation extends InvoiceValidation
{
protected function emailValidate()
{
....
}
//執行驗證
public function run()
{
....
}
}
class RealMailInvoiceValidation extends InvoiceValidation
{
protected function addressValidate()
{
....
}
//執行驗證
public function run()
{
....
}
}
$className = $method.'InvoiceValidation';
if (!class_exists($className)) {
return null;
}
$validate = new $className($item->member_id, $method, $item->amount);
$message = $validate->run();
switch ($method) {
case "RealMail":
$validate = new RealMailInvoiceValidation();
break;
case "Email":
$validate = new EmailInvoiceValidation();
break;
default:
return null;
}
$message = $validate->run();