PHP code example of intermaterium / kickstart

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

    

intermaterium / kickstart example snippets


use Intermaterium\Kickstart\Locator\FileHandlerLocator;
use Intermaterium\Kickstart\Response\ErrorResponseBuilder;
use Intermaterium\Kickstart\RuntimeFactory;

lder);
$runtime = $runtimeFactory->create(getenv('AWS_LAMBDA_RUNTIME_API'));

try {
    // Retrieve the function being invoked by lambda
    $fileHandlerLocator = new FileHandlerLocator(getenv('LAMBDA_TASK_ROOT'));
    $lambdaHandler = $fileHandlerLocator->get(getenv('_HANDLER'));
} catch (\Exception $e) {
    // If we failed to get the handler send an initialisation error and kill the lambda
    $runtime->initialisationFailure('Failed to get lambda handler', $e);
    exit(1);
}

do {
    // Infinitely loop handling events from lambda until lambda kills the runtime
    $runtime->invoke($lambdaHandler);
} while(true);

use Intermaterium\Kickstart\Context\Context;

return function($event, Context $context): mixed {
    return 'Hello ' . ($event['queryStringParameters']['name'] ?? 'world');
};

use Intermaterium\Kickstart\Context\Context;

class Handler
{
    public function __invoke($event, Context $context): mixed
    {
        return 'Hello ' . ($event['queryStringParameters']['name'] ?? 'world');
    }
}

return new Handler();