Skip to content

Commit 53cb12a

Browse files
committed
Конвертор битриксового Response/Request в Symfony Response/Request.
1 parent 92d4d53 commit 53cb12a

14 files changed

+982
-7
lines changed

bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$_SERVER['DOCUMENT_ROOT'] = __DIR__. "/..";

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
"functions/container.php"
2424
]
2525
},
26-
"repositories": [
27-
28-
],
2926
"require": {
3027
"php": ">=7.3 | ~8",
3128
"symfony/dependency-injection": "^4.0 || ^5.0",
@@ -46,9 +43,17 @@
4643
"symfony/dotenv": "^4.0 || ^5.0",
4744
"symfony/expression-language": "4.0 || ^5.0",
4845
"twig/twig": "~1.0",
49-
"proklung/base-exception": "^1.0"
46+
"proklung/base-exception": "^1.0",
47+
"symfony/psr-http-message-bridge": "^2.1",
48+
"nyholm/psr7": "^1.4",
49+
"guzzlehttp/psr7": "^1.8"
5050
},
5151
"require-dev": {
52-
"proklung/phpunit-testing-tools": "^1.1"
52+
"proklung/bitrix-phpunit-testing-tools": "^1.1"
53+
},
54+
"extra": {
55+
"installer-paths": {
56+
"vendor/sheerockoff/bitrix-ci/files/bitrix/modules/{$name}/": ["type:bitrix-module"]
57+
}
5358
}
5459
}

phpunit.xml.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="../vendor/autoload.php" colors="true" executionOrder="random" resolveDependencies="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Tests">
10+
<directory>Tests/Cases</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
<server name='HTTP_HOST' value='localhost' />
15+
<server name='SERVER_NAME' value='localhost' />
16+
</php>
17+
</phpunit>

src/Services/AppRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class AppRequest
1212
{
1313
/**
14-
* @var Request $request Объект Request.
14+
* @var Request $request Объект PsrRequest.
1515
*/
1616
private $request;
1717

@@ -25,7 +25,7 @@ public function __construct()
2525
}
2626

2727
/**
28-
* Объект Request.
28+
* Объект PsrRequest.
2929
*
3030
* @return Request
3131
*/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Prokl\ServiceProvider\Services\PSR;
4+
5+
use Bitrix\Main\HttpRequest;
6+
use Prokl\ServiceProvider\Services\PSR\PSR7\ServerPsrRequest;
7+
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
8+
use Symfony\Component\HttpFoundation\Request;
9+
10+
/**
11+
* Class BitrixRequestConvertor
12+
* @package Prokl\ServiceProvider\Services\PSR
13+
*
14+
* @since 24.05.2021
15+
*/
16+
class BitrixRequestConvertor
17+
{
18+
/**
19+
* @var HttpRequest $bitrixRequest Битриксовый Request.
20+
*/
21+
private $bitrixRequest;
22+
23+
/**
24+
* @var ServerPsrRequest $psrRequest
25+
*/
26+
private $psrRequest;
27+
28+
/**
29+
* BitrixRequestConvertor constructor.
30+
*
31+
* @param HttpRequest $bitrixRequest Битриксовый Request.
32+
*/
33+
public function __construct(HttpRequest $bitrixRequest)
34+
{
35+
$this->bitrixRequest = $bitrixRequest;
36+
$this->psrRequest = new ServerPsrRequest($this->bitrixRequest);
37+
}
38+
39+
/**
40+
* Request.
41+
*
42+
* @return Request
43+
*/
44+
public function request() : Request
45+
{
46+
$httpFoundationFactory = new HttpFoundationFactory();
47+
48+
return $httpFoundationFactory->createRequest($this->psrRequest);
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Prokl\ServiceProvider\Services\PSR;
4+
5+
use Bitrix\Main\HttpResponse;
6+
use Prokl\ServiceProvider\Services\PSR\PSR7\PsrResponse;
7+
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
/**
11+
* Class BitrixResponseConvertor
12+
* @package Prokl\ServiceProvider\Services\PSR
13+
*
14+
* @since 24.05.2021
15+
*/
16+
class BitrixResponseConvertor
17+
{
18+
/**
19+
* @var HttpResponse $bitrixResponse Битриксовый Response.
20+
*/
21+
private $bitrixResponse;
22+
23+
/**
24+
* @var PsrResponse $psrResponse
25+
*/
26+
private $psrResponse;
27+
28+
/**
29+
* BitrixResponseConvertor constructor.
30+
*
31+
* @param HttpResponse $bitrixResponse Битриксовый Response.
32+
*/
33+
public function __construct(HttpResponse $bitrixResponse)
34+
{
35+
$this->bitrixResponse = $bitrixResponse;
36+
$this->psrResponse = new PsrResponse($this->bitrixResponse);
37+
}
38+
39+
/**
40+
* Response.
41+
*
42+
* @return Response
43+
*/
44+
public function response() : Response
45+
{
46+
$httpFoundationFactory = new HttpFoundationFactory();
47+
48+
return $httpFoundationFactory->createResponse($this->psrResponse);
49+
}
50+
}

0 commit comments

Comments
 (0)