diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/deployment.xml b/.idea/deployment.xml
new file mode 100644
index 0000000..d0fc731
--- /dev/null
+++ b/.idea/deployment.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..639900d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..ba18e7d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php-rest-api-logging.iml b/.idea/php-rest-api-logging.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/php-rest-api-logging.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
new file mode 100644
index 0000000..31b8a3a
--- /dev/null
+++ b/.idea/php.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/sonarlint/issuestore/a/4/a43e0007356c2d041e43f70f6023bc8d2afea2e3 b/.idea/sonarlint/issuestore/a/4/a43e0007356c2d041e43f70f6023bc8d2afea2e3
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/sonarlint/issuestore/b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7 b/.idea/sonarlint/issuestore/b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7
new file mode 100644
index 0000000..e649ace
--- /dev/null
+++ b/.idea/sonarlint/issuestore/b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7
@@ -0,0 +1,5 @@
+
+W php:S1808"6Put exactly one space after comma separated arguments.(80
+G php:S2003"&Replace "require" with "require_once".(80
+?php:S125"Remove this commented out code.(ߢ80
+m php:S4833"LReplace "require" with namespace import mechanism through the "use" keyword.(80
\ No newline at end of file
diff --git a/.idea/sonarlint/issuestore/e/7/e700e69bab56bb0981a93adce94a782eeef77b9d b/.idea/sonarlint/issuestore/e/7/e700e69bab56bb0981a93adce94a782eeef77b9d
new file mode 100644
index 0000000..08ff645
--- /dev/null
+++ b/.idea/sonarlint/issuestore/e/7/e700e69bab56bb0981a93adce94a782eeef77b9d
@@ -0,0 +1,2 @@
+
+?php:S125"Remove this commented out code.(80
\ No newline at end of file
diff --git a/.idea/sonarlint/issuestore/f/d/fd475a94210be282f05505039527f15aa4c5feba b/.idea/sonarlint/issuestore/f/d/fd475a94210be282f05505039527f15aa4c5feba
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb
new file mode 100644
index 0000000..b6ef517
--- /dev/null
+++ b/.idea/sonarlint/issuestore/index.pb
@@ -0,0 +1,9 @@
+
+<
+paiement.log,f/d/fd475a94210be282f05505039527f15aa4c5feba
+9
+ error_log,a/4/a43e0007356c2d041e43f70f6023bc8d2afea2e3
+I
+src/ProductController.php,e/7/e700e69bab56bb0981a93adce94a782eeef77b9d
+9
+ index.php,b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7
\ No newline at end of file
diff --git a/.idea/sonarlint/securityhotspotstore/a/4/a43e0007356c2d041e43f70f6023bc8d2afea2e3 b/.idea/sonarlint/securityhotspotstore/a/4/a43e0007356c2d041e43f70f6023bc8d2afea2e3
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/sonarlint/securityhotspotstore/b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7 b/.idea/sonarlint/securityhotspotstore/b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/sonarlint/securityhotspotstore/e/7/e700e69bab56bb0981a93adce94a782eeef77b9d b/.idea/sonarlint/securityhotspotstore/e/7/e700e69bab56bb0981a93adce94a782eeef77b9d
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/sonarlint/securityhotspotstore/f/d/fd475a94210be282f05505039527f15aa4c5feba b/.idea/sonarlint/securityhotspotstore/f/d/fd475a94210be282f05505039527f15aa4c5feba
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb
new file mode 100644
index 0000000..b6ef517
--- /dev/null
+++ b/.idea/sonarlint/securityhotspotstore/index.pb
@@ -0,0 +1,9 @@
+
+<
+paiement.log,f/d/fd475a94210be282f05505039527f15aa4c5feba
+9
+ error_log,a/4/a43e0007356c2d041e43f70f6023bc8d2afea2e3
+I
+src/ProductController.php,e/7/e700e69bab56bb0981a93adce94a782eeef77b9d
+9
+ index.php,b/b/bb6499b8e938f92a3695fff1afe57edea4b9efb7
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/webServers.xml b/.idea/webServers.xml
new file mode 100644
index 0000000..4bcb8de
--- /dev/null
+++ b/.idea/webServers.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/error_log b/error_log
new file mode 100644
index 0000000..eb942cd
--- /dev/null
+++ b/error_log
@@ -0,0 +1,10 @@
+[21-Apr-2023 20:02:57 UTC] PHP Fatal error: Uncaught TypeError: Return value of ErrorHandler::handleException() must be an instance of void, none returned in /home/z3csh562/public_html/mwoptique/src/ErrorHandler.php:15
+Stack trace:
+#0 [internal function]: ErrorHandler::handleException(Object(ParseError))
+#1 {main}
+ thrown in /home/z3csh562/public_html/mwoptique/src/ErrorHandler.php on line 15
+[21-Apr-2023 20:08:41 UTC] PHP Fatal error: Uncaught TypeError: Return value of ErrorHandler::handleException() must be an instance of void, none returned in /home/z3csh562/public_html/mwoptique/src/ErrorHandler.php:15
+Stack trace:
+#0 [internal function]: ErrorHandler::handleException(Object(ParseError))
+#1 {main}
+ thrown in /home/z3csh562/public_html/mwoptique/src/ErrorHandler.php on line 15
diff --git a/httpCall.log b/httpCall.log
new file mode 100644
index 0000000..e69de29
diff --git a/index.php b/index.php
index 234bb2b..c2b29dd 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,4 @@
processRequest($_SERVER["REQUEST_METHOD"], $id);
-
-
-
-
-
-
-
-
-
-
-
-
+//if ($parts[2] != "products") {
+// http_response_code(404);
+// exit;
+//}
+$controller = new ProductController();
+$controller->processRequest($_SERVER["REQUEST_METHOD"], $request);
diff --git a/paiement.log b/paiement.log
new file mode 100644
index 0000000..de14eeb
--- /dev/null
+++ b/paiement.log
@@ -0,0 +1,35 @@
+
+
+2023-04-21 20:36:22
+
+
+2023-04-21 20:37:07
+
+
+2023-04-21 20:39:14
+
+
+2023-04-21 20:42:39
+
+
+2023-04-21 20:43:36
+
+
+2023-04-21 21:01:43
+
+
+2023-04-21 21:06:36
+
+
+2023-04-21 21:07:24
+
+
+2023-04-21 21:12:38
+
+
+2023-04-21 21:23:23
+{"0":"HTTP\/1.1 200 OK","Date":"Fri, 21 Apr 2023 21:23:23 GMT","Server":"Apache","Upgrade":"h2,h2c","Connection":"Upgrade, close","Last-Modified":"Thu, 13 Sep 2018 02:34:43 GMT","Accept-Ranges":"bytes","Content-Length":"6023","Vary":"Accept-Encoding,User-Agent","Content-Type":"text\/html"}
+
+
+2023-04-21 21:24:09
+{"0":"HTTP\/1.1 200 OK","Date":"Fri, 21 Apr 2023 21:24:09 GMT","Server":"Apache","Upgrade":"h2,h2c","Connection":"Upgrade, close","Last-Modified":"Thu, 13 Sep 2018 02:34:43 GMT","Accept-Ranges":"bytes","Content-Length":"6023","Vary":"Accept-Encoding,User-Agent","Content-Type":"text\/html"}
diff --git a/src/ProductController.php b/src/ProductController.php
index 3b6ab44..8e0cbe2 100644
--- a/src/ProductController.php
+++ b/src/ProductController.php
@@ -2,120 +2,111 @@
class ProductController
{
- public function __construct(private ProductGateway $gateway)
+// public function __construct(private ProductGateway $gateway)
+ public function __construct()
{
+
}
- public function processRequest(string $method, ?string $id): void
+ public function processRequest(string $method, string $request): void
{
- if ($id) {
-
- $this->processResourceRequest($method, $id);
-
- } else {
-
- $this->processCollectionRequest($method);
-
- }
+ $this->processCollectionRequest($method, $request);
}
- private function processResourceRequest(string $method, string $id): void
- {
- $product = $this->gateway->get($id);
-
- if ( ! $product) {
- http_response_code(404);
- echo json_encode(["message" => "Product not found"]);
- return;
- }
-
- switch ($method) {
- case "GET":
- echo json_encode($product);
- break;
-
- case "PATCH":
- $data = (array) json_decode(file_get_contents("php://input"), true);
-
- $errors = $this->getValidationErrors($data, false);
-
- if ( ! empty($errors)) {
- http_response_code(422);
- echo json_encode(["errors" => $errors]);
- break;
- }
-
- $rows = $this->gateway->update($product, $data);
-
- echo json_encode([
- "message" => "Product $id updated",
- "rows" => $rows
- ]);
- break;
-
- case "DELETE":
- $rows = $this->gateway->delete($id);
-
- echo json_encode([
- "message" => "Product $id deleted",
- "rows" => $rows
- ]);
- break;
-
- default:
- http_response_code(405);
- header("Allow: GET, PATCH, DELETE");
- }
- }
+// private function processResourceRequest(string $method, string $id): void
+// {
+// $product = $this->gateway->get($id);
+//
+// if ( ! $product) {
+// http_response_code(404);
+// echo json_encode(["message" => "Product not found"]);
+// return;
+// }
+//
+// switch ($method) {
+// case "GET":
+// echo json_encode($product);
+// break;
+//
+// case "PATCH":
+// $data = (array) json_decode(file_get_contents("php://input"), true);
+//
+// $errors = $this->getValidationErrors($data, false);
+//
+// if ( ! empty($errors)) {
+// http_response_code(422);
+// echo json_encode(["errors" => $errors]);
+// break;
+// }
+//
+// $rows = $this->gateway->update($product, $data);
+//
+// echo json_encode([
+// "message" => "Product $id updated",
+// "rows" => $rows
+// ]);
+// break;
+//
+// case "DELETE":
+// $rows = $this->gateway->delete($id);
+//
+// echo json_encode([
+// "message" => "Product $id deleted",
+// "rows" => $rows
+// ]);
+// break;
+//
+// default:
+// http_response_code(405);
+// header("Allow: GET, PATCH, DELETE");
+// }
+// }
- private function processCollectionRequest(string $method): void
+ private function processCollectionRequest(string $method, string $request): void
{
+
switch ($method) {
case "GET":
- echo json_encode($this->gateway->getAll());
+ http_response_code(200);
break;
-
+
case "POST":
- $data = (array) json_decode(file_get_contents("php://input"), true);
-
- $errors = $this->getValidationErrors($data);
-
- if ( ! empty($errors)) {
- http_response_code(422);
- echo json_encode(["errors" => $errors]);
- break;
- }
-
- $id = $this->gateway->create($data);
-
- http_response_code(201);
- echo json_encode([
- "message" => "Product created",
- "id" => $id
- ]);
+ http_response_code(202);
break;
default:
http_response_code(405);
header("Allow: GET, POST");
}
- }
-
- private function getValidationErrors(array $data, bool $is_new = true): array
- {
- $errors = [];
-
- if ($is_new && empty($data["name"])) {
- $errors[] = "name is required";
- }
-
- if (array_key_exists("size", $data)) {
- if (filter_var($data["size"], FILTER_VALIDATE_INT) === false) {
- $errors[] = "size must be an integer";
- }
+
+ $file = 'httpCall.log';
+ if (file_exists($file)) {
+ $content = file_get_contents($file);
+ } else {
+ $content = "";
}
-
- return $errors;
+
+ $date = new DateTime("now", new DateTimeZone('America/New_York'));
+ $logDate = $date->format('Y-m-d H:i:s');
+ $content .= "\n\n" . $logDate . "\n";
+
+ $content .= "\n" . $method . "\n";
+ $content .= "Request:\n" . $request . "\n";
+
+ $allHeaders = getallheaders();
+ unset($allHeaders["Authorization"]);
+ echo "Headers:\n\n";
+ echo json_encode($allHeaders);
+
+ $content .= "\nHeaders:\n" . json_encode($allHeaders) . "\n";
+
+ echo "\nBody:\n\n";
+ $entityBody = file_get_contents('php://input');
+ echo $entityBody;
+ $content .= "\n" . $entityBody . "\n";
+
+ file_put_contents($file, $content);
+
}
}