$fileRaw = file($filename); if ($fileRaw == false) { throw new \Exception("Can't read file {$filename}." . PHP_EOL); } $fileTrimmed = array_map("trim", $fileRaw); $fileFiltered = array_filter($fileTrimmed, "checkStringCallback"); return $fileFiltered; } function selectRandomElement($array) { return $array[mt_rand(0, count($array) - 1)]; } $options = getopt("c:h"); if (!isset($options["c"]) || $options["c"] <= 0 || isset($options["h"])) { die(outputHelpMessage($argv)); } $names = readNamesFile("./resource/names.txt"); $surnames = readNamesFile("./resource/surnames.txt"); for ($i = 0; $i < $options["c"]; $i++) { $student = new Student(); $student->setFirstName(selectRandomElement($names)); $student->setLastName(selectRandomElement($surnames)); $student->setGender(Student::GENDER_MALE); $student->setGroup(getRandomString(3, 5)); $student->setEmail(sprintf("*****@*****.**", getRandomString(5, 13))); $student->setBirthYear(sprintf("19%d%d", mt_rand(0, 9), mt_rand(0, 9))); $student->setStatus(Student::STATUS_RESIDENT); $student->setRating(mt_rand(0, StudentValidator::STUDENT_MAX_RATING)); $container["studentGateway"]->addStudent($student); } print "Database was successfully filled for {$options['c']} entries." . PHP_EOL;