Skip to content

Commit

Permalink
Конвертор битриксового Response/Request в Symfony Response/Request.
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed May 24, 2021
1 parent 92d4d53 commit 53cb12a
Show file tree
Hide file tree
Showing 14 changed files with 982 additions and 7 deletions.
3 changes: 3 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$_SERVER['DOCUMENT_ROOT'] = __DIR__. "/..";
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"functions/container.php"
]
},
"repositories": [

],
"require": {
"php": ">=7.3 | ~8",
"symfony/dependency-injection": "^4.0 || ^5.0",
Expand All @@ -46,9 +43,17 @@
"symfony/dotenv": "^4.0 || ^5.0",
"symfony/expression-language": "4.0 || ^5.0",
"twig/twig": "~1.0",
"proklung/base-exception": "^1.0"
"proklung/base-exception": "^1.0",
"symfony/psr-http-message-bridge": "^2.1",
"nyholm/psr7": "^1.4",
"guzzlehttp/psr7": "^1.8"
},
"require-dev": {
"proklung/phpunit-testing-tools": "^1.1"
"proklung/bitrix-phpunit-testing-tools": "^1.1"
},
"extra": {
"installer-paths": {
"vendor/sheerockoff/bitrix-ci/files/bitrix/modules/{$name}/": ["type:bitrix-module"]
}
}
}
17 changes: 17 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<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">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory>Tests/Cases</directory>
</testsuite>
</testsuites>
<php>
<server name='HTTP_HOST' value='localhost' />
<server name='SERVER_NAME' value='localhost' />
</php>
</phpunit>
4 changes: 2 additions & 2 deletions src/Services/AppRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class AppRequest
{
/**
* @var Request $request Объект Request.
* @var Request $request Объект PsrRequest.
*/
private $request;

Expand All @@ -25,7 +25,7 @@ public function __construct()
}

/**
* Объект Request.
* Объект PsrRequest.
*
* @return Request
*/
Expand Down
50 changes: 50 additions & 0 deletions src/Services/PSR/BitrixRequestConvertor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Prokl\ServiceProvider\Services\PSR;

use Bitrix\Main\HttpRequest;
use Prokl\ServiceProvider\Services\PSR\PSR7\ServerPsrRequest;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Component\HttpFoundation\Request;

/**
* Class BitrixRequestConvertor
* @package Prokl\ServiceProvider\Services\PSR
*
* @since 24.05.2021
*/
class BitrixRequestConvertor
{
/**
* @var HttpRequest $bitrixRequest Битриксовый Request.
*/
private $bitrixRequest;

/**
* @var ServerPsrRequest $psrRequest
*/
private $psrRequest;

/**
* BitrixRequestConvertor constructor.
*
* @param HttpRequest $bitrixRequest Битриксовый Request.
*/
public function __construct(HttpRequest $bitrixRequest)
{
$this->bitrixRequest = $bitrixRequest;
$this->psrRequest = new ServerPsrRequest($this->bitrixRequest);
}

/**
* Request.
*
* @return Request
*/
public function request() : Request
{
$httpFoundationFactory = new HttpFoundationFactory();

return $httpFoundationFactory->createRequest($this->psrRequest);
}
}
50 changes: 50 additions & 0 deletions src/Services/PSR/BitrixResponseConvertor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Prokl\ServiceProvider\Services\PSR;

use Bitrix\Main\HttpResponse;
use Prokl\ServiceProvider\Services\PSR\PSR7\PsrResponse;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Component\HttpFoundation\Response;

/**
* Class BitrixResponseConvertor
* @package Prokl\ServiceProvider\Services\PSR
*
* @since 24.05.2021
*/
class BitrixResponseConvertor
{
/**
* @var HttpResponse $bitrixResponse Битриксовый Response.
*/
private $bitrixResponse;

/**
* @var PsrResponse $psrResponse
*/
private $psrResponse;

/**
* BitrixResponseConvertor constructor.
*
* @param HttpResponse $bitrixResponse Битриксовый Response.
*/
public function __construct(HttpResponse $bitrixResponse)
{
$this->bitrixResponse = $bitrixResponse;
$this->psrResponse = new PsrResponse($this->bitrixResponse);
}

/**
* Response.
*
* @return Response
*/
public function response() : Response
{
$httpFoundationFactory = new HttpFoundationFactory();

return $httpFoundationFactory->createResponse($this->psrResponse);
}
}
Loading

0 comments on commit 53cb12a

Please sign in to comment.