PHP code example of gitsbt / waylume-sdk

1. Go to this page and download the library: Download gitsbt/waylume-sdk 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/ */

    

gitsbt / waylume-sdk example snippets




use Waylume\Sdk\License\LicenseProofSigner;

= json_decode(file_get_contents('php://input'), true) ?? [];
$requestedHostname = LicenseProofSigner::normalizeHostname((string) ($input['hostname'] ?? ''));

// Read this fixed value from your application's trusted configuration.
// Never derive it from the request body or the HTTP Host header.
$allowedHostname = 'app.example.com';
if ($requestedHostname === '' || $requestedHostname !== $allowedHostname) {
    http_response_code(403);
    echo json_encode(['error' => 'Hostname is not allowed.']);
    exit;
}

$signer = LicenseProofSigner::fromPrivateKey((string) getenv('WAYLUME_PRIVATE_KEY'));
echo $signer->sign($allowedHostname)->toJson();

use Waylume\Sdk\Flow\FlowRegistry;

$registry = new FlowRegistry();
$registry->register([
    'id' => 'upgrade-to-pro',
    'label' => 'Upgrade to Pro',
    'steps' => [
        [
            'id' => 'upgrade-btn',
            'summary' => 'Start the upgrade',
            'instruction' => 'Click Upgrade to Pro.',
            'target' => 'upgrade-btn',
            'actionType' => 'click',
            'waitFor' => 'navigation',
            'expectedUrlPattern' => '/',
        ],
    ],
]);

$registry->registerJson(file_get_contents(__DIR__ . '/waylume/upgrade-flow.json'));

use Waylume\Sdk\Rendering\WaylumeRenderer;

copy(
    WaylumeRenderer::runtimeAssetPath(),
    __DIR__ . '/public/vendor/waylume/loader.js'
);

use Waylume\Sdk\Rendering\WaylumeRenderer;
use Waylume\Sdk\Sdk\SdkMode;
use Waylume\Sdk\Sdk\WaylumeConfig;

$config = new WaylumeConfig(
    publicKeyId: getenv('WAYLUME_PUBLIC_KEY_ID') ?: null,
    mode: SdkMode::Auto,
    proofEndpoint: '/api/waylume-proof',
);

$renderer = new WaylumeRenderer(
    registry: $registry,
    config: $config,
    runtimeSrc: '/vendor/waylume/loader.js',
);

<?= $renderer->bootstrapScript() 

<?= $renderer->launcher(
    children: '<button aria-label="Open guides">?</button>',
    locale: 'en',
    floating: true,
    position: 'bottom-right',
) 

<?= $renderer->navigation(
    flowId: 'upgrade-to-pro',
    children: '<button>Start guide</button>',
    locale: 'en',
)