php:爲功能模塊編寫服務類,通過構建函數管理參數,以及實例化後調用方法

分析鳥雲的UpgradeService代碼,升級的所有參數和方法都在裏面

第一步:在其他文件實例化UpgradeService:

$this->upgradeService = new UpgradeService(
            REAL_PATH,
            "update.niaoyun.com",
            $this->dataDir,
            $dbconfig,
            $agentDomain,
            $agentid,
            $agentPass,
            $templates
        );

UpgradeService實例化後,參數已經賦值:

下面是UpgradeService..php

public function __construct($appRootDir, $masterHost, $tempDir, $dbConfig, $agentDomain, $agentid, $agentPassword, $templates)
    {
        $this->masterHost    = $masterHost;
        $this->agengid       = $agentid;
        $this->agentDomain   = $agentDomain;
        $this->agentPassword = $agentPassword;
............
}

第二步:通過$this->upgradeService便可調用UpgradeService..php裏面定義的方法啦

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章