Nôm na abc thì có thể làm thế này
interface CurlInterface {
function get($reqString, $paramArray = null, $apiUser = 'system');
function post($reqString, $paramArray, $apiUser = 'system'); // thêm cái param cuối xác định là PUT cũng được
function put($reqString, $paramArray, $apiUser = 'system');
}
class Curl implements CurlInterface {
// mấy hàm trong DiscourseCurl, tương ứng với CurlInteface ở trên
}
interface DiscourseApiInterface {
public function group($groupname, $usernames = array());
public function getGroups();
public function createUser($name, $userName, $emailAddress, $password);
public function activateUser($userId);
public function getUsernameByEmail($email);
public function getUserByUsername($userName);
public function createCategory($categoryName, $color, $textColor = '000000', $userName = 'system');
public function createTopic($topicTitle, $bodyText, $categoryId, $userName, $replyToId = 0);
public function createPost($bodyText, $topicId, $categoryId, $userName);
public function editPost($postId, $bodyText, $editReason = '');
public function inviteUser($email, $topicId, $userName = 'system');
public function changeSiteSetting($siteSetting, $value);
}
class DiscourseCurl extends Curl implements DiscourseApiInterface {
// đẩy code vô
}
sau đó nếu có service khác ko phải Discource thì cứ tương thôi
interface WhateverApiInterface {
// interface của cái củ riêng mà Whatever nó support
}
class WhateverCurl extends Curl implements WhateverApiInterface {
// đẩy code vô
}
Tạo ra ServiceProvider rồi bind
$this->app->bind('\path\to\DiscourseApiInterface', function () {
return new \path\to\DiscourseCurl; // chỗ này bind config API key rồi gì gì trong constructor luôn cũng được.
});
$this->app->bind('\path\to\DiscourseApiInterface', function () {
return new \path\to\WhateverCurl;
});