diff --git a/Faker.php b/Faker.php new file mode 100644 index 0000000000000000000000000000000000000000..0576c3cd38dd4dbd79ba07fe8cc150c6716387b4 --- /dev/null +++ b/Faker.php @@ -0,0 +1,35 @@ +<?php + +class Faker +{ + private array $code = ['Filter a array and exclude element if key is "chapeau"', 'Check if word is a palindromic word', 'return a number of occurence for word into a text']; + private array $test = ["If you're using JavaScript, you can use the filter method to exclude elements with a key of 'chapeau'. Here's an example:", + "A palindromic word is a word that reads the same backward as forward. To check if a word is a palindromic word, you can compare its reverse to the original word. Here's an example in JavaScript:", + "To return the number of occurrences of a word in a text, you can use the split method to convert the text into an array of words, and then use the filter method to count the number of elements in the array that match the target word. Here's an example in JavaScript:"]; + + public int $number; + + + public function __construct() + { + $this->number = rand(0, sizeof($this->code)-1); + } + + + + public function getCode(): string + { + return $this->code[$this->number]; + } + + public function getTest(): string + { + return $this->test[$this->number]; + } + + + public function regenerateCode(): void + { + $this->number = rand(1, sizeof($this->code)); + } +} \ No newline at end of file diff --git a/OpenAIGenerator.php b/OpenAIGenerator.php index fcc1a43690da10fbd41e1e1233000e1c92c79be5..c30b272091ac53ef2c90eb52bc7b364b49470b31 100644 --- a/OpenAIGenerator.php +++ b/OpenAIGenerator.php @@ -1,4 +1,5 @@ <?php +require_once('Faker.php'); class OPenAIGenerator { private string $question; @@ -12,6 +13,11 @@ class OPenAIGenerator { $this->usefaker = $useFaker; $this->question = $question; + if($useFaker) + { + $fakerClasse = new Faker(); + $this->setFaker($fakerClasse); + } if($generateCode) { $this->code = $this->genCode(); @@ -19,10 +25,10 @@ class OPenAIGenerator $this->test = $this->genTest(); } - public function setFaker($faker) // SPECIFY CLASS OF FAKER FOR RETURN TYPE + public function setFaker($fakerClasse) // SPECIFY CLASS OF FAKER FOR RETURN TYPE { // TO DOO SET FAKER CLASSE - $this->faker = $faker; + $this->faker = $fakerClasse; } public function genCode(): string @@ -42,7 +48,7 @@ class OPenAIGenerator { // TO DOO // USE CLASS FAKER FOR RETURN STRING - return ""; + return $this->faker->getCode(); } } @@ -63,7 +69,7 @@ class OPenAIGenerator { // TO DOO // USE CLASS FAKER FOR RETURN STRING - return ""; + return $this->faker->getTest(); } } diff --git a/index.php b/index.php index 1f895f6706cef38a29820a9423b7be5a30c79d51..ee6690a780501df69050fbfc6b02e966fe29f46f 100644 --- a/index.php +++ b/index.php @@ -21,7 +21,7 @@ HTMLEOF; if(!empty($_POST['question'])) { - $gen = new OpenAIGenerator($_POST['question']); + $gen = new OpenAIGenerator($_POST['question'], true ,true); echo $gen; } else