概念

适配器设计模式只是将某个对象的接口适配为另一个对象所期望的接口。

UML图

###代码实现

class errorObject
{
    private $_error;
    public function __construct($error)
    {
        $this->_error = $error;
    }

    public function getError() {
        return $this->_error;
    }
}

class LogToCsvErrorObject extends  errorObject{
    private $error_num;
    private $error_msg;

    public function __construct($error)
    {
        parent::__construct($error);
        $error = $this->getError();
        $parts = explode(":",$error);
        $this->error_num = $parts[0];
        $this->error_msg = $parts[1];
    }
    public function getErrorNum() {
        return $this->error_num;
    }

    public function getErrorMsg() {
        return $this->error_msg;
    }
}

class LogToConsole {
    private $_errorObject;

    public function __construct(errorObject $errorObject)
    {
        $this->_errorObject = $errorObject;
    }

    public function write() {
        fwrite(STDERR,$this->_errorObject->getError());
    }
}

class LogToCSV {
    private $_errorObject;

    public function __construct(LogToCsvErrorObject $errorObject)
    {
        $this->_errorObject = $errorObject;
    }

    public function write() {
        $error_num = $this->_errorObject->getErrorNum();
        $error_msg = $this->_errorObject->getErrorMsg();

        fwrite(STDERR,$error_msg."错误码:".$error_num);
    }
}

$error_obj = new LogToCsvErrorObject("404:NOT FOUND");

(new LogToCSV($error_obj))->write();