Skip to content
Snippets Groups Projects
Commit cebfbbec authored by Addin Munawwar's avatar Addin Munawwar
Browse files

feat: soap belom bisa (despair)

parent da3b4334
Branches
Tags
No related merge requests found
......@@ -4,6 +4,10 @@ WORKDIR /var/www/html
# PHP extension and Apache configuration
RUN docker-php-ext-install mysqli
RUN a2enmod rewrite
RUN apt-get -y update ; \
apt-get -y upgrade ; \
apt-get -y install ffmpeg ; \
\ No newline at end of file
RUN apt-get update \
&& apt-get install -y \
libxml2-dev \
&& rm -rf /var/lib/apt/lists/*
# Enable SOAP extension
RUN docker-php-ext-install soap
\ No newline at end of file
<?
class SoapConsumer {
private SoapClient $subscriptionClient;
private SoapClient $requestClient;
private $apiKey;
public function __construct() {
// Set SOAP client options
$options = [
'trace' => 1, // Allows you to trace request and response
'exceptions' => true, // Enables exceptions for HTTP errors
"encoding" => "UTF-8",
"stream_context" => stream_context_create([
'http' => [
'ApiKey' => $_ENV['SOAP_API_KEY']
]
])
];
$this->subscriptionClient = new SoapClient($_ENV['SOAP_URL'] . "subscription?wsdl", $options);
$this->requestClient = new SoapClient($_ENV['SOAP_URL'] . "request?wsdl", $options);
$this->apiKey = $_ENV['SOAP_API_KEY'];
$headerBody = new SoapVar($this->apiKey, XSD_STRING, null, null, 'ApiKey', 'http://ws.soap.com/');
$header = new SoapHeader('http://ws.soap.com/', 'ApiKey', $headerBody);
$this->subscriptionClient->__setSoapHeaders(array(
new SoapHeader(
'http://ws.soap.com/',
'ApiKey',
$this->apiKey,
false
),
new SoapHeader(
'ns2',
'ApiKey',
$this->apiKey,
false
),
new SoapHeader(
'ns1',
'ApiKey',
$this->apiKey,
false
),
$header
));
$this->subscriptionClient->__setSoapHeaders($header);
$this->requestClient->__setSoapHeaders(
new SoapHeader(
'http://ws.soap.com/',
'ApiKey',
$this->apiKey,
false
)
);
}
public function makeRequest($requestBy, $to, $requesterEmail) {
$response = $this->requestClient->MakeRequest([
'RequestBy' => $requestBy,
'To' => $to,
'RequesterEmail' => $requesterEmail,
]);
return $response;
// $apiKey = $this->apiKey;
// // Construct SOAP request XML
// $requestXml = <<<XML
// <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
// <Header>
// <ApiKey xmlns="http://ws.soap.com/">$apiKey</ApiKey>
// </Header>
// <Body>
// <MakeRequest xmlns="http://ws.soap.com/">
// <RequestBy xmlns="">$requestBy</RequestBy>
// <To xmlns="">$to</To>
// <RequesterEmail xmlns="">$requesterEmail</RequesterEmail>
// </MakeRequest>
// </Body>
// </Envelope>
// XML;
// $endpoint = $_ENV['SOAP_URL'] . "request";
// $headers = [
// 'Content-Type: text/xml; charset=utf-8',
// 'Content-Length: ' . strlen($requestXml),
// 'SOAPAction: http://ws.soap.com/MakeRequest',
// ];
// $ch = curl_init($endpoint);
// curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// // Send SOAP request
// $responseXml = curl_exec($ch);
// curl_close($ch);
// return $responseXml;
}
public function getSubscriptionOf($requester) {
// Define the SOAP request parameters
$requestParams = array(
'ApiKey' => $this->apiKey,
'GetSubscriptionOf' => array(
'Username' => $requester,
),
);
$res = $this->subscriptionClient->__soapCall('GetSubscriptionOf', array($requestParams));
// Process the result
var_dump($res);
// $response = $this->subscriptionClient->GetSubscriptionOf([
// 'Username' => $requester,
// ]);
// echo htmlentities( $this->subscriptionClient->__getLastRequest());
// return $response;
// $apiKey = $this->apiKey;
// // Construct SOAP request XML
// $requestXml = <<<XML
// <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
// <Header>
// <ApiKey xmlns="http://ws.soap.com/">$apiKey</ApiKey>
// </Header>
// <Body>
// <GetSubscriptionOf xmlns="http://ws.soap.com/">
// <Username xmlns="">$requester</Username>
// </GetSubscriptionOf>
// </Body>
// </Envelope>
// XML;
// $endpoint = $_ENV['SOAP_URL'] . "subscription";
// $headers = [
// 'Content-Type: text/xml; charset=utf-8',
// 'Content-Length: ' . strlen($requestXml),
// 'SOAPAction: http://ws.soap.com/GetSubscriptionOf',
// ];
// $ch = curl_init($endpoint);
// curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXml);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// // Send SOAP request
// $dataString = curl_exec($ch);
// curl_close($ch);
// // Use regular expression to extract usernames
// preg_match_all('/\+07:00(.*?)true/', $dataString, $matches);
// // Extract the usernames from the matches array
// $usernames = $matches[1];
// for ($i = 0; $i < count($usernames); $i++) {
// // if the username started with 2023
// if (substr($usernames[$i], 0, 4) == "2023") {
// $usernames[$i] = substr($usernames[$i], 29);
// }
// }
// // Print the result
// echo "usernames = [" . implode(', ', $usernames) . "]\n";
// return $dataString;
}
}
?>
\ No newline at end of file
<?php
class TestController extends Controller implements ControllerInterface
{
private SoapConsumer $soap;
public function __construct() {
require_once __DIR__ . '/../clients/SOAPConsumer.php';
$this->soap = new SoapConsumer();
}
public function index() {
}
public function req()
{
echo $this->soap->makeRequest('addin', 'yusuf', 'test@gmail.com');
}
public function sub()
{
echo $this->soap->getSubscriptionOf('a');
}
}
\ No newline at end of file
......@@ -27,7 +27,10 @@ class UserController extends Controller implements ControllerInterface
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
// show the login page
$mySubscriptionView = $this->view('user', 'MySubscriptionView');
$data = [
'username' => $_SESSION['username']
];
$mySubscriptionView = $this->view('user', 'MySubscriptionView', $data);
$mySubscriptionView->render();
break;
default:
......
......@@ -12,13 +12,14 @@ class Main {
$controllerPart = $url[0] ?? null;
$controllerPart = ucfirst($controllerPart);
if (isset($controllerPart) && file_exists(__DIR__ . '/../controllers/' . $controllerPart . 'Controller.php')) {
require_once __DIR__ . '/../controllers/' . $controllerPart . 'Controller.php';
$controllerClass = $controllerPart . 'Controller';
$this->controller = new $controllerClass();
}else{
header('Location: /book/');
require_once __DIR__ . '/../controllers/NotFoundController.php';
$this->controller = new NotFoundController();
}
unset($url[0]);
......
......@@ -27,7 +27,6 @@
<table border="1" class="styled-table">
<thead>
<tr>
<th>Id</th>
<th>Curator Name</th>
<th>Action</th>
</tr>
......@@ -38,7 +37,6 @@
foreach ($authors as $author) {
echo "<tr>";
echo "<td>" . $author['author_id'] . "</td>";
echo "<td>" . $author['full_name'] . "</td>";
echo '<td><a href="/author/update/' . $author['author_id'] .'">Pending/Details</a></td>';
echo "</tr>";
......
......@@ -22,8 +22,8 @@ with open('books.csv', newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
books.append({
'title': row['original_title'],
'description': f"Buku {row['original_title']} karya {row['authors']} ini menceritakan tentang {row['original_title']}.",
'title': row['title'],
'description': f"Buku {row['title']} karya {row['authors']} ini menceritakan tentang {row['title']}.",
'book_image': row['small_image_url']
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment