Skip to content
Open
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
3 changes: 0 additions & 3 deletions .coveralls.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on: [ "pull_request" ]

jobs:
tests:
strategy:
matrix:
php-versions: [ '8.0', '8.1' ]
composer-options: [ '--prefer-lowest', '']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: pcov
env:
fail-fast: true
- name: "Remove composer.lock file"
run: rm composer.lock || true
- uses: php-actions/composer@v6
with:
command: update # use update to use --prefer-lowest parameter
php_version: ${{ matrix.php-versions }}
version: 2
dev: yes
args: --no-interaction --no-progress --prefer-dist ${{ matrix.composer-options }}
- name: "Run php -l on all bundle files"
run: find . -not -path "./vendor/*" -type f -name '*.php' -exec php -l {} \;
- uses: php-actions/phpstan@v3
with:
path: .
memory_limit: 1G
level: 0
php_version: ${{ matrix.php-versions }}
- name: "Run phpunit"
run: "XDEBUG_MODE=coverage php ./vendor/bin/phpunit --coverage-text"
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion Curl/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function __destruct() {
*/
public function execute() {
$value = curl_exec($this->handle);

$error_no = curl_errno($this->handle);

if (0 !== $error_no) {
Expand Down
32 changes: 17 additions & 15 deletions DataCollector/LazyJsonEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Date: 29/11/2016
* Time: 15:05
*/

namespace evaisse\SimpleHttpBundle\DataCollector;

use Symfony\Component\Serializer\Encoder\JsonEncoder;
Expand All @@ -14,11 +15,10 @@
*/
class LazyJsonEncoder extends JsonEncoder
{

/**
* @var string
*/
protected $encoding;
protected string $encoding;

/**
* LazyJsonEncoder constructor.
Expand All @@ -37,26 +37,30 @@ public function __construct($encoding = 'utf-8')
* @param mixed $data data to encode
* @return mixed data encoded
*/
public function utf8Encode($data)
public function utf8Encode(mixed $data): mixed
{
if (is_string($data)) {
return utf8_encode($data);
} else if ($data instanceof \ArrayObject) {
}

if ($data instanceof \ArrayObject) {
$data = $data->getArrayCopy();
} else if($data instanceof \Exception) {
} elseif ($data instanceof \Exception) {
return $data->__toString();
} else if (is_object($data)) {
}
if (is_object($data)) {
$ovs = get_object_vars($data);
$new = clone $data;
foreach ($ovs as $k => $v) {
foreach ($ovs as $k => $v) {
if ($new instanceof \ArrayObject) {
$new[$k] = $this->utf8Encode($new[$k]);
} else {
$new->$k = $this->utf8Encode($new->$k);
}
}
return $new;
} else if (!is_array($data)) {
}
if (!is_array($data)) {
return $data;
}

Expand All @@ -72,7 +76,7 @@ public function utf8Encode($data)
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = array())
public function encode(mixed $data, string $format, array $context = array()): string
{
try {
if ($this->encoding !== 'utf-8') {
Expand All @@ -82,7 +86,7 @@ public function encode($data, $format, array $context = array())
} catch (\Exception $e) {
$data = $this->utf8Encode($data); // safely try to force encoding
try {
return json_encode($data);
return json_encode($data, JSON_THROW_ON_ERROR);
} catch (\Exception $e) {
return "{}";
}
Expand All @@ -92,14 +96,12 @@ public function encode($data, $format, array $context = array())
/**
* {@inheritdoc}
*/
public function decode($data, $format, array $context = array())
public function decode(string $data, string $format, array $context = array()): mixed
{
try {
return $this->decodingImpl->decode($data, self::FORMAT, $context);
} catch (\Exception $e) {
return json_decode($data);
return json_decode($data, false, 512, JSON_THROW_ON_ERROR);
}
}


}
}
55 changes: 53 additions & 2 deletions DataCollector/ProfilerDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ class ProfilerDataCollector extends DataCollector implements EventSubscriberInte
*/
protected $stopwatch;

/**
* blackfire instance id
* @var string
*/
protected string $blackfireClientId;

/**
* Access key to blackfire instance
* @var string
*/
protected string $blackfireClientToken;

/**
* sample amount used by blackfire commande
* number of times that the curl will be executed
* @var int
*/
protected int $blackfireSamples;

/**
* @param bool $debug
*/
Expand Down Expand Up @@ -131,6 +150,7 @@ public function normalizeCalls()
'sfDebugLink' => false,
'trace' => array_slice($v['trace'], 3),
'curlCommand' => $this->buildCurlCommand($v['request']),
'blackfireCommand' => $this->buildBlackfireCommand($v['request']),
);

if (isset($v['response'])) {
Expand Down Expand Up @@ -283,6 +303,25 @@ public function buildCurlCommand(Request $request)
return str_replace("\n", " \\\n", $command);
}

/**
* @param Request $request
* @return string
*/
public function buildBlackfireCommand(Request $request)
{
$command = "blackfire \\\n";
if (!empty($this->blackfireClientId)) {
$command .= "--client-id=\"$this->blackfireClientId\" \\\n";
}
if (!empty($this->blackfireClientToken)) {
$command .= "--client-token=\"$this->blackfireClientToken\" \\\n";
}
$command .= "--samples $this->blackfireSamples \\\n";

$curl = $this->buildCurlCommand($request);
return $command . $curl;
}

public function fetchTransferInfos(array $call)
{
$call['stop'] = isset($call['stop']) ? $call['stop'] : 0;
Expand Down Expand Up @@ -465,7 +504,7 @@ public function hasClientErrors()
*/
public function getClientErrors()
{
return array_filter($this->getCalls(), function ($call) {
return array_filter($this->getCalls(), static function ($call) {
if ($call['response']
&& array_key_exists('statusCode', $call['response'])
&& $call['response']['statusCode'] < 500
Expand Down Expand Up @@ -500,7 +539,7 @@ public function hasServerErrors()
*/
public function getServerErrors()
{
return array_filter($this->getCalls(), function ($call) {
return array_filter($this->getCalls(), static function ($call) {
if (is_array($call['response']) && array_key_exists('statusCode', $call['response']) && $call['response']['statusCode'] >= 500) {
return true;
}
Expand Down Expand Up @@ -641,4 +680,16 @@ public function reset()
$this->errors = [];
$this->stopwatch->reset();
}

/**
* Set blackfire properties
* @param $config array of items that can be used to set blackfire config
* @return void
*/
public function setBlackfireConfig(array $config): void
{
$this->blackfireClientId = $config["client_id"] ?? "";
$this->blackfireClientToken = $config["client_token"] ?? "";
$this->blackfireSamples = $config["samples"] ?? 10;
}
}
34 changes: 34 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace evaisse\SimpleHttpBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{

public function getConfigTreeBuilder() : TreeBuilder
{
$treeBuilder = new TreeBuilder('simple_http');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->arrayNode('blackfire')
->children()
->scalarNode('client_id')
->defaultValue(null)
->end()
->scalarNode('client_token')
->defaultValue(null)
->end()
->scalarNode('samples')
->defaultValue(10)
->end()
->end()
->end()
->end();

return $treeBuilder;
}
}
8 changes: 8 additions & 0 deletions DependencyInjection/SimpleHttpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ class SimpleHttpExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

if (!empty($config['blackfire'])) {
$container->getDefinition('simple_http.profiler.data_collector')
->addMethodCall('setBlackfireConfig', [$config['blackfire']]);
}
}
}
1 change: 0 additions & 1 deletion Http/Exception/CurlTransportException.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class CurlTransportException extends TransportException
82 => 'CURLE_SSL_CRL_BADFILE',
83 => 'CURLE_SSL_ISSUER_ERROR',
84 => 'CURLE_FTP_PRET_FAILED',
84 => 'CURLE_FTP_PRET_FAILED',
85 => 'CURLE_RTSP_CSEQ_ERROR',
86 => 'CURLE_RTSP_SESSION_ERROR',
87 => 'CURLE_FTP_BAD_FILE_LIST',
Expand Down
Loading