From 17eb5a1129b8c62c8bb22c3ac3e3a739e8b2130b Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Tue, 9 Apr 2024 11:02:36 +0500 Subject: [PATCH 1/9] add readFileLineByLine --- .../a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 | 2 ++ src/Controller/HomeController.php | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 b/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 index e69de29..ea6a1d3 100644 --- a/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 +++ b/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 @@ -0,0 +1,2 @@ + +vphp:S121"0Add curly braces around the nested statement(s).(8Ƌ1J$562771d0-0b91-4f4c-beaf-90c25c2ac224 \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 51d19fa..168fb51 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -12,26 +12,26 @@ use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - private function readLogFile(string $fileName): string { + private function readFileLineByLine(string $fileName): iterable { $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName; if (file_exists($filePath)) { - $text = ""; $file = fopen($filePath, "r"); while(!feof($file)) { - $line = fgets($file); - $text .= $line; + yield fgets($file); } fclose($file); - return $text; } - return "Такого файла не существует."; + else yield "Такого файла не существует."; } #[Route('/{fileName}', name: 'home')] public function home(string $fileName): Response // text.txt { - $text = $this->readLogFile($fileName); + $text = ""; + foreach($this->readFileLineByLine($fileName) as $line) { + $text .= $line; + } return $this->render('home.html.twig', ['text' => $text]); } } -- GitLab From 2a5ed5cc258d8a70e75bb5cb112fd3789ceb75ac Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Fri, 12 Apr 2024 17:30:48 +0500 Subject: [PATCH 2/9] refactoring --- .idea/sonarlint.xml | 10 + .../001fdc7418679b6419e44b1142ab051819764ece | 0 .../43dcb35f966f0fa054ba7993783bf64ca2be218c | 0 .../6037d4b4b463114752d4470f297faf20f6eb091f | 0 .../672311d2a7e203158feec05c65a1596673272747 | 0 .../6e70b6a94de880e98216f758f5f903c70ccf92d9 | 0 .../87042d1f46b57381244d70e7a42feeb7710727dc | 0 .../a5cc2925ca8258af241be7e5b0381edf30266302 | 0 .../ad8b439416d1e02614f47c5b471c7c4e587dca82 | 2 - .../baef02989dedf0ec859f7bce087a69f29bef2b72 | 0 .../c5d6e48c28c17a397cf53caa8389f831b393980f | 0 .../d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 | 0 .../fdb03812440437b51cbe4b19e899bfc5f72972fc | 0 .idea/sonarlint/issuestore/index.pb | 4 +- .../001fdc7418679b6419e44b1142ab051819764ece | 0 .../43dcb35f966f0fa054ba7993783bf64ca2be218c | 0 .../6037d4b4b463114752d4470f297faf20f6eb091f | 0 .../672311d2a7e203158feec05c65a1596673272747 | 0 .../6e70b6a94de880e98216f758f5f903c70ccf92d9 | 0 .../87042d1f46b57381244d70e7a42feeb7710727dc | 0 .../a5cc2925ca8258af241be7e5b0381edf30266302 | 0 .../baef02989dedf0ec859f7bce087a69f29bef2b72 | 0 .../c5d6e48c28c17a397cf53caa8389f831b393980f | 0 .../d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 | 0 .../fdb03812440437b51cbe4b19e899bfc5f72972fc | 0 .idea/sonarlint/securityhotspotstore/index.pb | 4 +- src/Action/Functions.php | 239 ++++++++++++++++++ src/Controller/HomeController.php | 29 +-- 28 files changed, 267 insertions(+), 21 deletions(-) create mode 100644 .idea/sonarlint.xml create mode 100644 .idea/sonarlint/issuestore/0/0/001fdc7418679b6419e44b1142ab051819764ece create mode 100644 .idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c create mode 100644 .idea/sonarlint/issuestore/6/0/6037d4b4b463114752d4470f297faf20f6eb091f create mode 100644 .idea/sonarlint/issuestore/6/7/672311d2a7e203158feec05c65a1596673272747 create mode 100644 .idea/sonarlint/issuestore/6/e/6e70b6a94de880e98216f758f5f903c70ccf92d9 create mode 100644 .idea/sonarlint/issuestore/8/7/87042d1f46b57381244d70e7a42feeb7710727dc create mode 100644 .idea/sonarlint/issuestore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 create mode 100644 .idea/sonarlint/issuestore/b/a/baef02989dedf0ec859f7bce087a69f29bef2b72 create mode 100644 .idea/sonarlint/issuestore/c/5/c5d6e48c28c17a397cf53caa8389f831b393980f create mode 100644 .idea/sonarlint/issuestore/d/3/d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 create mode 100644 .idea/sonarlint/issuestore/f/d/fdb03812440437b51cbe4b19e899bfc5f72972fc create mode 100644 .idea/sonarlint/securityhotspotstore/0/0/001fdc7418679b6419e44b1142ab051819764ece create mode 100644 .idea/sonarlint/securityhotspotstore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c create mode 100644 .idea/sonarlint/securityhotspotstore/6/0/6037d4b4b463114752d4470f297faf20f6eb091f create mode 100644 .idea/sonarlint/securityhotspotstore/6/7/672311d2a7e203158feec05c65a1596673272747 create mode 100644 .idea/sonarlint/securityhotspotstore/6/e/6e70b6a94de880e98216f758f5f903c70ccf92d9 create mode 100644 .idea/sonarlint/securityhotspotstore/8/7/87042d1f46b57381244d70e7a42feeb7710727dc create mode 100644 .idea/sonarlint/securityhotspotstore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 create mode 100644 .idea/sonarlint/securityhotspotstore/b/a/baef02989dedf0ec859f7bce087a69f29bef2b72 create mode 100644 .idea/sonarlint/securityhotspotstore/c/5/c5d6e48c28c17a397cf53caa8389f831b393980f create mode 100644 .idea/sonarlint/securityhotspotstore/d/3/d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 create mode 100644 .idea/sonarlint/securityhotspotstore/f/d/fdb03812440437b51cbe4b19e899bfc5f72972fc create mode 100644 src/Action/Functions.php diff --git a/.idea/sonarlint.xml b/.idea/sonarlint.xml new file mode 100644 index 0000000..6817efe --- /dev/null +++ b/.idea/sonarlint.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/0/0/001fdc7418679b6419e44b1142ab051819764ece b/.idea/sonarlint/issuestore/0/0/001fdc7418679b6419e44b1142ab051819764ece new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c b/.idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/6/0/6037d4b4b463114752d4470f297faf20f6eb091f b/.idea/sonarlint/issuestore/6/0/6037d4b4b463114752d4470f297faf20f6eb091f new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/6/7/672311d2a7e203158feec05c65a1596673272747 b/.idea/sonarlint/issuestore/6/7/672311d2a7e203158feec05c65a1596673272747 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/6/e/6e70b6a94de880e98216f758f5f903c70ccf92d9 b/.idea/sonarlint/issuestore/6/e/6e70b6a94de880e98216f758f5f903c70ccf92d9 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/8/7/87042d1f46b57381244d70e7a42feeb7710727dc b/.idea/sonarlint/issuestore/8/7/87042d1f46b57381244d70e7a42feeb7710727dc new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 b/.idea/sonarlint/issuestore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 b/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 index ea6a1d3..e69de29 100644 --- a/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 +++ b/.idea/sonarlint/issuestore/a/d/ad8b439416d1e02614f47c5b471c7c4e587dca82 @@ -1,2 +0,0 @@ - -vphp:S121"0Add curly braces around the nested statement(s).(8Ƌ1J$562771d0-0b91-4f4c-beaf-90c25c2ac224 \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/b/a/baef02989dedf0ec859f7bce087a69f29bef2b72 b/.idea/sonarlint/issuestore/b/a/baef02989dedf0ec859f7bce087a69f29bef2b72 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/c/5/c5d6e48c28c17a397cf53caa8389f831b393980f b/.idea/sonarlint/issuestore/c/5/c5d6e48c28c17a397cf53caa8389f831b393980f new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/d/3/d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 b/.idea/sonarlint/issuestore/d/3/d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/f/d/fdb03812440437b51cbe4b19e899bfc5f72972fc b/.idea/sonarlint/issuestore/f/d/fdb03812440437b51cbe4b19e899bfc5f72972fc new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index dae00e9..ab15ef3 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -10,4 +10,6 @@ C E assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 E -public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 \ No newline at end of file +public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 +H +src/Action/Functions.php,4\3\43dcb35f966f0fa054ba7993783bf64ca2be218c \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/0/0/001fdc7418679b6419e44b1142ab051819764ece b/.idea/sonarlint/securityhotspotstore/0/0/001fdc7418679b6419e44b1142ab051819764ece new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c b/.idea/sonarlint/securityhotspotstore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/6/0/6037d4b4b463114752d4470f297faf20f6eb091f b/.idea/sonarlint/securityhotspotstore/6/0/6037d4b4b463114752d4470f297faf20f6eb091f new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/6/7/672311d2a7e203158feec05c65a1596673272747 b/.idea/sonarlint/securityhotspotstore/6/7/672311d2a7e203158feec05c65a1596673272747 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/6/e/6e70b6a94de880e98216f758f5f903c70ccf92d9 b/.idea/sonarlint/securityhotspotstore/6/e/6e70b6a94de880e98216f758f5f903c70ccf92d9 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/8/7/87042d1f46b57381244d70e7a42feeb7710727dc b/.idea/sonarlint/securityhotspotstore/8/7/87042d1f46b57381244d70e7a42feeb7710727dc new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 b/.idea/sonarlint/securityhotspotstore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/b/a/baef02989dedf0ec859f7bce087a69f29bef2b72 b/.idea/sonarlint/securityhotspotstore/b/a/baef02989dedf0ec859f7bce087a69f29bef2b72 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/c/5/c5d6e48c28c17a397cf53caa8389f831b393980f b/.idea/sonarlint/securityhotspotstore/c/5/c5d6e48c28c17a397cf53caa8389f831b393980f new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/d/3/d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 b/.idea/sonarlint/securityhotspotstore/d/3/d355caa07ac4b7aa5002c909a2c1d4a6319cf7e9 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/f/d/fdb03812440437b51cbe4b19e899bfc5f72972fc b/.idea/sonarlint/securityhotspotstore/f/d/fdb03812440437b51cbe4b19e899bfc5f72972fc new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index dae00e9..ab15ef3 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -10,4 +10,6 @@ C E assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19 E -public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 \ No newline at end of file +public/files/text.txt,9\9\994b95f5d0e2f9641bf4e2c30422e6a0a6a105b5 +H +src/Action/Functions.php,4\3\43dcb35f966f0fa054ba7993783bf64ca2be218c \ No newline at end of file diff --git a/src/Action/Functions.php b/src/Action/Functions.php new file mode 100644 index 0000000..8e9fadc --- /dev/null +++ b/src/Action/Functions.php @@ -0,0 +1,239 @@ +12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4], + * ['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5],] + */ + + /** + * Найдет элемент с указаным id + * @param array $array - массив, содержащий элементы со структурой + * [ + * 'id' => 30, + * 'name' => 'Jhon', + * 'age' => 23, + * ] + * @param $id - ид искомого элемента + * @return ?array - найденный элемент + */ + + public function search(array $array, int $id): ?array + { + $rowId = array_search($id, array_column($array, 'id'), true); + if ($rowId) { + return $array[$rowId]; + } + return null; + } + + /** + * Удалить дубликаты, оставив только уникальные значения + * @param array $array + * @return array + */ + + public function uniqElements(array $array): array + { + return array_unique($array, SORT_REGULAR); + } + + /** + * Выходной массив: + * Array ( + * [0] => Array([0] => laravel, [1] => php) + * [1] => Array([0] => codeigniter, [1] => php) + * [3] => Array([0] => c++, [1] => java)) + * ) + */ + + /** + * Сгруппировать подразедлы в верхние разделы меню + * Дочерние элементы поместить в массив родителя с ключом submenu + * Значение под ключом depth определяет уровень раздела + * Массив $aMenu всегда начинается с элемента depth = 0, + * все последующие элементы с depth = 1 являются его дочерними + * элементами + * @param array $aMenu + * @return array + */ + + public function prepareMenu(array $aMenu): array + { + $result = []; + foreach ($aMenu as $arr) { + if ($arr['depth'] === 0) { + $result[] = array( + 'name' => $arr['name'], + 'depth' => $arr['depth'], + 'submenu' => [] + ); + continue; + } + $result[array_key_last($result)]['submenu'][] = array( + 'name' => $arr['name'], + 'depth' => $arr['depth'], + ); + } + return $result; + } + + /** + * Выходные данные: + * $aMenu = [ + * [ + * 'name' => 'Смартфоны и гаджеты', + * 'depth' => 0, + * 'submenu' => [ + * ['name' => 'Смартфоны, мобильные телефоны','depth' => 1,], + * ['name' => 'Планшеты','depth' => 1,], + * ['name' => 'Наушники и гарнитуры','depth' => 1,],], + * ], + * [ + * 'name' => 'Компьютеры и ноутбуки', + * 'depth' => 0, + * 'submenu' => [ + * ['name' => 'Ноутбуки и аксессуары','depth' => 1,], + * ['name' => 'Компьютеры и мониторы','depth' => 1,], + * ['name' => 'Компьютерные комплектующие','depth' => 1,],]], + * [ + * 'name' => 'Техника для дома', + * 'depth' => 0, + * 'submenu' => [ + * ['name' => 'Техника для уборки','depth' => 1,], + * ['name' => 'Товары для ухода за одеждой','depth' => 1,], + * ['name' => 'Аксессуары для техники','depth' => 1,],] + * ], + * [ + * 'name' => 'Товары для дома и кухни', + * 'depth' => 0, + * 'submenu' => [ + * ['name' => 'Посуда','depth' => 1,],]], + * ]; + */ + + /** + * Функция рассчитывает кол-во дней до нового года + * @param DateTimeImmutable $date дата от которой, необходимо рассчитать кол-во дней + * @return int + * @throws Exception + */ + + public function howDaysToNy(DateTimeImmutable $date): int + { + $endYear = date("Y-12-31", date_timestamp_get($date)); + $dateInterval = date_diff(new DateTimeImmutable($endYear), $date); + return (int)$dateInterval->format("%a") + 1; + } + + /** + * Вернет все пятницы 13 в году + * @param int $year год, в котором необходимо произвести расчет + * @return DateTimeImmutable[] + * @throws Exception + */ + + public function countFriday13(int $year): iterable + { + $startDate = new DateTime("$year-01-01 Friday"); + ++$year; + $endDate = new DateTime("$year-01-01"); + $interval = new DateInterval('P7D'); + foreach (new DatePeriod($startDate, $interval, $endDate) as $day) { + yield new DateTimeImmutable($day->format("Y-m-d")); + } + } + + /** + * Вернет кол-во дней между датами + * @param DateTimeImmutable $dateStart дата начала + * @param DateTimeImmutable $dateEnd дата окончания + * @return int + */ + public function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int + { + $dateInterval = date_diff($dateStart, $dateEnd); + return (int)$dateInterval->format("%a") ; + } + + /** + * Напиши функцию, которая принимает путь до файла, + * проверяет, что файл существует и выводит пользователю весь контент файла + * (файл можешь создать любой) + * @param string $filePath путь до файла + * @return void + * @throws Exception + */ + + public function readLogFile(string $filePath): void + { + if (file_exists($filePath)) { + $text = ""; + $file = fopen($filePath, 'rb'); + while(!feof($file)) { + $line = fgets($file); + $text .= $line; + } + fclose($file); + print $text; + } + else { + throw new RuntimeException("File not found: $filePath"); + } + } + + /** + * Переделай своё решение 8 задачи: + * замени вывод всего текста из файла разом на + * построчный вывод используя yield + * @param string $filePath путь до файла + * @return iterable + */ + + public function readFileLineByLine(string $filePath): iterable + { + if (file_exists($filePath)) { + $file = fopen($filePath, 'rb'); + while(!feof($file)) { + yield fgets($file); + } + fclose($file); + } + else { + throw new RuntimeException("File not found: $filePath"); + } + } +} + diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 168fb51..94b37f6 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -2,36 +2,31 @@ namespace App\Controller; -use DateInterval; -use DatePeriod; -use DateTime; -use DateTimeImmutable; +use App\Action\Functions; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - private function readFileLineByLine(string $fileName): iterable { - $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName; - if (file_exists($filePath)) { - $file = fopen($filePath, "r"); - while(!feof($file)) { - yield fgets($file); - } - fclose($file); - } - else yield "Такого файла не существует."; - } + private Functions $functions; + public function __construct(Functions $functions) + { + $this->functions = $functions; + } #[Route('/{fileName}', name: 'home')] public function home(string $fileName): Response // text.txt { + $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName; $text = ""; - foreach($this->readFileLineByLine($fileName) as $line) { + foreach ($this->functions->readFileLineByLine($filePath) as $line) { $text .= $line; } - return $this->render('home.html.twig', ['text' => $text]); + $response = new JsonResponse($text); + $response->setEncodingOptions(JSON_UNESCAPED_UNICODE); + return $response; } } -- GitLab From b3f9aa8a110385771e085e1d931968f7faf2e32b Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Fri, 12 Apr 2024 18:45:00 +0500 Subject: [PATCH 3/9] refactoring --- src/Controller/HomeController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index f7a28c0..3af0b26 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -115,8 +115,8 @@ class HomeController extends AbstractController return $response; } - #[Route('/{fileName}', name: 'home')] - public function home(string $fileName): Response // text.txt + #[Route('/func9/{fileName}', name: 'func9')] + public function func9(string $fileName): Response // text.txt { $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName; $text = ""; -- GitLab From 4e59581a67250050a0f3f888b538d1cf98477b20 Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Tue, 16 Apr 2024 13:46:00 +0500 Subject: [PATCH 4/9] temp commit --- public/files/text.txt | 2 -- src/Validation/ArrayValidation.php | 26 -------------------------- src/Validation/DateValidation.php | 14 -------------- 3 files changed, 42 deletions(-) delete mode 100644 public/files/text.txt delete mode 100644 src/Validation/ArrayValidation.php delete mode 100644 src/Validation/DateValidation.php diff --git a/public/files/text.txt b/public/files/text.txt deleted file mode 100644 index 3ba1fcf..0000000 --- a/public/files/text.txt +++ /dev/null @@ -1,2 +0,0 @@ -Раз, два, три, четыре, -пять, шесть, семь, восемь. \ No newline at end of file diff --git a/src/Validation/ArrayValidation.php b/src/Validation/ArrayValidation.php deleted file mode 100644 index 5807a44..0000000 --- a/src/Validation/ArrayValidation.php +++ /dev/null @@ -1,26 +0,0 @@ - Date: Tue, 16 Apr 2024 13:46:09 +0500 Subject: [PATCH 5/9] temp commit --- composer.json | 2 +- composer.lock | 119 +++++++++++++++++++++++++++----------------------- 2 files changed, 65 insertions(+), 56 deletions(-) diff --git a/composer.json b/composer.json index be86947..5246c9a 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "symfony/translation": "7.0.*", "symfony/twig-bundle": "7.0.*", "symfony/ux-turbo": "^2.16", - "symfony/validator": "7.0.*", + "symfony/validator": "6.4.*", "symfony/web-link": "7.0.*", "symfony/yaml": "7.0.*", "twig/extra-bundle": "^2.12|^3.0", diff --git a/composer.lock b/composer.lock index 5695357..dff4a31 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "168d5f8561d288fe5cd6fd2b406687e2", + "content-hash": "91b0c89268c08e0b881610c8ba320eb8", "packages": [ { "name": "composer/semver", @@ -1070,16 +1070,16 @@ }, { "name": "doctrine/orm", - "version": "3.1.1", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/doctrine/orm.git", - "reference": "9c560713925ac5859342e6ff370c4c997acf2fd4" + "reference": "f79d166a4e844beb9389f23bdb44abdbf58cec38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/orm/zipball/9c560713925ac5859342e6ff370c4c997acf2fd4", - "reference": "9c560713925ac5859342e6ff370c4c997acf2fd4", + "url": "https://api.github.com/repos/doctrine/orm/zipball/f79d166a4e844beb9389f23bdb44abdbf58cec38", + "reference": "f79d166a4e844beb9389f23bdb44abdbf58cec38", "shasum": "" }, "require": { @@ -1152,9 +1152,9 @@ ], "support": { "issues": "https://github.com/doctrine/orm/issues", - "source": "https://github.com/doctrine/orm/tree/3.1.1" + "source": "https://github.com/doctrine/orm/tree/3.1.2" }, - "time": "2024-03-21T11:37:52+00:00" + "time": "2024-04-15T14:20:40+00:00" }, { "name": "doctrine/persistence", @@ -1375,16 +1375,16 @@ }, { "name": "monolog/monolog", - "version": "3.5.0", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448" + "reference": "4b18b21a5527a3d5ffdac2fd35d3ab25a9597654" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/c915e2634718dbc8a4a15c61b0e62e7a44e14448", - "reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/4b18b21a5527a3d5ffdac2fd35d3ab25a9597654", + "reference": "4b18b21a5527a3d5ffdac2fd35d3ab25a9597654", "shasum": "" }, "require": { @@ -1407,7 +1407,7 @@ "phpstan/phpstan": "^1.9", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-strict-rules": "^1.4", - "phpunit/phpunit": "^10.1", + "phpunit/phpunit": "^10.5.17", "predis/predis": "^1.1 || ^2", "ruflin/elastica": "^7", "symfony/mailer": "^5.4 || ^6", @@ -1460,7 +1460,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/3.5.0" + "source": "https://github.com/Seldaek/monolog/tree/3.6.0" }, "funding": [ { @@ -1472,7 +1472,7 @@ "type": "tidelift" } ], - "time": "2023-10-27T15:32:31+00:00" + "time": "2024-04-12T21:02:21+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -1529,28 +1529,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", + "version": "5.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" + "reference": "298d2febfe79d03fe714eb871d5538da55205b1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/298d2febfe79d03fe714eb871d5538da55205b1a", + "reference": "298d2febfe79d03fe714eb871d5538da55205b1a", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.1", "ext-filter": "*", - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", + "phpdocumentor/type-resolver": "^1.7", + "phpstan/phpdoc-parser": "^1.7", "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" + "mockery/mockery": "~1.3.5", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-webmozart-assert": "^1.2", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^5.13" }, "type": "library", "extra": { @@ -1574,15 +1581,15 @@ }, { "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" + "email": "opensource@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.0" }, - "time": "2021-10-19T17:43:47+00:00" + "time": "2024-04-09T21:13:58+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -6820,53 +6827,55 @@ }, { "name": "symfony/validator", - "version": "v7.0.6", + "version": "v6.4.6", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "a2df2c63b7944a162dee86ab8065f2f91b7d6e36" + "reference": "ca1d78e8677e966e307a63799677b64b194d735d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/a2df2c63b7944a162dee86ab8065f2f91b7d6e36", - "reference": "a2df2c63b7944a162dee86ab8065f2f91b7d6e36", + "url": "https://api.github.com/repos/symfony/validator/zipball/ca1d78e8677e966e307a63799677b64b194d735d", + "reference": "ca1d78e8677e966e307a63799677b64b194d735d", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php83": "^1.27", "symfony/translation-contracts": "^2.5|^3" }, "conflict": { + "doctrine/annotations": "<1.13", "doctrine/lexer": "<1.1", - "symfony/dependency-injection": "<6.4", - "symfony/doctrine-bridge": "<7.0", - "symfony/expression-language": "<6.4", - "symfony/http-kernel": "<6.4", - "symfony/intl": "<6.4", - "symfony/property-info": "<6.4", - "symfony/translation": "<6.4.3|>=7.0,<7.0.3", - "symfony/yaml": "<6.4" + "symfony/dependency-injection": "<5.4", + "symfony/expression-language": "<5.4", + "symfony/http-kernel": "<5.4", + "symfony/intl": "<5.4", + "symfony/property-info": "<5.4", + "symfony/translation": "<5.4.35|>=6.0,<6.3.12|>=6.4,<6.4.3|>=7.0,<7.0.3", + "symfony/yaml": "<5.4" }, "require-dev": { + "doctrine/annotations": "^1.13|^2", "egulias/email-validator": "^2.1.10|^3|^4", - "symfony/cache": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/console": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", - "symfony/mime": "^6.4|^7.0", - "symfony/property-access": "^6.4|^7.0", - "symfony/property-info": "^6.4|^7.0", - "symfony/translation": "^6.4.3|^7.0.3", - "symfony/yaml": "^6.4|^7.0" + "symfony/cache": "^5.4|^6.0|^7.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/console": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/expression-language": "^5.4|^6.0|^7.0", + "symfony/finder": "^5.4|^6.0|^7.0", + "symfony/http-client": "^5.4|^6.0|^7.0", + "symfony/http-foundation": "^5.4|^6.0|^7.0", + "symfony/http-kernel": "^5.4|^6.0|^7.0", + "symfony/intl": "^5.4|^6.0|^7.0", + "symfony/mime": "^5.4|^6.0|^7.0", + "symfony/property-access": "^5.4|^6.0|^7.0", + "symfony/property-info": "^5.4|^6.0|^7.0", + "symfony/translation": "^5.4.35|~6.3.12|^6.4.3|^7.0.3", + "symfony/yaml": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -6894,7 +6903,7 @@ "description": "Provides tools to validate values", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/validator/tree/v7.0.6" + "source": "https://github.com/symfony/validator/tree/v6.4.6" }, "funding": [ { @@ -6910,7 +6919,7 @@ "type": "tidelift" } ], - "time": "2024-03-28T09:20:36+00:00" + "time": "2024-03-27T22:00:14+00:00" }, { "name": "symfony/var-dumper", -- GitLab From f343dbfc87e62dcbe497cd5ca1f64ac90a3d26fc Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Tue, 16 Apr 2024 14:09:07 +0500 Subject: [PATCH 6/9] temp commit --- src/Controller/HomeController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 1ae1c84..ac992d4 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Action\Functions; +use App\Service\FileUploader; use App\Requests\{ SortPriceRequest, SearchRequest, -- GitLab From b594f6ba61a00c0fd620a3c8ea2d7d56cd859b12 Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Wed, 17 Apr 2024 10:33:47 +0500 Subject: [PATCH 7/9] fix --- .../4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c | 3 +++ src/Controller/HomeController.php | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c b/.idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c index e69de29..7521a9c 100644 --- a/.idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c +++ b/.idea/sonarlint/issuestore/4/3/43dcb35f966f0fa054ba7993783bf64ca2be218c @@ -0,0 +1,3 @@ + +php:S112"FDefine and throw a dedicated exception instead of using a generic one.(ۄ81J$47edde45-6969-4470-9c01-b4077dd7b5f4 +php:S112"FDefine and throw a dedicated exception instead of using a generic one.(ۄ81J$5eb02a27-89bd-4e34-8e30-b9f86d63a21d \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index ac992d4..2c12538 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -106,12 +106,13 @@ class HomeController extends AbstractController return $response; } - #[Route('/func9/{fileName}', name: 'func9')] - public function func9(string $fileName): Response // text.txt + #[Route('/readFileLineByLine', name: 'readFileLineByLine')] + public function readFileLineByLine(Request $request, FileUploader $fileUploader): Response // text.txt { - $filePath = $this->getParameter('kernel.project_dir') . "/public/files/" . $fileName; + $file = $request->files->get('file'); + $fileName = $fileUploader->upload($file); $text = ""; - foreach ($this->functions->readFileLineByLine($filePath) as $line) { + foreach ($this->functions->readFileLineByLine($fileName) as $line) { $text .= $line; } $response = new JsonResponse($text); -- GitLab From f7ec08afe6d2e424fcd52cf0458abbc77ae938da Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Wed, 17 Apr 2024 12:36:10 +0500 Subject: [PATCH 8/9] fix --- src/Controller/HomeController.php | 10 ++++------ src/Service/FileUploader.php | 33 ------------------------------- 2 files changed, 4 insertions(+), 39 deletions(-) delete mode 100644 src/Service/FileUploader.php diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 2c12538..0e2c3d2 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -96,23 +96,21 @@ class HomeController extends AbstractController } #[Route('/readLogFile', name: 'readLogFile')] - public function readLogFile(Request $request, FileUploader $fileUploader): Response + public function readLogFile(Request $request): Response { $file = $request->files->get('file'); - $fileName = $fileUploader->upload($file); - $text = $this->functions->readLogFile($fileName); + $text = $this->functions->readLogFile($file); $response = new JsonResponse($text); $response->setEncodingOptions(JSON_UNESCAPED_UNICODE); return $response; } #[Route('/readFileLineByLine', name: 'readFileLineByLine')] - public function readFileLineByLine(Request $request, FileUploader $fileUploader): Response // text.txt + public function readFileLineByLine(Request $request): Response // text.txt { $file = $request->files->get('file'); - $fileName = $fileUploader->upload($file); $text = ""; - foreach ($this->functions->readFileLineByLine($fileName) as $line) { + foreach ($this->functions->readFileLineByLine($file) as $line) { $text .= $line; } $response = new JsonResponse($text); diff --git a/src/Service/FileUploader.php b/src/Service/FileUploader.php deleted file mode 100644 index 8bd280f..0000000 --- a/src/Service/FileUploader.php +++ /dev/null @@ -1,33 +0,0 @@ -targetDirectory = $targetDirectory; - } - - public function upload(UploadedFile $file) - { - $fileName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) .'.'. $file->guessExtension(); - try { - $file->move($this->getTargetDirectory(), $fileName); - } catch (FileException $e) { - throw new FileException($e->getMessage()); - } - - return $this->getTargetDirectory() . $fileName; - } - - public function getTargetDirectory() - { - return $this->targetDirectory; - } -} \ No newline at end of file -- GitLab From 4cbd2e5735eb29f36f9340b2ed95bc5d1b8ea50a Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Wed, 17 Apr 2024 15:04:27 +0500 Subject: [PATCH 9/9] fix --- config/services.yaml | 5 +---- src/Controller/HomeController.php | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index b94693f..c18468a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -21,7 +21,4 @@ services: - '../src/Kernel.php' # add more service definitions when explicit configuration is needed - # please note that last definitions always *replace* previous ones - App\Service\FileUploader: - arguments: - $targetDirectory: '%kernel.project_dir%/public/files/' \ No newline at end of file + # please note that last definitions always *replace* previous ones \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 0e2c3d2..06abf3e 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -99,7 +99,7 @@ class HomeController extends AbstractController public function readLogFile(Request $request): Response { $file = $request->files->get('file'); - $text = $this->functions->readLogFile($file); + $text = $this->functions->readLogFile($file->getRealPath()); $response = new JsonResponse($text); $response->setEncodingOptions(JSON_UNESCAPED_UNICODE); return $response; @@ -110,7 +110,7 @@ class HomeController extends AbstractController { $file = $request->files->get('file'); $text = ""; - foreach ($this->functions->readFileLineByLine($file) as $line) { + foreach ($this->functions->readFileLineByLine($file->getRealPath()) as $line) { $text .= $line; } $response = new JsonResponse($text); -- GitLab