PHP code example of tkotosz / fn-fdk-php

1. Go to this page and download the library: Download tkotosz/fn-fdk-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/ */

    

tkotosz / fn-fdk-php example snippets




= new Tkotosz\FnPhpFdk\Fdk();

$fdk->handle(function ($input) {
    $name = 'World';
    if (isset($input['name'])) {
        $name = $input['name'];
    }
    return ['message' => 'Hello ' . $name];
});



= new Tkotosz\FnPhpFdk\Fdk();

$fdk->handle(function ($input, $ctx) {
    $name = 'World';
    if (isset($input['name'])) {
        $name = $input['name'];
    }
    return ['message' => 'Hello ' . $name, 'callId' => $ctx->getCallId()];
});

$fdk->handle(function ($input) use ($fdk) {
    return ['message' => 'Hello ' . ($input ?: 'World')];
}, ['inputMode' => 'string']);

$fdk->handle(function ($input) use ($fdk) {
    return $fdk->rawResult('Hello '. ($input ?: 'World'));
}, ['inputMode' => 'string']);

$fdk->handle(function ($input, $context) use ($fdk) {
    return $context->getHeaders(); // this will return all request headers as json
}, ['inputMode' => 'string']);

$fdk->handle(function ($input, $context) {
    $context->setResponseStatus(201);
    $context->setResponseContentType('text/plain');
    $context->setResponseHeader('X-Awesomeness-level', 100);
    $context->addResponseHeader('X-Awesome-number', 1);
    $context->addResponseHeader('X-Awesome-number', 2);
    return 'Hello '. ($input ?: 'World');
}, ['inputMode' => 'string']);
sh
echo -n '{"name":"Tibor"}' | fn invoke fdkdemo phpfunc
sh
echo -n '{"name":"Tibor"}' | fn invoke fdkdemo phpfunc