PHP code example of silverstripe / silverstripe-search-client-php

1. Go to this page and download the library: Download silverstripe/silverstripe-search-client-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

silverstripe / silverstripe-search-client-php example snippets


$plugins = [
    new AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('https://9595b293cf40d7532796c4ca67a27b81-bifrost.silverstripe.io')),
    new AddPathPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('/api/v1')),
    new HeaderAppendPlugin([
        'Authorization' => 'Bearer ABC.123.456',
    ]),
];

// When no HTTP Client is provided, PSR-18 discovery will be used, and your plugins will be attached to the HTTP Client
return Client::create(httpClient: null, additionalPlugins: $plugins);

$httpClient = new GuzzleHttp\Client();
$plugins = [
    new AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('https://9595b293cf40d7532796c4ca67a27b81-bifrost.silverstripe.io')),
    new AddPathPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('/api/v1')),
    new HeaderAppendPlugin([
        'Authorization' => 'Bearer ABC.123.456',
    ]),
];

// Apply the plugins to the HTTP Client
$httpClient = new PluginClient($httpClient, $plugins);

// When an explicit HTTP Client is provided, it will be used
return Client::create($httpClient);