Commit 533f878b authored by Akex's avatar Akex
Browse files

add func to read file | add test data

parent 2a7f91b8
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
+1 −1
Original line number Diff line number Diff line
@@ -8,5 +8,5 @@ namespace App\TestData;

class TestData
{

    public const FILE_PATH = "TestData/FileToRead.txt";
}
+6 −1
Original line number Diff line number Diff line
@@ -2,6 +2,11 @@

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

use App\Actions /*placeholder for a class */;
use App\Actions\ReadLogFileAction;
use App\TestData\TestData;

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