From 4235deb4afd2bba4b0a294803a2c0355662936c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sun, 10 Mar 2024 08:27:37 +0300 Subject: [PATCH 01/15] =?UTF-8?q?=D0=90=D0=BB=D0=B3=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D1=82=D0=BC=D1=8B=20=D0=9A=D0=B0=D1=80=D0=BC=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=93.=D0=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e16b2a49b..bc954ee5f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,74 @@ -# PHP_2023 +## https://leetcode.com/problems/intersection-of-two-linked-lists/ -https://otus.ru/lessons/razrabotchik-php/?utm_source=github&utm_medium=free&utm_campaign=otus +сложность O(m+n) + + +``` +class Solution { + function getIntersectionNode($headA, $headB) { + $itemA = $headA; + $itemB = $headB; + + while ($itemA !== $itemB) { + $itemA = $itemA ? $itemA->next : $headB; + $itemB = $itemB ? $itemB->next : $headA; + } + return $itemA; + } +} +``` + +## https://leetcode.com/problems/fraction-to-recurring-decimal/description/ + +сложность O(n) + +``` +function fractionToDecimal($numerator, $denominator) { + if ($numerator == 0) { + return "0"; + } + + $result = ""; + + $numeratorSign = $numerator < 0 ? "-" : ""; + $denominatorSign = $denominator < 0 ? "-" : ""; + + if ($numeratorSign !== $denominatorSign) { + $result .= "-"; + } + + $numerator = abs($numerator); + $denominator = abs($denominator); + + $quotient = (int) ($numerator / $denominator); + $remainder = $numerator % $denominator; + + $result .= (string) $quotient; + + if ($remainder === 0) { + return $result; + } + + $result .= "."; + + $fractionalPart = ""; + $remainderPositions = []; + + while ($remainder !== 0) { + if (isset($remainderPositions[$remainder])) { + $index = $remainderPositions[$remainder]; + $fractionalPart = substr_replace($fractionalPart, "(", $index, 0); + $fractionalPart .= ")"; + break; + } + + $remainderPositions[$remainder] = strlen($fractionalPart); + $remainder *= 10; + $quotient = (int) ($remainder / $denominator); + $fractionalPart .= (string) $quotient; + $remainder %= $denominator; + } + + return $result . $fractionalPart; +} +``` From db922d7583f85e1a3a9db540361cd5fbef0d8605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 16 Mar 2024 13:38:16 +0300 Subject: [PATCH 02/15] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 +++--- hw19/code/composer.json | 10 ++++++++ hw19/code/composer.lock | 18 ++++++++++++++ hw19/docker/docker-compose.yaml | 42 +++++++++++++++++++++++++++++++++ hw19/docker/php-fpm/Dockerfile | 27 +++++++++++++++++++++ 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 hw19/code/composer.json create mode 100644 hw19/code/composer.lock create mode 100644 hw19/docker/docker-compose.yaml create mode 100644 hw19/docker/php-fpm/Dockerfile diff --git a/.gitignore b/.gitignore index 46833ddb6..3b6a6abe3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /.idea -mysql/dbdata/* -code/* -.env -php-fpm/socket/* +hw19/code/vendor + + diff --git a/hw19/code/composer.json b/hw19/code/composer.json new file mode 100644 index 000000000..09e7a9882 --- /dev/null +++ b/hw19/code/composer.json @@ -0,0 +1,10 @@ +{ + "name": "gkarman/rabbitmq", + "type": "project", + "autoload": { + "psr-4": { + "Gkarman\\Rabbitmq\\": "src/" + } + }, + "require": {} +} diff --git a/hw19/code/composer.lock b/hw19/code/composer.lock new file mode 100644 index 000000000..ae571edf6 --- /dev/null +++ b/hw19/code/composer.lock @@ -0,0 +1,18 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "7cc6b26b3b75d5355b11d3180552fcf6", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/hw19/docker/docker-compose.yaml b/hw19/docker/docker-compose.yaml new file mode 100644 index 000000000..a449165b8 --- /dev/null +++ b/hw19/docker/docker-compose.yaml @@ -0,0 +1,42 @@ +version: '3' + +services: + app: + build: + context: ./php-fpm + dockerfile: Dockerfile + image: otus/php-fpm + container_name: otus-php-fpm + volumes: + - ../code:/var/www/app.loc + networks: + - otus-network + + nginx: + build: + context: ./nginx + dockerfile: Dockerfile + image: otus/nginx + container_name: otus-nginx + ports: + - "80:80" + volumes: + - ../code:/var/www/app.loc + networks: + - otus-network + + rabbitmq: + image: rabbitmq:3.7.5-management + working_dir: /app + hostname: rabbit-mq + container_name: 'otus-rabbit-mq' + ports: + - 15672:15672 + - 5672:5672 + environment: + RABBITMQ_DEFAULT_USER: user + RABBITMQ_DEFAULT_PASS: password + +networks: + otus-network: + driver: bridge diff --git a/hw19/docker/php-fpm/Dockerfile b/hw19/docker/php-fpm/Dockerfile new file mode 100644 index 000000000..e9567a1ac --- /dev/null +++ b/hw19/docker/php-fpm/Dockerfile @@ -0,0 +1,27 @@ +FROM php:8.2-fpm + +RUN apt-get update && apt-get install -y \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libpng-dev \ + libonig-dev \ + libzip-dev \ + libmemcached-dev \ + zlib1g-dev \ + libssl-dev \ + libmcrypt-dev \ + && pecl install redis \ + && docker-php-ext-enable redis \ + && pecl install mcrypt \ + && docker-php-ext-enable mcrypt \ + && docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) gd \ + && pecl install memcached && \ + docker-php-ext-enable memcached + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer + +COPY ./php.ini /usr/local/etc/php/conf.d/php-custom.ini + +CMD ["php-fpm"] From bb5c2d2deaaa705e8aed2597b9605c2e37f94a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Thu, 21 Mar 2024 09:30:36 +0300 Subject: [PATCH 03/15] GKarman/hw-19-rabbitMQ --- .gitignore | 2 +- hw19/code/composer.json | 5 +- hw19/code/composer.lock | 317 +++++++++++++++++- hw19/code/index.php | 11 + hw19/code/src/App.php | 24 ++ hw19/code/src/Configs/rabbitMQ.ini | 5 + .../Application/GenerateReportUseCase.php | 35 ++ .../Request/GenerateOrderRequest.php | 24 ++ .../Response/GenerateReportResponse.php | 13 + .../Domain/Entity/OrderReportRequest.php | 41 +++ .../OrderReportRepositoryInterface.php | 11 + .../OrderReport/Domain/ValueObject/Email.php | 29 ++ .../OrderReport/Domain/ValueObject/Id.php | 29 ++ .../Domain/ValueObject/ReportDateFrom.php | 36 ++ .../Domain/ValueObject/ReportDateTo.php | 36 ++ .../Console/OrderReportCommand.php | 29 ++ .../Http/OrderReportController.php | 25 ++ .../Repository/RabbitMQQueueRepository.php | 40 +++ hw19/docker/docker-compose.yaml | 2 + hw19/docker/nginx/Dockerfile | 11 + hw19/docker/nginx/hosts/app.loc.conf | 24 ++ hw19/docker/php-fpm/Dockerfile | 2 +- hw19/docker/php-fpm/php.ini | 0 23 files changed, 745 insertions(+), 6 deletions(-) create mode 100644 hw19/code/index.php create mode 100644 hw19/code/src/App.php create mode 100644 hw19/code/src/Configs/rabbitMQ.ini create mode 100644 hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php create mode 100644 hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php create mode 100644 hw19/code/src/Modules/OrderReport/Application/Response/GenerateReportResponse.php create mode 100644 hw19/code/src/Modules/OrderReport/Domain/Entity/OrderReportRequest.php create mode 100644 hw19/code/src/Modules/OrderReport/Domain/Repository/OrderReportRepositoryInterface.php create mode 100644 hw19/code/src/Modules/OrderReport/Domain/ValueObject/Email.php create mode 100644 hw19/code/src/Modules/OrderReport/Domain/ValueObject/Id.php create mode 100644 hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php create mode 100644 hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php create mode 100644 hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php create mode 100644 hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php create mode 100644 hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php create mode 100644 hw19/docker/nginx/Dockerfile create mode 100644 hw19/docker/nginx/hosts/app.loc.conf create mode 100644 hw19/docker/php-fpm/php.ini diff --git a/.gitignore b/.gitignore index 3b6a6abe3..cacf1b542 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /.idea hw19/code/vendor - +hw19/code/.idea diff --git a/hw19/code/composer.json b/hw19/code/composer.json index 09e7a9882..611e100ed 100644 --- a/hw19/code/composer.json +++ b/hw19/code/composer.json @@ -6,5 +6,8 @@ "Gkarman\\Rabbitmq\\": "src/" } }, - "require": {} + "require": { + "ext-mbstring": "*", + "php-amqplib/php-amqplib": "^3.2" + } } diff --git a/hw19/code/composer.lock b/hw19/code/composer.lock index ae571edf6..b45c1a1ac 100644 --- a/hw19/code/composer.lock +++ b/hw19/code/composer.lock @@ -4,15 +4,326 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7cc6b26b3b75d5355b11d3180552fcf6", - "packages": [], + "content-hash": "68fd5e09e1694c52206970465a780e41", + "packages": [ + { + "name": "paragonie/constant_time_encoding", + "version": "v2.6.3", + "source": { + "type": "git", + "url": "https://github.com/paragonie/constant_time_encoding.git", + "reference": "58c3f47f650c94ec05a151692652a868995d2938" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938", + "reference": "58c3f47f650c94ec05a151692652a868995d2938", + "shasum": "" + }, + "require": { + "php": "^7|^8" + }, + "require-dev": { + "phpunit/phpunit": "^6|^7|^8|^9", + "vimeo/psalm": "^1|^2|^3|^4" + }, + "type": "library", + "autoload": { + "psr-4": { + "ParagonIE\\ConstantTime\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com", + "role": "Maintainer" + }, + { + "name": "Steve 'Sc00bz' Thomas", + "email": "steve@tobtu.com", + "homepage": "https://www.tobtu.com", + "role": "Original Developer" + } + ], + "description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)", + "keywords": [ + "base16", + "base32", + "base32_decode", + "base32_encode", + "base64", + "base64_decode", + "base64_encode", + "bin2hex", + "encoding", + "hex", + "hex2bin", + "rfc4648" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/constant_time_encoding/issues", + "source": "https://github.com/paragonie/constant_time_encoding" + }, + "time": "2022-06-14T06:56:20+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v9.99.100", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", + "shasum": "" + }, + "require": { + "php": ">= 7" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*", + "vimeo/psalm": "^1" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/random_compat/issues", + "source": "https://github.com/paragonie/random_compat" + }, + "time": "2020-10-15T08:29:30+00:00" + }, + { + "name": "php-amqplib/php-amqplib", + "version": "v3.6.1", + "source": { + "type": "git", + "url": "https://github.com/php-amqplib/php-amqplib.git", + "reference": "76eee289e98b0b309a761787e65cbe1acbaf8c72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/76eee289e98b0b309a761787e65cbe1acbaf8c72", + "reference": "76eee289e98b0b309a761787e65cbe1acbaf8c72", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "ext-sockets": "*", + "php": "^7.2||^8.0", + "phpseclib/phpseclib": "^2.0|^3.0" + }, + "conflict": { + "php": "7.4.0 - 7.4.1" + }, + "replace": { + "videlalvaro/php-amqplib": "self.version" + }, + "require-dev": { + "ext-curl": "*", + "nategood/httpful": "^0.2.20", + "phpunit/phpunit": "^7.5|^9.5", + "squizlabs/php_codesniffer": "^3.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpAmqpLib\\": "PhpAmqpLib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-or-later" + ], + "authors": [ + { + "name": "Alvaro Videla", + "role": "Original Maintainer" + }, + { + "name": "Raúl Araya", + "email": "nubeiro@gmail.com", + "role": "Maintainer" + }, + { + "name": "Luke Bakken", + "email": "luke@bakken.io", + "role": "Maintainer" + }, + { + "name": "Ramūnas Dronga", + "email": "github@ramuno.lt", + "role": "Maintainer" + } + ], + "description": "Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.", + "homepage": "https://github.com/php-amqplib/php-amqplib/", + "keywords": [ + "message", + "queue", + "rabbitmq" + ], + "support": { + "issues": "https://github.com/php-amqplib/php-amqplib/issues", + "source": "https://github.com/php-amqplib/php-amqplib/tree/v3.6.1" + }, + "time": "2024-02-07T17:21:26+00:00" + }, + { + "name": "phpseclib/phpseclib", + "version": "3.0.37", + "source": { + "type": "git", + "url": "https://github.com/phpseclib/phpseclib.git", + "reference": "cfa2013d0f68c062055180dd4328cc8b9d1f30b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/cfa2013d0f68c062055180dd4328cc8b9d1f30b8", + "reference": "cfa2013d0f68c062055180dd4328cc8b9d1f30b8", + "shasum": "" + }, + "require": { + "paragonie/constant_time_encoding": "^1|^2", + "paragonie/random_compat": "^1.4|^2.0|^9.99.99", + "php": ">=5.6.1" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "ext-dom": "Install the DOM extension to load XML formatted public keys.", + "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", + "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", + "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", + "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations." + }, + "type": "library", + "autoload": { + "files": [ + "phpseclib/bootstrap.php" + ], + "psr-4": { + "phpseclib3\\": "phpseclib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jim Wigginton", + "email": "terrafrost@php.net", + "role": "Lead Developer" + }, + { + "name": "Patrick Monnerat", + "email": "pm@datasphere.ch", + "role": "Developer" + }, + { + "name": "Andreas Fischer", + "email": "bantu@phpbb.com", + "role": "Developer" + }, + { + "name": "Hans-Jürgen Petrich", + "email": "petrich@tronic-media.com", + "role": "Developer" + }, + { + "name": "Graham Campbell", + "email": "graham@alt-three.com", + "role": "Developer" + } + ], + "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.", + "homepage": "http://phpseclib.sourceforge.net", + "keywords": [ + "BigInteger", + "aes", + "asn.1", + "asn1", + "blowfish", + "crypto", + "cryptography", + "encryption", + "rsa", + "security", + "sftp", + "signature", + "signing", + "ssh", + "twofish", + "x.509", + "x509" + ], + "support": { + "issues": "https://github.com/phpseclib/phpseclib/issues", + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.37" + }, + "funding": [ + { + "url": "https://github.com/terrafrost", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpseclib", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib", + "type": "tidelift" + } + ], + "time": "2024-03-03T02:14:58+00:00" + } + ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-mbstring": "*" + }, "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/hw19/code/index.php b/hw19/code/index.php new file mode 100644 index 000000000..d1bc50b36 --- /dev/null +++ b/hw19/code/index.php @@ -0,0 +1,11 @@ +run(); diff --git a/hw19/code/src/App.php b/hw19/code/src/App.php new file mode 100644 index 000000000..382ed61d2 --- /dev/null +++ b/hw19/code/src/App.php @@ -0,0 +1,24 @@ +run($_POST); + } + + if (!empty($_SERVER['argv'])) { + + $command = new OrderReportCommand(); + return $command->run(); + } + } +} diff --git a/hw19/code/src/Configs/rabbitMQ.ini b/hw19/code/src/Configs/rabbitMQ.ini new file mode 100644 index 000000000..300e72c8c --- /dev/null +++ b/hw19/code/src/Configs/rabbitMQ.ini @@ -0,0 +1,5 @@ +host = 'rabbitmq' +port = 5672 +queue = 'otus' +user = 'user' +password = 'password' diff --git a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php new file mode 100644 index 000000000..39013e76d --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php @@ -0,0 +1,35 @@ +createDateFrom), + new ReportDateTo($request->createDateTo), + new Email($request->emailTo), + ); + $this->repository->save($orderReportRequest); + + return new GenerateReportResponse("Отчет будет отправлен на email {$request->emailTo}"); + } +} diff --git a/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php b/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php new file mode 100644 index 000000000..8b2e8caf5 --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php @@ -0,0 +1,24 @@ +userId; + } + + public function getDateFrom(): ReportDateFrom + { + return $this->dateFrom; + } + + public function getDateTo(): ReportDateTo + { + return $this->dateTo; + } + + public function getEmailTo(): Email + { + return $this->emailTo; + } +} diff --git a/hw19/code/src/Modules/OrderReport/Domain/Repository/OrderReportRepositoryInterface.php b/hw19/code/src/Modules/OrderReport/Domain/Repository/OrderReportRepositoryInterface.php new file mode 100644 index 000000000..1ec0c64ee --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Domain/Repository/OrderReportRepositoryInterface.php @@ -0,0 +1,11 @@ +assertValidValue($email); + $this->email = $email; + } + + public function getValue(): string + { + return $this->email; + } + + private function assertValidValue(string $email): void + { + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + throw new InvalidArgumentException('Поле email некорректно'); + } + } +} diff --git a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/Id.php b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/Id.php new file mode 100644 index 000000000..0938142e5 --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/Id.php @@ -0,0 +1,29 @@ +assertValidValue($id); + $this->id = $id; + } + + public function getValue(): int + { + return $this->id; + } + + private function assertValidValue(int $id): void + { + if ($id < 0) { + throw new InvalidArgumentException("Id не валидно"); + } + } +} diff --git a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php new file mode 100644 index 000000000..6d4b31fec --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php @@ -0,0 +1,36 @@ +assertValidValue($date); + $this->dateFrom = new \DateTime($date); + } + + public function getValue(): \DateTime + { + return $this->dateFrom; + } + + private function assertValidValue(string $date): void + { + $format = 'Y-m-d'; + $dateFrom = \DateTime::createFromFormat($format, $date); + + if (!$dateFrom || $dateFrom->format($format) !== $date) { + throw new InvalidArgumentException('Дата не валидна или не соответствует формату Y-m-d'); + } + + $earliestDate = new \DateTime('2020-01-01'); + if ($dateFrom < $earliestDate) { + throw new InvalidArgumentException('Дата должна быть более '. $earliestDate->format('Y-m-d')); + } + } +} diff --git a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php new file mode 100644 index 000000000..45af15581 --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php @@ -0,0 +1,36 @@ +assertValidValue($date); + $this->dateTo = new \DateTime($date); + } + + public function getValue(): \DateTime + { + return $this->dateTo; + } + + private function assertValidValue(string $date): void + { + $format = 'Y-m-d'; + $dateTo = \DateTime::createFromFormat($format, $date); + + if (!$dateTo || $dateTo->format($format) !== $date) { + throw new InvalidArgumentException('Дата не валидна или не соответствует формату Y-m-d'); + } + + $nowDate = new \DateTime(); + if ($dateTo > $nowDate) { + throw new InvalidArgumentException('Дата не должна быть более '. $nowDate->format('Y-m-d')); + } + } +} diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php new file mode 100644 index 000000000..7d16c455a --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php @@ -0,0 +1,29 @@ +channel(); + $channel->queue_declare($configs['queue'], false, false, false, false); + + $callback = function ($msg) { + echo ' [x] Received ', $msg->body, "\n"; + }; + + $channel->basic_consume($configs['queue'], '', false, true, false, false, $callback); + + try { + $channel->consume(); + } catch (\Throwable $exception) { + echo $exception->getMessage(); + } + } +} diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php new file mode 100644 index 000000000..559e655b9 --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php @@ -0,0 +1,25 @@ +run($generateOrderRequest); + } catch (\Exception $e) { + $response = new GenerateReportResponse($e->getMessage()); + } + + return $response->message; + } +} diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php b/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php new file mode 100644 index 000000000..0e21d45ff --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php @@ -0,0 +1,40 @@ +init(); + } + + public function save(OrderReportRequest $request): void + { + $msg = new AMQPMessage(serialize($request)); + $this->channel->basic_publish($msg, '', 'otus'); + $this->channel->close(); + $this->connection->close(); + } + + /** + * @throws \Exception + */ + private function init(): void + { + $configs = parse_ini_file('src/Configs/rabbitMQ.ini'); + $this->connection = new AMQPStreamConnection($configs['host'], $configs['port'], $configs['user'], $configs['password']); + $this->channel = $this->connection->channel(); + $this->channel->queue_declare($configs['queue'], false, false, false, false); + } +} diff --git a/hw19/docker/docker-compose.yaml b/hw19/docker/docker-compose.yaml index a449165b8..12536c78d 100644 --- a/hw19/docker/docker-compose.yaml +++ b/hw19/docker/docker-compose.yaml @@ -36,6 +36,8 @@ services: environment: RABBITMQ_DEFAULT_USER: user RABBITMQ_DEFAULT_PASS: password + networks: + - otus-network networks: otus-network: diff --git a/hw19/docker/nginx/Dockerfile b/hw19/docker/nginx/Dockerfile new file mode 100644 index 000000000..0f4fe9b1f --- /dev/null +++ b/hw19/docker/nginx/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:latest + +COPY ./hosts/app.loc.conf /etc/nginx/conf.d/app.loc.conf + +WORKDIR /data + +VOLUME /data + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/hw19/docker/nginx/hosts/app.loc.conf b/hw19/docker/nginx/hosts/app.loc.conf new file mode 100644 index 000000000..7f07750c6 --- /dev/null +++ b/hw19/docker/nginx/hosts/app.loc.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name app.loc; + root /var/www/app.loc; + index index.php index.html; + + location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ { + access_log off; + expires max; + } + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~* .php$ { + try_files $uri = 404; + fastcgi_split_path_info ^(.+.php)(/.+)$; + fastcgi_pass app:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} diff --git a/hw19/docker/php-fpm/Dockerfile b/hw19/docker/php-fpm/Dockerfile index e9567a1ac..6d5f29515 100644 --- a/hw19/docker/php-fpm/Dockerfile +++ b/hw19/docker/php-fpm/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y \ && docker-php-ext-enable redis \ && pecl install mcrypt \ && docker-php-ext-enable mcrypt \ - && docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \ + && docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip sockets \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install -j$(nproc) gd \ && pecl install memcached && \ diff --git a/hw19/docker/php-fpm/php.ini b/hw19/docker/php-fpm/php.ini new file mode 100644 index 000000000..e69de29bb From 9d0223445e2b2b8c9ed180af01727466939625d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Thu, 21 Mar 2024 09:48:28 +0300 Subject: [PATCH 04/15] GKarman/hw-19-rabbitMQ readme --- README.md | 86 ++++++++++++++----------------------------------------- 1 file changed, 21 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index bc954ee5f..36ca1bae7 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,30 @@ -## https://leetcode.com/problems/intersection-of-two-linked-lists/ -сложность O(m+n) +1. Скачать проект + ``` + git clone + ``` +2. Зайти в папку проекта и выполнить ``` -class Solution { - function getIntersectionNode($headA, $headB) { - $itemA = $headA; - $itemB = $headB; + cd hw19/docker + docker-compose up -d +``` + +3. Зайти внутрь php-fpm и запустить скрипт consumer - while ($itemA !== $itemB) { - $itemA = $itemA ? $itemA->next : $headB; - $itemB = $itemB ? $itemB->next : $headA; - } - return $itemA; - } -} +``` +docker exec otus-php-fpm bash +cd ../app.loc +php index.php ``` -## https://leetcode.com/problems/fraction-to-recurring-decimal/description/ +4. Посылаем post запрос наример через postman -сложность O(n) -``` -function fractionToDecimal($numerator, $denominator) { - if ($numerator == 0) { - return "0"; - } - - $result = ""; - - $numeratorSign = $numerator < 0 ? "-" : ""; - $denominatorSign = $denominator < 0 ? "-" : ""; - - if ($numeratorSign !== $denominatorSign) { - $result .= "-"; - } - - $numerator = abs($numerator); - $denominator = abs($denominator); - - $quotient = (int) ($numerator / $denominator); - $remainder = $numerator % $denominator; - - $result .= (string) $quotient; - - if ($remainder === 0) { - return $result; - } - - $result .= "."; - - $fractionalPart = ""; - $remainderPositions = []; - - while ($remainder !== 0) { - if (isset($remainderPositions[$remainder])) { - $index = $remainderPositions[$remainder]; - $fractionalPart = substr_replace($fractionalPart, "(", $index, 0); - $fractionalPart .= ")"; - break; - } - - $remainderPositions[$remainder] = strlen($fractionalPart); - $remainder *= 10; - $quotient = (int) ($remainder / $denominator); - $fractionalPart .= (string) $quotient; - $remainder %= $denominator; - } - - return $result . $fractionalPart; -} -``` + + +5. Заходим в терминал с php-fpm и видим там вывод нашего сообщения из очереди + + +``` ``` From 0a1c3c982a2d687bd515a59da2130c6f7b366cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Thu, 21 Mar 2024 09:52:36 +0300 Subject: [PATCH 05/15] GKarman/hw-19-rabbitMQ readme --- README.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 36ca1bae7..811a6793b 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,22 @@ php index.php ``` 4. Посылаем post запрос наример через postman +- на хост http://app.loc/ +- формат json поля + - email_to + - create_date_from + - create_date_to - - +пример запроса +``` +curl --location 'http://app.loc/' \ +--form 'email_to="test@mail.ru"' \ +--form 'create_date_from="2024-01-01"' \ +--form 'create_date_to="2024-01-30"' +``` 5. Заходим в терминал с php-fpm и видим там вывод нашего сообщения из очереди - -``` ``` +``` + [x] Received O:69:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\Entity\OrderReportRequest":4:{s:77:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\Entity\OrderReportRequestuserId";O:58:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\Id":1:{s:62:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\Idid";i:1;}s:79:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\Entity\OrderReportRequestdateFrom";O:70:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\ReportDateFrom":1:{s:80:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\ReportDateFromdateFrom";O:8:"DateTime":3:{s:4:"date";s:26:"2024-01-01 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}}s:77:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\Entity\OrderReportRequestdateTo";O:68:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\ReportDateTo":1:{s:76:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\ReportDateTodateTo";O:8:"DateTime":3:{s:4:"date";s:26:"2024-01-30 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}}s:78:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\Entity\OrderReportRequestemailTo";O:61:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\Email":1:{s:68:"Gkarman\Rabbitmq\Modules\OrderReport\Domain\ValueObject\Emailemail";s:12:"test@mail.ru";}} +``` From 498d9c4baa43d9774641458bf7173573ef5a0bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Thu, 21 Mar 2024 09:57:37 +0300 Subject: [PATCH 06/15] GKarman/hw-19-rabbitMQ readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 811a6793b..49c4519fe 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ 1. Скачать проект ``` - git clone + git clone git@github.com:otusteamedu/PHP_2023.git ``` 2. Зайти в папку проекта и выполнить ``` + git checkout GKarman/hw-19-rabbitMQ cd hw19/docker docker-compose up -d ``` From 2caa9a1fc5179c0bde31387e6acce8c7181571a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 23 Mar 2024 12:57:11 +0300 Subject: [PATCH 07/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +-- hw19/code/src/App.php | 2 +- .../src/Infrastructure/RabbitMQConfigs.php | 51 +++++++++++++++++++ .../Application/GenerateReportUseCase.php | 4 +- .../Request/GenerateOrderRequest.php | 1 + .../Response/GenerateReportResponse.php | 4 +- .../Domain/Entity/OrderReportRequest.php | 11 ++-- .../OrderReportRepositoryInterface.php | 1 + .../OrderReport/Domain/ValueObject/Email.php | 1 + .../OrderReport/Domain/ValueObject/Id.php | 1 + .../Domain/ValueObject/ReportDateFrom.php | 1 + .../Domain/ValueObject/ReportDateTo.php | 1 + .../Console/OrderReportCommand.php | 1 + .../Http/OrderReportController.php | 1 + .../Repository/RabbitMQQueueRepository.php | 22 +++++--- hw19/docker/docker-compose.yaml | 18 +++++++ 16 files changed, 104 insertions(+), 24 deletions(-) create mode 100644 hw19/code/src/Infrastructure/RabbitMQConfigs.php diff --git a/README.md b/README.md index 49c4519fe..70f73c9c4 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,7 @@ docker-compose up -d ``` -3. Зайти внутрь php-fpm и запустить скрипт consumer - -``` -docker exec otus-php-fpm bash -cd ../app.loc -php index.php -``` +3. consumer стартует автоматически в отдельном контейнере 4. Посылаем post запрос наример через postman - на хост http://app.loc/ diff --git a/hw19/code/src/App.php b/hw19/code/src/App.php index 382ed61d2..aac4a932c 100644 --- a/hw19/code/src/App.php +++ b/hw19/code/src/App.php @@ -1,4 +1,5 @@ run(); } diff --git a/hw19/code/src/Infrastructure/RabbitMQConfigs.php b/hw19/code/src/Infrastructure/RabbitMQConfigs.php new file mode 100644 index 000000000..4e9110dfd --- /dev/null +++ b/hw19/code/src/Infrastructure/RabbitMQConfigs.php @@ -0,0 +1,51 @@ +host = $configs['host'] ?? null; + $this->port = $configs['port'] ?? null; + $this->user = $configs['user'] ?? null; + $this->password = $configs['password'] ?? null; + $this->queue = $configs['queue'] ?? null; + } + + public function getHost(): ?string + { + return $this->host; + } + + public function getPort(): ?string + { + return $this->port; + } + + public function getUser(): ?string + { + return $this->user; + } + + public function getPassword(): ?string + { + return $this->password; + } + + public function getQueue(): ?string + { + return $this->queue; + } +} diff --git a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php index 39013e76d..e49a0cfe1 100644 --- a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php +++ b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php @@ -1,4 +1,5 @@ init(); + + public function __construct( + RabbitMqConfigs $rabbitMQConfigs, + ) { + $this->init($rabbitMQConfigs); } public function save(OrderReportRequest $request): void @@ -30,11 +34,15 @@ public function save(OrderReportRequest $request): void /** * @throws \Exception */ - private function init(): void + private function init(RabbitMqConfigs $rabbitMQConfigs): void { - $configs = parse_ini_file('src/Configs/rabbitMQ.ini'); - $this->connection = new AMQPStreamConnection($configs['host'], $configs['port'], $configs['user'], $configs['password']); + $this->connection = new AMQPStreamConnection( + $rabbitMQConfigs->getHost(), + $rabbitMQConfigs->getPort(), + $rabbitMQConfigs->getUser(), + $rabbitMQConfigs->getPassword() + ); $this->channel = $this->connection->channel(); - $this->channel->queue_declare($configs['queue'], false, false, false, false); + $this->channel->queue_declare($rabbitMQConfigs->getQueue(), false, false, false, false); } } diff --git a/hw19/docker/docker-compose.yaml b/hw19/docker/docker-compose.yaml index 12536c78d..8c9a3f0d8 100644 --- a/hw19/docker/docker-compose.yaml +++ b/hw19/docker/docker-compose.yaml @@ -12,6 +12,24 @@ services: networks: - otus-network + app2: + build: + context: ./php-fpm + dockerfile: Dockerfile + image: otus/php-fpm2 + container_name: otus-php-fpm2 + depends_on: + - rabbitmq + command: > + sh -c " + cd ../app.loc; + php index.php; + " + volumes: + - ../code:/var/www/app.loc + networks: + - otus-network + nginx: build: context: ./nginx From 4a9ec6e27f5e711387d5c0b661c580e3fd57fb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 14:36:01 +0300 Subject: [PATCH 08/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + hw19/code/src/App.php | 10 +++- .../Console/OrderReportCommand.php | 18 +++++-- .../Http/OrderReportController.php | 8 ++- .../RabbitLibs/RabbitAMQPLib.php | 49 +++++++++++++++++++ .../Repository/RabbitMQQueueRepository.php | 35 ++----------- 6 files changed, 82 insertions(+), 39 deletions(-) create mode 100644 hw19/code/src/Modules/OrderReport/Infastructure/RabbitLibs/RabbitAMQPLib.php diff --git a/.gitignore b/.gitignore index cacf1b542..a1f7d0bde 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.idea hw19/code/vendor hw19/code/.idea +hw20/ diff --git a/hw19/code/src/App.php b/hw19/code/src/App.php index aac4a932c..5c8842e5a 100644 --- a/hw19/code/src/App.php +++ b/hw19/code/src/App.php @@ -4,20 +4,26 @@ namespace Gkarman\Rabbitmq; +use Gkarman\Rabbitmq\Infrastructure\RabbitMQConfigs; +use Gkarman\Rabbitmq\Modules\OrderReport\Application\GenerateReportUseCase; use Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\Console\OrderReportCommand; use Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\Http\OrderReportController; +use Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\RabbitLibs\RabbitAMQPLib; +use Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\Repository\RabbitMQQueueRepository; class App { public function run() { if (!empty($_POST)) { - $controller = new OrderReportController(); + $controller = new OrderReportController( + new GenerateReportUseCase(new RabbitMQQueueRepository(new RabbitAMQPLib(new RabbitMQConfigs()))) + ); return $controller->run($_POST); } if (!empty($_SERVER['argv'])) { - $command = new OrderReportCommand(); + $command = new OrderReportCommand(new RabbitMQConfigs()); return $command->run(); } } diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php index 7b312dfea..aa7176fd9 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php @@ -4,22 +4,32 @@ namespace Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\Console; +use Gkarman\Rabbitmq\Infrastructure\RabbitMQConfigs; use PhpAmqpLib\Connection\AMQPStreamConnection; class OrderReportCommand { + public function __construct( + private readonly RabbitMQConfigs $configs + ) + {} + public function run() { - $configs = parse_ini_file('src/Configs/rabbitMQ.ini'); - $connection = new AMQPStreamConnection($configs['host'], $configs['port'], $configs['user'], $configs['password']); + $connection = new AMQPStreamConnection( + $this->configs->getHost(), + $this->configs->getPort(), + $this->configs->getUser(), + $this->configs->getPassword() + ); $channel = $connection->channel(); - $channel->queue_declare($configs['queue'], false, false, false, false); + $channel->queue_declare($this->configs->getQueue(), false, false, false, false); $callback = function ($msg) { echo ' [x] Received ', $msg->body, "\n"; }; - $channel->basic_consume($configs['queue'], '', false, true, false, false, $callback); + $channel->basic_consume($this->configs->getQueue(), '', false, true, false, false, $callback); try { $channel->consume(); diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php index de2e2ea09..6de482e28 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php @@ -11,12 +11,16 @@ class OrderReportController { + public function __construct( + private GenerateReportUseCase $useCase + ) + {} + public function run(array $request): string { try { $generateOrderRequest = GenerateOrderRequest::createFromArray($request); - $useCase = new GenerateReportUseCase(new RabbitMQQueueRepository()); - $response = $useCase->run($generateOrderRequest); + $response = $this->useCase->run($generateOrderRequest); } catch (\Exception $e) { $response = new GenerateReportResponse($e->getMessage()); } diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/RabbitLibs/RabbitAMQPLib.php b/hw19/code/src/Modules/OrderReport/Infastructure/RabbitLibs/RabbitAMQPLib.php new file mode 100644 index 000000000..d1249cf6a --- /dev/null +++ b/hw19/code/src/Modules/OrderReport/Infastructure/RabbitLibs/RabbitAMQPLib.php @@ -0,0 +1,49 @@ +configs = $configs; + $this->connection = $this->initConnection(); + $this->channel = $this->initChannel(); + } + + private function initConnection(): AMQPStreamConnection + { + $connection = new AMQPStreamConnection( + $this->configs->getHost(), + $this->configs->getPort(), + $this->configs->getUser(), + $this->configs->getPassword() + ); + + return $connection; + } + + private function initChannel(): AMQPChannel + { + $channel = $this->connection->channel(); + $channel->queue_declare($this->configs->getQueue(), false, false, false, false); + return $channel; + } + public function publish(string $message): void + { + $msg = new AMQPMessage($message); + $this->channel->basic_publish($msg, '', 'otus'); + $this->channel->close(); + $this->connection->close(); + } +} diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php b/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php index 7892b55d8..534bbfe30 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php @@ -4,45 +4,18 @@ namespace Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\Repository; -use Gkarman\Rabbitmq\Infrastructure\RabbitMQConfigs; use Gkarman\Rabbitmq\Modules\OrderReport\Domain\Entity\OrderReportRequest; use Gkarman\Rabbitmq\Modules\OrderReport\Domain\Repository\OrderReportRepositoryInterface; -use PhpAmqpLib\Channel\AMQPChannel; -use PhpAmqpLib\Connection\AMQPStreamConnection; -use PhpAmqpLib\Message\AMQPMessage; +use Gkarman\Rabbitmq\Modules\OrderReport\Infastructure\RabbitLibs\RabbitAMQPLib; class RabbitMQQueueRepository implements OrderReportRepositoryInterface { - private AMQPStreamConnection $connection; - - private AMQPChannel $channel; - public function __construct( - RabbitMqConfigs $rabbitMQConfigs, - ) { - $this->init($rabbitMQConfigs); - } + private RabbitAMQPLib $rabbitAMQPLib, + ) {} public function save(OrderReportRequest $request): void { - $msg = new AMQPMessage(serialize($request)); - $this->channel->basic_publish($msg, '', 'otus'); - $this->channel->close(); - $this->connection->close(); - } - - /** - * @throws \Exception - */ - private function init(RabbitMqConfigs $rabbitMQConfigs): void - { - $this->connection = new AMQPStreamConnection( - $rabbitMQConfigs->getHost(), - $rabbitMQConfigs->getPort(), - $rabbitMQConfigs->getUser(), - $rabbitMQConfigs->getPassword() - ); - $this->channel = $this->connection->channel(); - $this->channel->queue_declare($rabbitMQConfigs->getQueue(), false, false, false, false); + $this->rabbitAMQPLib->publish(serialize($request)); } } From e91838a89d48d6f8f665b1ff57b0a780eb052081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 14:43:22 +0300 Subject: [PATCH 09/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Infrastructure/RabbitMQConfigs.php | 32 +++++++++---------- .../Application/GenerateReportUseCase.php | 3 +- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/hw19/code/src/Infrastructure/RabbitMQConfigs.php b/hw19/code/src/Infrastructure/RabbitMQConfigs.php index 4e9110dfd..a932b4728 100644 --- a/hw19/code/src/Infrastructure/RabbitMQConfigs.php +++ b/hw19/code/src/Infrastructure/RabbitMQConfigs.php @@ -4,25 +4,23 @@ namespace Gkarman\Rabbitmq\Infrastructure; -use PhpAmqpLib\Connection\AMQPStreamConnection; - class RabbitMQConfigs { - private readonly ?string $host; - private readonly ?string $port; - private readonly ?string $user; - private readonly ?string $password; - private readonly ?string $queue; - - public function __construct() - { - $configs = parse_ini_file('src/Configs/rabbitMQ.ini'); - $this->host = $configs['host'] ?? null; - $this->port = $configs['port'] ?? null; - $this->user = $configs['user'] ?? null; - $this->password = $configs['password'] ?? null; - $this->queue = $configs['queue'] ?? null; - } + private readonly ?string $host; + private readonly ?string $port; + private readonly ?string $user; + private readonly ?string $password; + private readonly ?string $queue; + + public function __construct() + { + $configs = parse_ini_file('src/Configs/rabbitMQ.ini'); + $this->host = $configs['host'] ?? null; + $this->port = $configs['port'] ?? null; + $this->user = $configs['user'] ?? null; + $this->password = $configs['password'] ?? null; + $this->queue = $configs['queue'] ?? null; + } public function getHost(): ?string { diff --git a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php index e49a0cfe1..8d3597e04 100644 --- a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php +++ b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php @@ -17,8 +17,7 @@ class GenerateReportUseCase { public function __construct( private OrderReportRepositoryInterface $repository, - ) - {} + ) {} public function run(GenerateOrderRequest $request): GenerateReportResponse { From 559f4eb05c65972d72c7057f678f3fd9a4b450fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 14:46:11 +0300 Subject: [PATCH 10/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/OrderReport/Application/GenerateReportUseCase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php index 8d3597e04..e49a0cfe1 100644 --- a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php +++ b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php @@ -17,7 +17,8 @@ class GenerateReportUseCase { public function __construct( private OrderReportRepositoryInterface $repository, - ) {} + ) + {} public function run(GenerateOrderRequest $request): GenerateReportResponse { From 32cb2e8d283fc54ed01f87cb124bb3294c5abd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 14:57:24 +0300 Subject: [PATCH 11/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderReport/Application/GenerateReportUseCase.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php index e49a0cfe1..33df2e4c4 100644 --- a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php +++ b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php @@ -16,9 +16,8 @@ class GenerateReportUseCase { public function __construct( - private OrderReportRepositoryInterface $repository, - ) - {} + private OrderReportRepositoryInterface $repository + ) {} public function run(GenerateOrderRequest $request): GenerateReportResponse { From bc297b97658100dacae53e8d58d32d218927840e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 15:01:38 +0300 Subject: [PATCH 12/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/OrderReport/Application/GenerateReportUseCase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php index 33df2e4c4..da7046a9d 100644 --- a/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php +++ b/hw19/code/src/Modules/OrderReport/Application/GenerateReportUseCase.php @@ -17,7 +17,8 @@ class GenerateReportUseCase { public function __construct( private OrderReportRepositoryInterface $repository - ) {} + ) { + } public function run(GenerateOrderRequest $request): GenerateReportResponse { From af1b7cae36aa9b0e9f642b20a29149f216a119fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 15:09:53 +0300 Subject: [PATCH 13/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Application/Request/GenerateOrderRequest.php | 5 ++--- .../Application/Response/GenerateReportResponse.php | 4 ++-- .../OrderReport/Domain/Entity/OrderReportRequest.php | 3 +-- .../OrderReport/Domain/ValueObject/ReportDateFrom.php | 3 ++- .../OrderReport/Domain/ValueObject/ReportDateTo.php | 3 ++- .../Infastructure/Console/OrderReportCommand.php | 7 ++++--- .../Infastructure/Http/OrderReportController.php | 7 ++++--- .../Infastructure/Repository/RabbitMQQueueRepository.php | 3 ++- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php b/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php index 2dcb56696..7e62accdc 100644 --- a/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php +++ b/hw19/code/src/Modules/OrderReport/Application/Request/GenerateOrderRequest.php @@ -10,11 +10,10 @@ public function __construct( public string $emailTo, public string $createDateFrom, public string $createDateTo, - ) - { + ) { } - public static function createFromArray(array $data) :self + public static function createFromArray(array $data): self { return new self( $data['email_to'] ?? '', diff --git a/hw19/code/src/Modules/OrderReport/Application/Response/GenerateReportResponse.php b/hw19/code/src/Modules/OrderReport/Application/Response/GenerateReportResponse.php index fcfcc4437..eb59d4338 100644 --- a/hw19/code/src/Modules/OrderReport/Application/Response/GenerateReportResponse.php +++ b/hw19/code/src/Modules/OrderReport/Application/Response/GenerateReportResponse.php @@ -8,6 +8,6 @@ class GenerateReportResponse { public function __construct( public string $message - ) - {} + ) { + } } diff --git a/hw19/code/src/Modules/OrderReport/Domain/Entity/OrderReportRequest.php b/hw19/code/src/Modules/OrderReport/Domain/Entity/OrderReportRequest.php index 48566eee8..5cab330e2 100644 --- a/hw19/code/src/Modules/OrderReport/Domain/Entity/OrderReportRequest.php +++ b/hw19/code/src/Modules/OrderReport/Domain/Entity/OrderReportRequest.php @@ -16,8 +16,7 @@ public function __construct( private readonly ReportDateFrom $dateFrom, private readonly ReportDateTo $dateTo, private readonly Email $emailTo, - ) - { + ) { } public function getUserId(): Id diff --git a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php index ec6f8cf18..42a357f56 100644 --- a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php +++ b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateFrom.php @@ -9,6 +9,7 @@ class ReportDateFrom { private \DateTime $dateFrom; + public function __construct(string $date) { $this->assertValidValue($date); @@ -31,7 +32,7 @@ private function assertValidValue(string $date): void $earliestDate = new \DateTime('2020-01-01'); if ($dateFrom < $earliestDate) { - throw new InvalidArgumentException('Дата должна быть более '. $earliestDate->format('Y-m-d')); + throw new InvalidArgumentException('Дата должна быть более ' . $earliestDate->format('Y-m-d')); } } } diff --git a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php index ed1e0669f..e4f727b2e 100644 --- a/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php +++ b/hw19/code/src/Modules/OrderReport/Domain/ValueObject/ReportDateTo.php @@ -9,6 +9,7 @@ class ReportDateTo { private \DateTime $dateTo; + public function __construct(string $date) { $this->assertValidValue($date); @@ -31,7 +32,7 @@ private function assertValidValue(string $date): void $nowDate = new \DateTime(); if ($dateTo > $nowDate) { - throw new InvalidArgumentException('Дата не должна быть более '. $nowDate->format('Y-m-d')); + throw new InvalidArgumentException('Дата не должна быть более ' . $nowDate->format('Y-m-d')); } } } diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php index aa7176fd9..2e01182b2 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php @@ -11,8 +11,8 @@ class OrderReportCommand { public function __construct( private readonly RabbitMQConfigs $configs - ) - {} + ) { + } public function run() { @@ -33,7 +33,8 @@ public function run() try { $channel->consume(); - } catch (\Throwable $exception) { + } + catch (\Throwable $exception) { echo $exception->getMessage(); } } diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php index 6de482e28..f172e4c03 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php @@ -13,15 +13,16 @@ class OrderReportController { public function __construct( private GenerateReportUseCase $useCase - ) - {} + ) { + } public function run(array $request): string { try { $generateOrderRequest = GenerateOrderRequest::createFromArray($request); $response = $this->useCase->run($generateOrderRequest); - } catch (\Exception $e) { + } + catch (\Exception $e) { $response = new GenerateReportResponse($e->getMessage()); } diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php b/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php index 534bbfe30..44e546515 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Repository/RabbitMQQueueRepository.php @@ -12,7 +12,8 @@ class RabbitMQQueueRepository implements OrderReportRepositoryInterface { public function __construct( private RabbitAMQPLib $rabbitAMQPLib, - ) {} + ) { + } public function save(OrderReportRequest $request): void { From 8b7fd08abb5887799e1fcad901e288bb187ca9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 15:14:24 +0300 Subject: [PATCH 14/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderReport/Infastructure/Console/OrderReportCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php index 2e01182b2..f99278d4d 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Console/OrderReportCommand.php @@ -33,8 +33,7 @@ public function run() try { $channel->consume(); - } - catch (\Throwable $exception) { + } catch (\Throwable $exception) { echo $exception->getMessage(); } } From a3d999bc07353aa976ad96b9cd7eb026190d6c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=BC=D0=B0=D0=BD?= Date: Sat, 30 Mar 2024 15:15:32 +0300 Subject: [PATCH 15/15] =?UTF-8?q?GKarman/hw-19-rabbitMQ=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrderReport/Infastructure/Http/OrderReportController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php index f172e4c03..bef3200b0 100644 --- a/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php +++ b/hw19/code/src/Modules/OrderReport/Infastructure/Http/OrderReportController.php @@ -21,8 +21,7 @@ public function run(array $request): string try { $generateOrderRequest = GenerateOrderRequest::createFromArray($request); $response = $this->useCase->run($generateOrderRequest); - } - catch (\Exception $e) { + } catch (\Exception $e) { $response = new GenerateReportResponse($e->getMessage()); }