Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions Controller/ReplayController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: sroussel
* Date: 03/02/2016
* Time: 16:30
*/

namespace evaisse\SimpleHttpBundle\Controller;

Expand All @@ -20,22 +14,11 @@
*/
class ReplayController extends AbstractController
{
/** @var Helper $serviceHelper */
protected $serviceHelper;

/**
* @param Helper $serviceHelper
*/
public function __construct(Helper $serviceHelper)
public function __construct(protected Helper $serviceHelper)
{
$this->serviceHelper = $serviceHelper;
}

/**
* @Route("/http-replay", name="simple_http.replay_request")
* @param Request $request
* @return Response
*/
#[Route('/http-replay', name: 'simple_http.replay_request')]
public function replayRequestAction(Request $request): Response
{
$request = json_decode($request->request->get('request'));
Expand Down
9 changes: 7 additions & 2 deletions DataCollector/ProfilerDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace evaisse\SimpleHttpBundle\DataCollector;

use evaisse\SimpleHttpBundle\Http\StatementEventMap;
use evaisse\SimpleHttpBundle\Serializer\RequestNormalizer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
Expand Down Expand Up @@ -280,7 +281,11 @@ public function fetchTransferInfos(array $call): array

public function fetchRequestInfos(Request $request): array
{
$normalizers = array(new RequestNormalizer(), new ObjectNormalizer());
$normalizers = array(new GetSetMethodNormalizer(defaultContext: [
AbstractNormalizer::IGNORED_ATTRIBUTES => [
'session',
]
]), new ObjectNormalizer());
$encoders = array(new JsonEncoder());
$serializer = new Serializer($normalizers, $encoders);

Expand Down
46 changes: 0 additions & 46 deletions Serializer/CustomGetSetNormalizer.php

This file was deleted.

21 changes: 0 additions & 21 deletions Serializer/RequestNormalizer.php

This file was deleted.

36 changes: 6 additions & 30 deletions Service/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,10 @@

class Helper
{
/** @var Kernel */
protected $httpKernel;

/** @var EventDispatcherInterface */
protected $eventDispatcher;

/**
* Helper constructor.
* @param Kernel $httpKernel
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(Kernel $httpKernel, EventDispatcherInterface $eventDispatcher)
public function __construct(protected Kernel $httpKernel, protected EventDispatcherInterface $eventDispatcher)
{
$this->httpKernel = $httpKernel;
$this->eventDispatcher = $eventDispatcher;
}

/**
*
* @return CookieJar
*/
public function getDefaultCookieJar(): SessionCookieJar|CookieJar
{
return $this->createCookieJar();
Expand All @@ -60,12 +43,10 @@ public function createCookieJar(?SessionInterface $session = null): SessionCooki
*/
public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null, ?Kernel $client = null): static
{
$httpClient = $client ? $client : $this->httpKernel;
$client = $client ?: $this->httpKernel;

/*
Fetch Cookie jar from session
*/
$cookieJar = $cookieJar ? $cookieJar : $this->getDefaultCookieJar();
/** Fetch Cookie jar from session */
$cookieJar = $cookieJar ?: $this->getDefaultCookieJar();

foreach ($servicesList as $service) {
$sessionCookies = $cookieJar->allValues($service->getRequest()->getUri());
Expand All @@ -74,13 +55,10 @@ public function execute(array $servicesList, ?SessionCookieJar $cookieJar = null
}
}

$httpClient->execute($servicesList);
$client->execute($servicesList);

/*
Persist cookies
*/
/** Persist cookies */
foreach ($servicesList as $service) {

if (!$service->getResponse()) {
continue;
}
Expand Down Expand Up @@ -246,6 +224,4 @@ public function DELETE($url, array $parameters = array()): mixed
{
return $this->fire('DELETE', $url, $parameters);
}


}
11 changes: 1 addition & 10 deletions Twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ public function __construct(protected LoaderInterface $loader)
{
}

/**
* @return string
*/
public function getName(): string
{
return 'simple_http_extension';
}


public function getFilters(): array
{
$safe = array('is_safe' => array('html'));
Expand All @@ -41,7 +37,6 @@ public function getFilters(): array
];
}


public function getFunctions(): array
{
$safe = array('is_safe' => array('html'));
Expand All @@ -60,11 +55,7 @@ public function numberFormat(int|float $number, int $decimals = 0): string
return number_format($number, $decimals, $locale['decimal_point'], $locale['thousands_sep']);
}

/**
* @param $ms
* @return string
*/
public function formatMilliseconds($ms): string
public function formatMilliseconds(float|int $ms): string
{
if ($ms >= 1) {
return $this->numberFormat($ms, 1) . ' s';
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"symfony/serializer": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/stopwatch": "^5.4 || ^6.0",
"symfony/routing": "^5.4 || ^6.0",
"symfony/config": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/security-http": "^5.4 || ^6.0",
Expand Down
Loading