Skip to content

Conversation

@Zaimwa9
Copy link
Contributor

@Zaimwa9 Zaimwa9 commented Oct 20, 2025

Contributes to #107.


Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

  • new utility getUserAgent to get version from composer as flagsmith-php-sdk/v4.5.1 or returns flagsmith-php-sdk/unknown
  • Added header in API and Analytics requests

How did you test this code?

  • Added tests

Use this dummy php server:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Flagsmith\Flagsmith;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Psr7\Response;

class LoggingClient implements ClientInterface
{
    public function sendRequest(RequestInterface $request): ResponseInterface
    {
        echo "\n=== HTTP REQUEST ===\n";
        echo "Method: " . $request->getMethod() . "\n";
        echo "URI: " . $request->getUri() . "\n";
        echo "\nHeaders:\n";
        foreach ($request->getHeaders() as $name => $values) {
            foreach ($values as $value) {
                echo "  {$name}: {$value}\n";
            }
        }
        return new Response(200, ['Content-Type' => 'application/json'], []);
    }
}


try {
    $flagsmith = (new Flagsmith('test-api-key'))
        ->withClient(new LoggingClient());

    echo "Getting environment flags...\n";
    $flags = $flagsmith->getEnvironmentFlags();
} catch (Exception $e) {
    echo "\n✗ Error: " . "\n";
}

This returns normally:

 Method: GET
URI: https://edge.api.flagsmith.com/api/v1/flags/

Headers:
  Host: edge.api.flagsmith.com
  Accept: application/json
  Content-Type: application/json
  X-Environment-Key: test-api-key
  User-Agent: flagsmith-php-sdk/v4.5.1

Or after removing the version in composer:

 Method: GET
URI: https://edge.api.flagsmith.com/api/v1/flags/

Headers:
  Host: edge.api.flagsmith.com
  Accept: application/json
  Content-Type: application/json
  X-Environment-Key: test-api-key
  User-Agent: flagsmith-php-sdk/unknown

@Zaimwa9 Zaimwa9 requested a review from a team as a code owner October 20, 2025 13:14
@Zaimwa9 Zaimwa9 requested review from emyller and removed request for a team October 20, 2025 13:14
@Zaimwa9 Zaimwa9 merged commit ae35794 into main Oct 21, 2025
4 checks passed
@Zaimwa9 Zaimwa9 deleted the feat/add-user-agent-header-to-requests branch October 21, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants