Skip to content

Commit

Permalink
Merge pull request #14 from tastphp/v1.4.1
Browse files Browse the repository at this point in the history
clean code && add Response compoment
  • Loading branch information
xujiajun committed Jul 19, 2017
2 parents d08e518 + ed0342d commit 9d2fe60
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Framework/Container/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Psr\Container\NotFoundExceptionInterface;

/**
* Class NotFoundException
* @package TastPHP\Framework\Container
*/
class NotFoundException extends \InvalidArgumentException implements NotFoundExceptionInterface
{

Expand Down
1 change: 0 additions & 1 deletion src/Framework/Listener/MiddlewareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace TastPHP\Framework\Listener;

use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Component\EventDispatcher\Event;
use TastPHP\Service\ServiceKernel;
use TastPHP\Framework\Event\AppEvent;
Expand Down
6 changes: 5 additions & 1 deletion src/Framework/Listener/ResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ public function onResponseAction(Event $event)
{
$response = $event->getResponse();

if ($response instanceof Response || $response instanceof RedirectResponse || $response instanceof JsonResponse) {
if ($response instanceof Response
|| $response instanceof RedirectResponse
|| $response instanceof JsonResponse
) {
$response->send();
}

if (is_string($response)) {
echo $response;
}

if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
}
Expand Down
7 changes: 4 additions & 3 deletions src/Framework/Request/RequestAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RequestAdapter
{
/**
* @param Request $symfonyRequest
* @return mixed
* @return psrRequest
*/
public static function convertPsr7Request(Request $symfonyRequest)
{
Expand All @@ -22,12 +22,13 @@ public static function convertPsr7Request(Request $symfonyRequest)

/**
* @param $psrRequest
* @return mixed
* @return SymfonyRequest
*/
public static function convertSymfonyRequest($psrRequest)
{
$app = \Kernel::getInstance();
$httpFoundationFactory = $app['httpFoundationFactory'];;
$httpFoundationFactory = $app['httpFoundationFactory'];

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

namespace TastPHP\Framework\Response;

use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

/**
* Class Response
* @package TastPHP\Framework\Request
*/
class Response extends SymfonyResponse
{

}
34 changes: 34 additions & 0 deletions src/Framework/Response/ResponseAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace TastPHP\Framework\Response;

/**
* Class ResponseAdapter
* @package TastPHP\Framework\Response
*/
class ResponseAdapter
{
/**
* @param Response $symfonyResponse
* @return psrResponse
*/
public static function convertPsr7Response(Response $symfonyResponse)
{
$app = \Kernel::getInstance();
$psr7Factory = $app['psr7Factory'];

return $psr7Factory->createResponse($symfonyResponse);
}

/**
* @param $psrResponse
* @return SymfonyResponse
*/
public static function convertSymfonyResponse($psrResponse)
{
$app = \Kernel::getInstance();
$httpFoundationFactory = $app['httpFoundationFactory'];

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

0 comments on commit 9d2fe60

Please sign in to comment.