References Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community github GitHub github Get Started arrow_up_right
Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community

Components

HTTP URI HTTP Body Decoder HTTP Static Provider PHP Globals Provider OS Info CPU Info Assembly Weak Types Getting Started Architecture Application Window WebView Deployment Components Framework Integrations Examples Community

PHP Globals Provider

The component provides the ability to manage global PHP variables and obtain their state depending on WebView requests:

  • $_SERVER
  • $_POST
  • $_GET
  • $_FILES
  • etc.

This component is not included by default in the boson-php/runtime and must be installed separately.

Installation

Via Composer:

composer require boson-php/globals-provider

Requirements:

  • PHP ^8.4

The $_SERVER Superglobals

The component provides several implementations of ServerGlobalsProviderInterface for managing PHP $_SERVER superglobals:

  • Boson\Component\GlobalsProvider\DefaultServerGlobalsProvider
  • Boson\Component\GlobalsProvider\StaticServerGlobalsProvider
  • Boson\Component\GlobalsProvider\CompoundServerGlobalsProvider
  • Boson\Component\GlobalsProvider\EmptyServerGlobalsProvider

Default Provider

The Boson\Component\GlobalsProvider\DefaultServerGlobalsProvider provides basic request-aware parameters:

use Boson\Component\GlobalsProvider\DefaultServerGlobalsProvider;
use Boson\Component\Http\Request;

$provider = new DefaultServerGlobalsProvider();

$globals = $provider->getServerGlobals(new Request(
    method: 'POST',
    url: 'https://example.com/path?query=value',
    headers: ['Host' => 'example.com']
));

//
// Expected output:
//
// array:9 [
//   "REQUEST_TIME_FLOAT" => 1749130915.4316
//   "REQUEST_TIME" => 1749130915
//   "REQUEST_METHOD" => "POST"
//   "QUERY_STRING" => "query=value"
//   "PATH_INFO" => "/path"
//   "REMOTE_ADDR" => "example.com"
//   "REMOTE_PORT" => 80
//   "REQUEST_URI" => "/path?query=value"
//   "HTTP_HOST" => "example.com"
// ]
//

This provider automatically sets request-dependent variables:

  • Request time parameters (REQUEST_TIME, REQUEST_TIME_FLOAT)
  • Request information (REQUEST_METHOD, REQUEST_URI, HTTP_HOST, etc.)
  • Request headers (converted to uppercase with HTTP_ prefix)

PSR-20 Clock

The DefaultServerGlobalsProvider supports custom time handling through PSR-20 Clock interface:

use Boson\Component\GlobalsProvider\DefaultServerGlobalsProvider;
use Psr\Clock\ClockInterface;

class CustomClock implements ClockInterface
{
    public function now(): \DateTimeImmutable
    {
        return new \DateTimeImmutable('2024-01-01 12:00:00');
    }
}

$provider = new DefaultServerGlobalsProvider(
    clock: new CustomClock(),
);

The PSR-20 Clock component is used to generate the REQUEST_TIME and REQUEST_TIME_FLOAT parameters.

[ 
    "REQUEST_TIME_FLOAT" => 1749130915.4316,
    "REQUEST_TIME" => 1749130915,
    // ...
]

This allows for consistent time-based testing and custom time handling in your application.

Static Provider

The Boson\Component\GlobalsProvider\StaticServerGlobalsProvider provides constant server parameters that are independent of the request:

use Boson\Component\GlobalsProvider\StaticServerGlobalsProvider;

// With default superglobal $_SERVER values
$provider = new StaticServerGlobalsProvider();

// Or with custom values
$provider = new StaticServerGlobalsProvider([
    'DOCUMENT_ROOT' => '/custom/root',
    'SERVER_NAME' => 'example.com',
    'SERVER_PORT' => '8080',
    'SERVER_SOFTWARE' => 'Custom Server'
]);

The provider ensures:

  • Valid document root (from SCRIPT_FILENAME or DOCUMENT_ROOT)
  • Default server name (SERVER_NAME)
  • Default server port (SERVER_PORT)
  • Default server software (SERVER_SOFTWARE)
  • etc...

Compound Provider

The Boson\Component\GlobalsProvider\CompoundServerGlobalsProvider combines multiple providers into a single one:

use Boson\Component\GlobalsProvider\CompoundServerGlobalsProvider;
use Boson\Component\GlobalsProvider\DefaultServerGlobalsProvider;
use Boson\Component\GlobalsProvider\StaticServerGlobalsProvider;

$providers = [
    // PHP default $_SERVER superglobals provider
    new StaticServerGlobalsProvider(),
    // Request-aware $_SERVER superglobals provider
    new DefaultServerGlobalsProvider(),
    // Custom superglobals provider
    new StaticServerGlobalsProvider([
        'SERVER_SOFTWARE' => 'Custom Server'
    ]),
];

$provider = new CompoundServerGlobalsProvider($providers);

The compound provider merges results from all providers in the order they are provided. Later providers can override values from earlier ones.

Empty Provider

The Boson\Component\GlobalsProvider\EmptyServerGlobalsProvider returns an empty array of server globals:

use Boson\Component\GlobalsProvider\EmptyServerGlobalsProvider;

$provider = new EmptyServerGlobalsProvider();
$globals = $provider->getServerGlobals($request); // Returns []

The $_POST Superglobals

The component does not currently provide functionality for obtaining PHP superglobal $_POST variables.

The $_GET Superglobals

The component does not currently provide functionality for obtaining PHP superglobal $_GET variables.

The $_FILES Superglobals

The component does not currently provide functionality for obtaining PHP superglobal $_FILES variables.

github discord telegram Get started Documentation Contribution Guide License Release Notes BOSON PHP © 2025. All Rights Reversed.