Loading index.php +0 −32 Original line number Diff line number Diff line Loading @@ -68,37 +68,5 @@ $func = new Hp\Test\Functions(); ]; print_r($func->prepareMenu($aMenu)); ?> <h1>Function 5</h1> <?php print("<h2>До НГ: </h2>"); print($func->howDaysToNy(new DateTimeImmutable())); ?> <h1>Function 6</h1> <?php print("<h2>Пятницы 13: </h2>"); foreach($func->countFriday13(2024) as $date) { print($date->format("Y-m-d l") . "\n"); } ?> <h1>Function 7</h1> <?php print("<h2>Разница дней: </h2>"); print($func->diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01"))); ?> <h1>Function 8</h1> <?php $func->readLogFile(__DIR__ . "/public/text.txt"); ?> <h1>Function 9</h1> <?php foreach($func->readFileLineByLine(__DIR__ . "/public/text.txt") as $line) { print($line); } ?> </body> </html> No newline at end of file src/Functions.php +0 −77 Original line number Diff line number Diff line Loading @@ -117,82 +117,5 @@ class Functions { * 'submenu' => [ * ['name' => 'Посуда','depth' => 1,],]], ]; */ /** * Функция рассчитывает кол-во дней до нового года * @param DateTime $date дата от которой, необходимо рассчитать кол-во дней * @return int */ function howDaysToNy(DateTimeImmutable $date): int { $endYear = date("Y-12-31", date_timestamp_get($date)); $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return $dateInterval->format("%a") + 1; } /** * Вернет все пятницы 13 в году * @param int $yaer год, в котором необходимо произвести расчет * @return DateTimeImmutable[] */ function countFriday13(int $year): iterable { $stardDate = new DateTime("{$year}-01-01 Friday"); $year += 1; $endDate = new DateTime("{$year}-01-01"); $interval = new DateInterval('P7D'); foreach(new DatePeriod($stardDate, $interval, $endDate) as $day) { yield new DateTimeImmutable($day->format("Y-m-d")); } } /** * Вернет кол-во дней между датами * @param DateTimeImmutable $dateStart дата начала * @param DateTimeImmutable $dateEnd дата окончания * @return int */ function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { $dateInterval = date_diff($dateStart, $dateEnd); return $dateInterval->format("%a") ; } /** * Переделай своё решение 8 задачи: * замени вывод всего текста из файла разом на * построчный вывод используя yield * @param string $filePath путь до файла * @return void */ function readLogFile(string $filePath): void { if (file_exists($filePath)) { $text = ""; $file = fopen($filePath, "r"); while(!feof($file)) { $line = fgets($file); $text .= $line; } fclose($file); print($text); } else print("Такого файла не существует."); } /** * Переделай своё решение 8 задачи: * замени вывод всего текста из файла разом на * построчный вывод используя yield * @param string $filePath путь до файла * @return void */ function readFileLineByLine(string $filePath): iterable { if (file_exists($filePath)) { $file = fopen($filePath, "r"); while(!feof($file)) { yield fgets($file); } fclose($file); } else yield "Такого файла не существует."; } } Loading
index.php +0 −32 Original line number Diff line number Diff line Loading @@ -68,37 +68,5 @@ $func = new Hp\Test\Functions(); ]; print_r($func->prepareMenu($aMenu)); ?> <h1>Function 5</h1> <?php print("<h2>До НГ: </h2>"); print($func->howDaysToNy(new DateTimeImmutable())); ?> <h1>Function 6</h1> <?php print("<h2>Пятницы 13: </h2>"); foreach($func->countFriday13(2024) as $date) { print($date->format("Y-m-d l") . "\n"); } ?> <h1>Function 7</h1> <?php print("<h2>Разница дней: </h2>"); print($func->diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01"))); ?> <h1>Function 8</h1> <?php $func->readLogFile(__DIR__ . "/public/text.txt"); ?> <h1>Function 9</h1> <?php foreach($func->readFileLineByLine(__DIR__ . "/public/text.txt") as $line) { print($line); } ?> </body> </html> No newline at end of file
src/Functions.php +0 −77 Original line number Diff line number Diff line Loading @@ -117,82 +117,5 @@ class Functions { * 'submenu' => [ * ['name' => 'Посуда','depth' => 1,],]], ]; */ /** * Функция рассчитывает кол-во дней до нового года * @param DateTime $date дата от которой, необходимо рассчитать кол-во дней * @return int */ function howDaysToNy(DateTimeImmutable $date): int { $endYear = date("Y-12-31", date_timestamp_get($date)); $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); return $dateInterval->format("%a") + 1; } /** * Вернет все пятницы 13 в году * @param int $yaer год, в котором необходимо произвести расчет * @return DateTimeImmutable[] */ function countFriday13(int $year): iterable { $stardDate = new DateTime("{$year}-01-01 Friday"); $year += 1; $endDate = new DateTime("{$year}-01-01"); $interval = new DateInterval('P7D'); foreach(new DatePeriod($stardDate, $interval, $endDate) as $day) { yield new DateTimeImmutable($day->format("Y-m-d")); } } /** * Вернет кол-во дней между датами * @param DateTimeImmutable $dateStart дата начала * @param DateTimeImmutable $dateEnd дата окончания * @return int */ function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { $dateInterval = date_diff($dateStart, $dateEnd); return $dateInterval->format("%a") ; } /** * Переделай своё решение 8 задачи: * замени вывод всего текста из файла разом на * построчный вывод используя yield * @param string $filePath путь до файла * @return void */ function readLogFile(string $filePath): void { if (file_exists($filePath)) { $text = ""; $file = fopen($filePath, "r"); while(!feof($file)) { $line = fgets($file); $text .= $line; } fclose($file); print($text); } else print("Такого файла не существует."); } /** * Переделай своё решение 8 задачи: * замени вывод всего текста из файла разом на * построчный вывод используя yield * @param string $filePath путь до файла * @return void */ function readFileLineByLine(string $filePath): iterable { if (file_exists($filePath)) { $file = fopen($filePath, "r"); while(!feof($file)) { yield fgets($file); } fclose($file); } else yield "Такого файла не существует."; } }