{ $this->structure = $structure; $this->answers = $answers; } public function validate() { return $this->structure->check($this->answers); } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $postdata = file_get_contents("php://input"); $request = json_decode($postdata, true); $structure = $request['structure']; $structureId = $request['structureId']; $path = MAIN_PATH . BARANEK_PATH . "php/structures/" . ucfirst($structure) . "StructureStrategy.php"; require_once $path; } catch (Exception $e) { echo "reject"; exit; } $strategy = ucfirst($structure) . "StructureStrategy"; $validator = new AnswerValidator(new $strategy($structureId), (array) $request['answers']); if ($validator->validate()) { echo "resolve"; } else { echo "reject"; } } else { echo "reject"; }