Commit 5eeac1de authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS|Function_8' into 'main'

Ptps|function 8

See merge request !18
parents f058647d c51c544d
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

use Exception;

class ReadLogFileAction
{
    /**
     * Принимает путь до файла,
     * проверяет, что файл существует и выводит пользователю весь контент файла
     * (файл можешь создать любой)
     *
     * @param string $filePath путь до файла
     * @return void
     * @throws Exception при отсутсвии фаила по переданному пути
     */
    public static function read(string $filePath): void
    {
        if (!file_exists($filePath)) {
            throw new Exception("По данному пути ничего не найдено: $filePath");
        }

        echo file_get_contents($filePath);
    }
}
+5 −0
Original line number Diff line number Diff line
1 H
2  E
3   L
4    L
5     O
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ namespace App\TestData;

class TestData
{
    public const FILE_PATH = "TestData/FileToRead.txt";

    public const NON_UNIQE_ARRAY = [
        [
            'laravel',
+9 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

require_once __DIR__ . '/../vendor/autoload.php';


use App\Actions\ReadLogFileAction;
use App\Actions\UniqElementsAction;
use App\Actions\DiffDaysAction;
use App\Actions\CountFriday13;
@@ -12,6 +12,14 @@ use App\Actions\IdSearchAction;
use App\Actions\PrepareMenuAction;
use App\TestData\TestData;

echo 'ReadLogFileAction: <br>';
try {
    ReadLogFileAction::read(TestData::FILE_PATH);
} catch (Exception $ex) {
    echo $ex->getMessage();
}
echo '<hr>';

echo 'UniqElementsAction: <br>';
var_dump(UniqElementsAction::uniqElements(TestData::NON_UNIQE_ARRAY));
echo '<hr>';