/**
  * @param string $saveDirectory
  * @param array $filteredPost
  * @param array $result
  * @return array
  */
 public function getSchemaSql($saveDirectory, $filteredPost, $result)
 {
     $entityManager = $this->createEM($saveDirectory, $filteredPost['driver'], $filteredPost['dbname'], $filteredPost['user'], $filteredPost['password']);
     $classes = $this->getEntitiesMetadata($saveDirectory, $filteredPost, $entityManager);
     if (count($classes) == 0) {
         return Utils::returnResultWithErrorMessage($result, 'nofiles');
     }
     $schemaTool = $this->getSchemaTool($entityManager);
     try {
         $schemaSqlArray = $this->getArrayOfSqlLines($schemaTool, $classes);
     } catch (\Exception $e) {
         return Utils::returnResultWithErrorMessage($result, 'sqlstringfailed');
     }
     $schemaSql = "";
     if ($schemaSqlArray) {
         $result['status'] = 'success';
         foreach ($schemaSqlArray as $sql) {
             $schemaSql .= $sql . "<br/>";
         }
         $result['schemaSQL'] = $schemaSql;
     } else {
         return Utils::returnResultWithErrorMessage($result, 'sqlstringfailed');
     }
     return $result;
 }
 /**
  * @param array $post
  * @param array $result
  * @return array
  */
 public function saveFiles($post, $result)
 {
     if (Utils::areThereDuplicatePropertyNames($post)) {
         return Utils::returnResultWithErrorMessage($result, "duplicatePropertyNames");
     }
     $this->getEntityStringCreator()->consumePostData($post);
     $namespace = $this->getEntityStringCreator()->getClassDataStringCreator()->getNamespace();
     $namespace = Utils::replaceSlashesWithSystemSeparator($namespace);
     $classname = $this->getEntityStringCreator()->getClassDataStringCreator()->getClassname();
     $targetPhpFilePath = $this->buildTargetFilePath($namespace, $classname, $this->getSaveDir(), false);
     $jsonTargetFilePath = $this->buildTargetFilePath($namespace, $classname, $this->getJsonSaveDir(), true);
     if (!$targetPhpFilePath || !$jsonTargetFilePath) {
         return Utils::returnResultWithErrorMessage($result, "didntcreatefolder");
     }
     $outputString = $this->getEntityStringCreator()->makeFinalEntityString();
     $jsonRepresentation = $this->getEntityStringCreator()->createJsonRepresentation();
     if (!$outputString || !$jsonRepresentation) {
         return Utils::returnResultWithErrorMessage($result, "stringnotcreated");
     }
     $finalPhpString = "<?php\n\n" . $outputString;
     file_put_contents($targetPhpFilePath, $finalPhpString);
     file_put_contents($jsonTargetFilePath, $jsonRepresentation);
     if ($this->checkIfContentsMatchTheInput($targetPhpFilePath, $finalPhpString, $jsonTargetFilePath, $jsonRepresentation)) {
         $result["status"] = "success";
         $result["entityString"] = $finalPhpString;
         $result["jsonEntityRepresentation"] = $jsonRepresentation;
     } else {
         $result["message"] = "notsaved";
     }
     return $result;
 }
 public function testReturnResultWithErrorMessage()
 {
     $test = [];
     $result = Utils::returnResultWithErrorMessage($test, "testMessage");
     $this->assertArrayHasKey('message', $result);
     $this->assertEquals('testMessage', $result['message']);
 }
 /**
  * @param array $post
  * @param array $result
  * @return array
  */
 public function getString($post, $result)
 {
     if (Utils::areThereDuplicatePropertyNames($post)) {
         return Utils::returnResultWithErrorMessage($result, "duplicatePropertyNames");
     }
     $this->getEntityStringCreator()->consumePostData($post);
     if (!@($finalString = $this->getEntityStringCreator()->makeFinalEntityString())) {
         return Utils::returnResultWithErrorMessage($result, "stringnotcreated");
     }
     $result["entityString"] = "<pre>{$finalString}</pre>";
     $result["status"] = "success";
     return $result;
 }
 /**
  * @param array $post
  * @param array $result
  * @return JsonModel
  */
 public function populateForm($post, $result)
 {
     $classname = Utils::replaceSlashesWithSystemSeparator($post["classname"]);
     if (!$classname || $classname == "") {
         return $result;
     }
     $filename = $this->getJsonSaveDir() . DIRECTORY_SEPARATOR . $classname . ".json";
     $json = @file_get_contents($filename);
     //filename is made from classname and it's in turn made from reading directory content.
     if (!$json || $json == "") {
         return $result;
     }
     $result["status"] = "success";
     $result["json"] = $json;
     unset($result["message"]);
     return $result;
 }