/**
  * @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;
 }
 /**
  * @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;
 }
 public function testReplaceSlashesWithSystemSeparator()
 {
     $testString = "Test\\Test\\Test";
     $result = Utils::replaceSlashesWithSystemSeparator($testString);
     $this->assertEquals("Test" . self::DS . "Test" . self::DS . "Test", $result);
 }