Skip to content

Commit

Permalink
Merge pull request #9 from SDPM-lab/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
monkenWu authored Feb 22, 2023
2 parents d7f8d73 + cee5bb6 commit ccf3d30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Exception/ActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public static function forTimeFloat(string $serviceName): ActionException
return new self("Action {$serviceName} Time Out 秒數必須大於 0.0 。");
}

public static function forServiceDataNotFound(string $serviceName): ActionException
{
return new self("尚未定義 {$serviceName} 服務進服務列表內,請檢查服務的 serviceName 是否正確。");
}

/**
* 取得發生錯誤的 Restponse 實體
*
Expand Down
39 changes: 39 additions & 0 deletions src/Service/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,49 @@ public function __construct(string $serviceName, string $method, string $path)
$this->serviceName = $serviceName;
$this->method = $method;
$this->path = $path;

if (is_null(ServiceList::getServiceData($this->serviceName))) {
throw ActionException::forServiceDataNotFound($this->serviceName);
}

$this->baseUrl = ServiceList::getServiceData($this->serviceName)->getBaseUrl();
$this->client = ServiceList::getHttpClient();
}

/**
* 序列化儲存之成員變數。
*
* @return array
*/
public function __sleep()
{
return [
'method',
'baseUrl',
'path',
'serviceName',
'requestOption',
'filters',
'doneHandler',
'meaningData',
'failHandler',
'isSuccess',
'numOfAction',
'retry',
'retryDelay',
'timeout',
'request'
];
}

/**
* 反序列化後,針對 client 重新賦值。
*/
public function __wakeup()
{
$this->client = ServiceList::getHttpClient();
}

/**
* 執行 Action 所定義的內容(同步執行)
*
Expand Down

0 comments on commit ccf3d30

Please sign in to comment.