diff --git a/.env.example b/.env.example index d840b0e0bbad8d104b50b508980a2a7ac0808bed..ad73005083406925c6a507ef3c059ae3f0cfc441 100644 --- a/.env.example +++ b/.env.example @@ -7,5 +7,9 @@ POSTGRES_USER=postgres POSTGRES_PASSWORD=root API_KEY=secret -REST_HOST=http://webtune-soap:8080/webtune-soap -REST_KEY=apahayo \ No newline at end of file + +REST_API="http://webtune-rest:8888" +REST_KEY=secret_turu + +SOAP_API=http://webtune-soap:8080/webtune-soap +SOAP_KEY=secret_blebekblebek diff --git a/Controller/ExampleController.php b/Controller/ExampleController.php deleted file mode 100644 index 38158599798aeb6e126412408e50e4fedede4093..0000000000000000000000000000000000000000 --- a/Controller/ExampleController.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -namespace Controller; - -use Lib\Interfaces\Routing\IRequest; -use Lib\Interfaces\Routing\IResponse; - -class ExampleController { - static function HalamanX(IRequest $req, IResponse $res) { - return $res->view("Pages/HalamanX", [ - "kucing" => 12, - ]); - } -} diff --git a/Controller/SubsciberController.php b/Controller/SubsciberController.php index 98abb2acaba11121bb927249c5f3855c6f9b7c6d..8cb55cbf5375e88490fc693c1e7629d614cf000a 100644 --- a/Controller/SubsciberController.php +++ b/Controller/SubsciberController.php @@ -143,7 +143,7 @@ class SubsciberController { } static function fetchSubscriptions(int $page,int $limit, int $user_id,$db){ - $fetcher = new FetchAPI(getenv("REST_HOST")); + $fetcher = new FetchAPI(getenv("REST_API")); $param = [ "page"=>$page, "limit"=>$limit, @@ -217,7 +217,7 @@ class SubsciberController { // $data = json_decode($output,true)["data"]; //fetch max page - $fetcher = new FetchAPI(getenv("REST_HOST")); + $fetcher = new FetchAPI(getenv("REST_API")); $param = [ "page-size"=>$limit, ]; diff --git a/Controller/TestController.php b/Controller/TestController.php new file mode 100644 index 0000000000000000000000000000000000000000..544075ca4029e3714b81e421998cfb4dda877d27 --- /dev/null +++ b/Controller/TestController.php @@ -0,0 +1,17 @@ +<?php + +namespace Controller; + +use Lib\Interfaces\Routing\IRequest; +use Lib\Interfaces\Routing\IResponse; +use Service\Soap\TestSoap; + +class TestController { + static function soapPing(IRequest $req, IResponse $res) { + $test = new TestSoap(); + + return $res->json([ + "result" => $test->ping(), + ]); + } +} diff --git a/Lib/Service/Api/FetchAPI.php b/Lib/Service/Api/FetchAPI.php index fedf7ed5c69a6040a503877cf0bf828b38cc2717..33cd4e1d521e54f6018ea8cd734df325515452cf 100644 --- a/Lib/Service/Api/FetchAPI.php +++ b/Lib/Service/Api/FetchAPI.php @@ -1,64 +1,63 @@ <?php - namespace Lib\Service\Api; -use PDO; +namespace Lib\Service\Api; - class FetchAPI{ - private string $host; +class FetchAPI{ + private string $host; - public function __construct(string $host) - { - $this->host = $host; - } - - public function get(string $endpoint,array $param, array $headers){ - $url = $this->host . $endpoint; - //add param - if(count($param)>0){ - $url .= "?"; - } - foreach($param as $key=>$value){ - $url = $url . $key . "=" . $value . "&"; - } - $ch = curl_init($url); - //set curl header - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); - curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false); - curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false); - curl_setopt( $ch , CURLOPT_TIMEOUT, 10000); - //set http header - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $output = curl_exec($ch); - curl_close($ch); + public function __construct(string $host) + { + $this->host = $host; + } - return $output; + public function get(string $endpoint,array $param, array $headers){ + $url = $this->host . $endpoint; + //add param + if(count($param)>0){ + $url .= "?"; } + foreach($param as $key=>$value){ + $url = $url . $key . "=" . $value . "&"; + } + $ch = curl_init($url); + //set curl header + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); + curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false); + curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false); + curl_setopt( $ch , CURLOPT_TIMEOUT, 10000); + //set http header + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $output = curl_exec($ch); + curl_close($ch); - public function post(string $endpoint,array $param, array $headers){ - $url = $this->host . $endpoint; - //add param - $ch = curl_init($url); - //set curl header - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); - curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false); - curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false); - curl_setopt( $ch , CURLOPT_TIMEOUT, 10000); - //set post payload - curl_setopt($ch, CURLOPT_POST, 1); - $post_payload = ""; - foreach($param as $key=>$value){ - $post_payload = $post_payload . $key . "=" . $value . "&"; - } - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_payload); - //set http header - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $output = curl_exec($ch); - curl_close($ch); + return $output; + } - return $output; + public function post(string $endpoint,array $param, array $headers){ + $url = $this->host . $endpoint; + //add param + $ch = curl_init($url); + //set curl header + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); + curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER, false); + curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST, false); + curl_setopt( $ch , CURLOPT_TIMEOUT, 10000); + //set post payload + curl_setopt($ch, CURLOPT_POST, 1); + $post_payload = ""; + foreach($param as $key=>$value){ + $post_payload = $post_payload . $key . "=" . $value . "&"; } - } \ No newline at end of file + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_payload); + //set http header + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + $output = curl_exec($ch); + curl_close($ch); + + return $output; + } +} \ No newline at end of file diff --git a/Router/AppRoutes.php b/Router/AppRoutes.php index bda19082c6a6c355810b2b8bc422f2cda6063b42..e99ece04fe68e79cd54a83a703d5e24ada247103 100644 --- a/Router/AppRoutes.php +++ b/Router/AppRoutes.php @@ -7,6 +7,7 @@ use Controller\AlbumController; use Controller\HomeController; use Controller\LaguController; use Controller\SubsciberController; +use Controller\TestController; use Lib\Dependency; use Lib\Enums\Request\HttpMethod; use Lib\Interfaces\Routing\IRoute; @@ -25,6 +26,7 @@ class AppRoutes $route = $this->route; $route->route(HttpMethod::Get, "/", [HomeController::class, "homepage"]); + $route->route(HttpMethod::Get, "/soap/ping", [TestController::class, "soapPing"]); //halaman lihat lagu $route->route(HttpMethod::Get, "/search", [LaguController::class, "searchLagu"]); @@ -38,7 +40,6 @@ class AppRoutes // Auth $route->groupRoute("/auth", AuthRoutes::getRoutes()); - $route->route(HttpMethod::Get, "/testing", [ExampleController::class, "HalamanX"]); // Album $route->route(HttpMethod::Get, "/album", [AlbumController::class, "getAlbums"]); diff --git a/Service/Soap/TestSoap.php b/Service/Soap/TestSoap.php new file mode 100644 index 0000000000000000000000000000000000000000..8af3bc16603e919ec041b582e4a5d0a6e8cfc654 --- /dev/null +++ b/Service/Soap/TestSoap.php @@ -0,0 +1,23 @@ +<?php + +namespace Service\Soap; + +class TestSoap { + private SoapClientFactory $factory; + + public function __construct() { + $wsdl = getenv("SOAP_API"). "/services/test?wsdl"; + $this->factory = new SoapClientFactory($wsdl); + } + + public function ping( + ?string $last_token = null + ): string { + $soap = $this->factory->generate_client($last_token); + + return $soap->__soapCall( + "ping", + [] + ); + } +} \ No newline at end of file