PHP code example of spinningcatstudios / lingara-apps

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

    

spinningcatstudios / lingara-apps example snippets


use Lingara\Apps\App;
use Lingara\Apps\Card;
use Lingara\Apps\Generated\AppActionRequest;
use Lingara\Apps\Generated\AppRenderRequest;
use Lingara\Apps\Generated\AppSlotName;
use Lingara\Apps\Psr15Handler;
use Lingara\Apps\Reply;
use Nyholm\Psr7\Factory\Psr17Factory;

$app = new App(
    // The app's signing secret, lgr_whsec_…, from its settings. Pass a list of
    // two during a rotation. A malformed secret throws here, at startup.
    secret: (string) getenv('LINGARA_APP_SECRET'),
    render: function (AppRenderRequest $request) {
        $today = Card::create()
            ->heading("Today's five", 1)
            ->term('雨', reading: 'yǔ', gloss: 'rain', lang: 'zh')
            ->button('Done', 'done')
            ->build();
        return $request->getSlot() === AppSlotName::HOME_SIDE
            ? Reply::of($today)->tutorNote('The learner is reviewing weather words.')
            : $today;
    },
    actions: [
        'done' => fn(AppActionRequest $request) => Card::create()->text('Well done')->build(),
    ],
);

$factory = new Psr17Factory();
$handler = new Psr15Handler($app, $factory, $factory); // a PSR-15 RequestHandlerInterface

use Lingara\Apps\Generated\AppSlotName;
use Lingara\Apps\Manifest;

$json = Manifest::create()->defaultLocale('en')->name('Daily five')->description('Five words to review.')
    ->renderUrl('https://apps.example.com/lingara/render')->slots(AppSlotName::HOME_SIDE)
    ->context('languages', 'plan_summary')
    ->toJson(); // Throws ManifestException naming the rule an upload would refuse.

$request = (new Nyholm\Psr7Server\ServerRequestCreator($factory, $factory, $factory, $factory))->fromGlobals();
$response = $handler->handle($request);