{"id":344943,"date":"2023-02-03T15:04:16","date_gmt":"2023-02-03T15:04:16","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=344943"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=344943","title":{"rendered":"<span>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0438\u0437 Symfony API \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Mercure<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-endpoint-api-with-php-and-symfony-part-3-8955325c5101\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 API \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u041a\u043e\u0433\u0434\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u043a \u0444\u043e\u043d\u043e\u0432\u0430\u044f, \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/symfony.com\/doc\/current\/messenger.html\"><u>symfony messenger<\/u><\/a>, \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u0432 \u043e\u0442\u0432\u0435\u0442 \u043a\u043e\u0434 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <em>HTTP 202 Accepted.<\/em><\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0432\u043d\u0435\u0441\u0443 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438. \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e, \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/mercure.rocks\/\"><u>mercure<\/u><\/a>, \u0442\u0430\u043a \u043a\u0430\u043a symfony \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0441 \u043d\u0438\u043c \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>\u042f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u0445. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0435\u0433\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445: <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-d5f03d3141c0\">\u0427\u0430\u0441\u0442\u044c 1<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-part-2-187604ffeb67\">\u0427\u0430\u0441\u0442\u044c 2<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-endpoint-api-with-php-and-symfony-part-3-8955325c5101\">\u0427\u0430\u0441\u0442\u044c 3<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-endpoint-api-with-php-and-symfony-part-4-9cfc0e2f9925\">\u0427\u0430\u0441\u0442\u044c 4<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-part-5-a8fcdcdc3471\">\u0427\u0430\u0441\u0442\u044c 5<\/a>.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 mercure<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 mercure \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e composer:<\/p>\n<pre><code>composer require mercure<\/code><\/pre>\n<p>Symfony \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0445\u0430\u0431\u0430 mercure \u0438\u0437 <a href=\"https:\/\/www.docker.com\/\"><u>docker<\/u><\/a>. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0444\u0430\u0439\u043b <em>docker-compose.yaml <\/em>\u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 mercure. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0445\u0430\u0431, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code>docker-compose up -d<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432\u0430\u0448\u0435\u0433\u043e <em>docker-compose<\/em> \u0444\u0430\u0439\u043b\u0430.<\/p>\n<h3>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043d\u0430\u0448 \u0445\u0430\u0431 mercure, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"php\">interface ApiOperationNotificationInterface {     public function getNotificationData(): string;     public function getTopic(): string; }<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><code>getNotificationData()<\/code>: \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 mercure.<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p><code>getTopic()<\/code>: \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043f\u0438\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/symfony.com\/doc\/current\/mercure.html\"><u>\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/u><\/a>, \u0442\u043e\u043f\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442\u0443 <em>\u0418\u043d\u0442\u0435\u0440\u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (IRL)<\/em>. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043f\u0438\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><em>https:\/\/&lt;mydomain>\/&lt;userIdenfier>\/&lt;subject> <\/em>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><code>mydomain<\/code>: \u0434\u043e\u043c\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><code>userIdentifier<\/code>: \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>subject<\/code>: \u043e \u043a\u0430\u043a\u043e\u043c \u0442\u0438\u043f\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u201c\u043f\u043b\u0430\u0442\u0435\u0436\u0438\u201d.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <code>userIdentifier<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u043e\u043f\u0438\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0441\u0432\u043e\u0438 \u0442\u043e\u043f\u0438\u043a\u0438.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u043e\u043d\u043e\u0432\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>APINotificationOperationInterface<\/code><em>:<\/em><\/p>\n<pre><code class=\"php\">#[IsBackground] class SendPaymentOperation implements ApiOperationInterface, ApiOperationNotificationInterface {      private SentPaymentNotification $notification;      public function perform(ApiInput $apiInput): ApiOutput     {                  \/\/ \u041a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043b\u0430\u0442\u0435\u0436\u0438                  $this->notification = new SentPaymentNotification('Your payment has been processed successfully', SentPaymentNotification::OK);         return new ApiOutput([], Response::HTTP_OK);     }      public function getName(): string     {         return 'SendPaymentOperation';     }      public function getInput(): string     {         return '';     }      public function getGroup(): ?string     {         return null;     }       public function getNotificationData(): string     {         return $this->notification;     }      public function getTopic(): string     {         return 'https:\/\/topics.domain.com\/%s\/payments';     } }<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>SentPaymentNotification<\/code><em> <\/em>\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<pre><code class=\"php\">class SentPaymentNotification {     const OK = 'OK';     const KO = 'KO';      public function __construct(         private readonly string $message,         private readonly string $status     ){ }      public function __toString(): string     {         return json_encode(['message' => $this->message, 'status' => $this->status]);     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, <code>SendPaymentNotification<\/code><em> <\/em>\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 json \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0432 \u043c\u0435\u0442\u043e\u0434 <code>__toString<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c.<\/p>\n<h3>\u0412\u043d\u0435\u0441\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u043e\u043f\u0438\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 <code>userIdentifier<\/code>, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e <code>ApiOperationMessage<\/code><em>, <\/em>\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440:<\/p>\n<pre><code class=\"php\">class ApiOperationMessage {     public function __construct(         public readonly ApiInput $apiInput,         public readonly string $userUuid     ){ } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, <code>ApiOperationMessageHandler<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 uuid. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>ApiOperationHandler<\/code>, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b uuid \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <code>ApiOperationMessage<\/code> \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c:<\/p>\n<pre><code class=\"php\">class ApiOperationHandler {     private ApiOperationsCollection $apiOperationsCollection;      private Security $security;     private MessageBusInterface $bus;      public function __construct(ApiOperationsCollection $apiOperationsCollection, Security $security, MessageBusInterface $bus)     {         $this->apiOperationsCollection = $apiOperationsCollection;         $this->security = $security;         $this->bus = $bus;     }      \/**      * @throws \\ReflectionException      *\/     public function performOperation(ApiInput $apiInput): ApiOutput     {         \/\/ ....... \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434          $attribute = $this->getBackgroundAttr($operationHandler);         if($attribute){             $stamps = ($attribute->delay > 0) ? [new DelayStamp($attribute->delay * 1000)] : [];             $this->bus->dispatch(new ApiOperationMessage($apiInput, $this->security->getUser()->getUuid()), $stamps);             return new ApiOutput(                 ['status' => 'Queued'],                 Response::HTTP_ACCEPTED             );         }            return $operationHandler->perform($apiInput);     }      \/\/ ....... }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a <code>ApiOperationMessageHandler<\/code><em> <\/em>\u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f, \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442<em> <\/em><code>ApiOperationNotificationInterface<\/code><em>.<\/em><\/p>\n<pre><code class=\"php\">#[AsMessageHandler] class ApiOperationMessageHandler {     public function __construct(         private readonly ApiOperationsCollection $apiOperationsCollection,         private readonly LockHandler $lockHandler,         private readonly MessageBusInterface $bus,         private readonly AttributeHelper $attributeHelper,         private readonly HubInterface $hub     ){ }       \/**      * @throws \\RedisException      *\/     public function __invoke(ApiOperationMessage $message): void     {          \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434  .......          if($operation instanceof ApiOperationNotificationInterface){              $topic = sprintf($operation->getTopic(), Uuid::fromString($message->userUuid)->toBase32());              $this->hub->publish(                 new Update(                     $topic,                     $operation->getNotificationData()                 )             );         }     } }<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>__invoke<\/code>, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>ApiOperationNotificationInterface<\/code>.\u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u043c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043f\u0438\u043a \u0441 uuid \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 base32 \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0432 \u0445\u0430\u0431\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 <code>getNotificationData()<\/code>.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 uuids \u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b <a href=\"https:\/\/symfony.com\/doc\/current\/components\/uid.html\"><u>symfony uid component<\/u><\/a><u>.<\/u><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h3>\n<p>\u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0438\u0437 <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-part-2-187604ffeb67\"><u>\u0441\u0442\u0430\u0442\u044c\u0438<\/u><\/a><em>, <\/em>\u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>in memory users symfony<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0441\u043b\u0443\u0436\u0438\u043b\u043e \u043d\u0430\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0434\u0435\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>in_memory_users<\/code> \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439, \u043a\u0440\u043e\u043c\u0435 <code>identifier<\/code> \u0438 <code>roles<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e uuid. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c:<\/p>\n<pre><code class=\"php\">class UserProvider implements UserProviderInterface {      public function refreshUser(UserInterface $user)     {         \/\/ TODO: \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 refreshUser().     }      public function supportsClass(string $class)     {         return $class === User::class;     }      public function loadUserByIdentifier(string $identifier): UserInterface     {         $users = [             [                 'identifier' => \"fYDg7nMhlvxAtL7KfBnS\",                 'roles'      => [\"ROLE_USER\", \"ROLE_SUPERUSER\"],                 'uuid'       => 'c5b6206c-340c-41e6-abed-18ca2258c578'             ]         ];          $users = array_filter($users, fn($u) => $u['identifier'] === $identifier);         if(count($users) == 0){             throw new UserNotFoundException('User does not exists');         }          return new User(array_pop($users));     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0443 \u043d\u0430\u0441 \u0432 <code>in_memory_users<\/code><em>, <\/em>\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>array_filter<\/code> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u043d\u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f<em> <\/em><code>UserNotFoundHttpException<\/code>, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>User<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <code>User<\/code>:<\/p>\n<pre><code class=\"php\">class User implements UserInterface {      private string $uuid;     private array $roles;     private string $identifier;      public function __construct(array $userData)     {         $this->uuid = $userData['uuid'];         $this->roles = $userData['roles'];         $this->identifier = $userData['identifier'];     }       public function getRoles(): array     {         return $this->roles;     }      public function eraseCredentials()     {      }      public function getUserIdentifier(): string     {         return $this->identifier;     }      public function getUuid(): string     {         return $this->uuid;     }  }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 <code>User<\/code><em> <\/em>\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>UserInterface<\/code><em> <\/em>Symfony<em>. <\/em>\u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434<em> <\/em><code>loadUserByIdentifier<\/code> \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 <code>symfony security.yaml<\/code>:<\/p>\n<pre><code class=\"php\">providers:         custom_provider:             id: App\\Security\\Provider\\UserProvider     firewalls:         dev:             pattern: ^\/(_(profiler|wdt)|css|images|js)\/             security: false         api:             pattern: '^\/api\/v1\/operation'             provider: custom_provider             access_denied_handler: App\\Security\\AccessDeniedHandler             custom_authenticators:                 - App\\Security\\ApiTokenAuthenticator<\/code><\/pre>\n<h3>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 \u043d\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 twig-\u0448\u0430\u0431\u043b\u043e\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0448 \u0442\u043e\u043f\u0438\u043a \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"php\">&lt;script>     const eventSource = new EventSource(\"{{ mercure('https:\/\/topics.domain.com\/65PRG6RD0C87KAQV8RS8H5HHBR\/payments')|escape('js') }}\");     eventSource.onmessage = event => {         \/\/ \u0411\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442         console.log(JSON.parse(event.data));     } &lt;\/script><\/code><\/pre>\n<p>\u042d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/symfony.com\/doc\/current\/mercure.html\"><u>\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/u><\/a>. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u0441\u0434\u0435\u043b\u0430\u043b, \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u043e\u043f\u0438\u043a\u0430 IRI. \u0412 URL \u0442\u043e\u043f\u0438\u043a\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c uuid \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 <code>base32 (65PRG6RD0C87KAQV8RS8H5HHBR).<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 twig:<\/p>\n<pre><code class=\"php\">#[Route('\/admin\/topics', name: 'get_topics', methods: ['GET'])] public function getTopics(): Response {     return $this->render('topics.html.twig'); }<\/code><\/pre>\n<blockquote>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c twig-\u0448\u0430\u0431\u043b\u043e\u043d, \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 twig: composer2 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 symfony\/twig-bundle. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e symfony \u0438 twig <a href=\"https:\/\/symfony.com\/doc\/current\/templates.html\"><u>\u0437\u0434\u0435\u0441\u044c<\/u><\/a><\/p>\n<\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 API \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 <code>SendPaymentOperation<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/83f\/d97\/02a\/83fd9702a253274978f340ed5d67d92f.png\" width=\"875\" height=\"476\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/83f\/d97\/02a\/83fd9702a253274978f340ed5d67d92f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 <em>\/admin\/topics<\/em>, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1b5\/844\/758\/1b5844758170ff656bc38a8568c1d4d9.png\" width=\"677\" height=\"328\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1b5\/844\/758\/1b5844758170ff656bc38a8568c1d4d9.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0430\u0448\u0438 \u0442\u043e\u043f\u0438\u043a\u0438 \u0438 \u0432\u0438\u0434\u0435\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0445\u0430\u0431. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434-\u0447\u0430\u0441\u0442\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c.<\/p>\n<hr\/>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435 \u00ab\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e php 8.1 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e rector\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u0430 &#171;Symfony Framework&#187;. \u041d\u0430 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c rector \u043a \u043a\u043e\u0434\u0443 \u043d\u0430 php 8 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 8.1,<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u044e\u0430\u043d\u0441\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0441 myclabs\/php-enum \u043d\u0430 built-in enum,<\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u0441\u0443\u0434\u0438\u043c readonly-\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u0438\u0445 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 \u0442\u0435\u0441\u0442\u044b.<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/otus.pw\/So8e\/\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u043a.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/714616\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/714616\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-endpoint-api-with-php-and-symfony-part-3-8955325c5101\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0430\u0442\u0440\u0438\u0431\u0443\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 API \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u041a\u043e\u0433\u0434\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u043a \u0444\u043e\u043d\u043e\u0432\u0430\u044f, \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/symfony.com\/doc\/current\/messenger.html\"><u>symfony messenger<\/u><\/a>, \u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u0432 \u043e\u0442\u0432\u0435\u0442 \u043a\u043e\u0434 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <em>HTTP 202 Accepted.<\/em><\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0432\u043d\u0435\u0441\u0443 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438. \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e, \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/mercure.rocks\/\"><u>mercure<\/u><\/a>, \u0442\u0430\u043a \u043a\u0430\u043a symfony \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0441 \u043d\u0438\u043c \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>\u042f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u0445. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0435\u0433\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445: <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-d5f03d3141c0\">\u0427\u0430\u0441\u0442\u044c 1<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-part-2-187604ffeb67\">\u0427\u0430\u0441\u0442\u044c 2<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-endpoint-api-with-php-and-symfony-part-3-8955325c5101\">\u0427\u0430\u0441\u0442\u044c 3<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-endpoint-api-with-php-and-symfony-part-4-9cfc0e2f9925\">\u0427\u0430\u0441\u0442\u044c 4<\/a>, <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-part-5-a8fcdcdc3471\">\u0427\u0430\u0441\u0442\u044c 5<\/a>.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 mercure<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 mercure \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e composer:<\/p>\n<pre><code>composer require mercure<\/code><\/pre>\n<p>Symfony \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0445\u0430\u0431\u0430 mercure \u0438\u0437 <a href=\"https:\/\/www.docker.com\/\"><u>docker<\/u><\/a>. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0444\u0430\u0439\u043b <em>docker-compose.yaml <\/em>\u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 mercure. \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0445\u0430\u0431, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code>docker-compose up -d<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432\u0430\u0448\u0435\u0433\u043e <em>docker-compose<\/em> \u0444\u0430\u0439\u043b\u0430.<\/p>\n<h3>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043d\u0430\u0448 \u0445\u0430\u0431 mercure, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"php\">interface ApiOperationNotificationInterface {     public function getNotificationData(): string;     public function getTopic(): string; }<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p><code>getNotificationData()<\/code>: \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 mercure.<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p><code>getTopic()<\/code>: \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043f\u0438\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/symfony.com\/doc\/current\/mercure.html\"><u>\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/u><\/a>, \u0442\u043e\u043f\u0438\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442\u0443 <em>\u0418\u043d\u0442\u0435\u0440\u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0440\u0435\u0441\u0443\u0440\u0441\u0430 (IRL)<\/em>. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043f\u0438\u043a\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><em>https:\/\/&lt;mydomain>\/&lt;userIdenfier>\/&lt;subject> <\/em>\u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><code>mydomain<\/code>: \u0434\u043e\u043c\u0435\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><code>userIdentifier<\/code>: \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><code>subject<\/code>: \u043e \u043a\u0430\u043a\u043e\u043c \u0442\u0438\u043f\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u201c\u043f\u043b\u0430\u0442\u0435\u0436\u0438\u201d.<\/p>\n<\/li>\n<\/ul>\n<p>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <code>userIdentifier<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u043e\u043f\u0438\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0441\u0432\u043e\u0438 \u0442\u043e\u043f\u0438\u043a\u0438.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u043e\u043d\u043e\u0432\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>APINotificationOperationInterface<\/code><em>:<\/em><\/p>\n<pre><code class=\"php\">#[IsBackground] class SendPaymentOperation implements ApiOperationInterface, ApiOperationNotificationInterface {      private SentPaymentNotification $notification;      public function perform(ApiInput $apiInput): ApiOutput     {                  \/\/ \u041a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u043b\u0430\u0442\u0435\u0436\u0438                  $this->notification = new SentPaymentNotification('Your payment has been processed successfully', SentPaymentNotification::OK);         return new ApiOutput([], Response::HTTP_OK);     }      public function getName(): string     {         return 'SendPaymentOperation';     }      public function getInput(): string     {         return '';     }      public function getGroup(): ?string     {         return null;     }       public function getNotificationData(): string     {         return $this->notification;     }      public function getTopic(): string     {         return 'https:\/\/topics.domain.com\/%s\/payments';     } }<\/code><\/pre>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 <code>SentPaymentNotification<\/code><em> <\/em>\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<pre><code class=\"php\">class SentPaymentNotification {     const OK = 'OK';     const KO = 'KO';      public function __construct(         private readonly string $message,         private readonly string $status     ){ }      public function __toString(): string     {         return json_encode(['message' => $this->message, 'status' => $this->status]);     } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0438\u0434\u0435\u0442\u044c, <code>SendPaymentNotification<\/code><em> <\/em>\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 json \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0432 \u043c\u0435\u0442\u043e\u0434 <code>__toString<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c.<\/p>\n<h3>\u0412\u043d\u0435\u0441\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u043e\u043f\u0438\u043a\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 <code>userIdentifier<\/code>, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u0433\u043e <code>ApiOperationMessage<\/code><em>, <\/em>\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 \u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440:<\/p>\n<pre><code class=\"php\">class ApiOperationMessage {     public function __construct(         public readonly ApiInput $apiInput,         public readonly string $userUuid     ){ } }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, <code>ApiOperationMessageHandler<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 uuid. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>ApiOperationHandler<\/code>, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b uuid \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <code>ApiOperationMessage<\/code> \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c:<\/p>\n<pre><code class=\"php\">class ApiOperationHandler {     private ApiOperationsCollection $apiOperationsCollection;      private Security $security;     private MessageBusInterface $bus;      public function __construct(ApiOperationsCollection $apiOperationsCollection, Security $security, MessageBusInterface $bus)     {         $this->apiOperationsCollection = $apiOperationsCollection;         $this->security = $security;         $this->bus = $bus;     }      \/**      * @throws \\ReflectionException      *\/     public function performOperation(ApiInput $apiInput): ApiOutput     {         \/\/ ....... \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434          $attribute = $this->getBackgroundAttr($operationHandler);         if($attribute){             $stamps = ($attribute->delay > 0) ? [new DelayStamp($attribute->delay * 1000)] : [];             $this->bus->dispatch(new ApiOperationMessage($apiInput, $this->security->getUser()->getUuid()), $stamps);             return new ApiOutput(                 ['status' => 'Queued'],                 Response::HTTP_ACCEPTED             );         }            return $operationHandler->perform($apiInput);     }      \/\/ ....... }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a <code>ApiOperationMessageHandler<\/code><em> <\/em>\u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f, \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442<em> <\/em><code>ApiOperationNotificationInterface<\/code><em>.<\/em><\/p>\n<pre><code class=\"php\">#[AsMessageHandler] class ApiOperationMessageHandler {     public function __construct(         private readonly ApiOperationsCollection $apiOperationsCollection,         private readonly LockHandler $lockHandler,         private readonly MessageBusInterface $bus,         private readonly AttributeHelper $attributeHelper,         private readonly HubInterface $hub     ){ }       \/**      * @throws \\RedisException      *\/     public function __invoke(ApiOperationMessage $message): void     {          \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434  .......          if($operation instanceof ApiOperationNotificationInterface){              $topic = sprintf($operation->getTopic(), Uuid::fromString($message->userUuid)->toBase32());              $this->hub->publish(                 new Update(                     $topic,                     $operation->getNotificationData()                 )             );         }     } }<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>__invoke<\/code>, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>ApiOperationNotificationInterface<\/code>.\u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u043c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u043f\u0438\u043a \u0441 uuid \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435 base32 \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0432 \u0445\u0430\u0431\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 <code>getNotificationData()<\/code>.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 uuids \u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b <a href=\"https:\/\/symfony.com\/doc\/current\/components\/uid.html\"><u>symfony uid component<\/u><\/a><u>.<\/u><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h3>\n<p>\u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0438\u0437 <a href=\"https:\/\/medium.com\/@ict80\/creating-a-one-api-endpoint-with-php-and-symfony-part-2-187604ffeb67\"><u>\u0441\u0442\u0430\u0442\u044c\u0438<\/u><\/a><em>, <\/em>\u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>in memory users symfony<\/code>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0441\u043b\u0443\u0436\u0438\u043b\u043e \u043d\u0430\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0434\u0435\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>in_memory_users<\/code> \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u043b\u0435\u0439, \u043a\u0440\u043e\u043c\u0435 <code>identifier<\/code> \u0438 <code>roles<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e uuid. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c:<\/p>\n<pre><code class=\"php\">class UserProvider implements UserProviderInterface {      public function refreshUser(UserInterface $user)     {         \/\/ TODO: \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 refreshUser().     }      public function supportsClass(string $class)     {         return $class === User::class;     }      public function loadUserByIdentifier(string $identifier): UserInterface     {         $users = [             [                 'identifier' => \"fYDg7nMhlvxAtL7KfBnS\",                 'roles'      => [\"ROLE_USER\", \"ROLE_SUPERUSER\"],                 'uuid'       => 'c5b6206c-340c-41e6-abed-18ca2258c578'             ]         ];          $users = array_filter($users, fn($u) => $u['identifier'] === $identifier);         if(count($users) == 0){             throw new UserNotFoundException('User does not exists');         }          return new User(array_pop($users));     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u0438\u043c\u0435\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0443 \u043d\u0430\u0441 \u0432 <code>in_memory_users<\/code><em>, <\/em>\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>array_filter<\/code> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u043d\u0438 \u043e\u0434\u0438\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u043f\u0440\u043e\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f<em> <\/em><code>UserNotFoundHttpException<\/code>, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <code>User<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <code>User<\/code>:<\/p>\n<pre><code class=\"php\">class User implements UserInterface {      private string $uuid;     private array $roles;     private string $identifier;      public function __construct(array $userData)     {         $this->uuid = $userData['uuid'];         $this->roles = $userData['roles'];         $this->identifier = $userData['identifier'];     }       public function getRoles(): array     {         return $this->roles;     }      public function eraseCredentials()     {      }      public function getUserIdentifier(): string     {         return $this->identifier;     }      public function getUuid(): string     {         return $this->uuid;     }  }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 <code>User<\/code><em> <\/em>\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>UserInterface<\/code><em> <\/em>Symfony<em>. <\/em>\u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434<em> <\/em><code>loadUserByIdentifier<\/code> \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 <code>symfony security.yaml<\/code>:<\/p>\n<pre><code class=\"php\">providers:         custom_provider:             id: App\\Security\\Provider\\UserProvider     firewalls:         dev:             pattern: ^\/(_(profiler|wdt)|css|images|js)\/             security: false         api:             pattern: '^\/api\/v1\/operation'             provider: custom_provider             access_denied_handler: App\\Security\\AccessDeniedHandler             custom_authenticators:           <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-344943","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=344943"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344943\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}