PHP code example of milpa / app-runtime

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

    

milpa / app-runtime example snippets


// Run after LivePlugin boots. These are the same registries used by GET and action POST.
$container->get(\Milpa\Live\Contracts\Component\ComponentRegistryInterface::class)
    ->register('task-item', new TaskItem($repository));
$container->get(\Milpa\Live\Rendering\ComponentRendererRegistry::class)
    ->registerFor('task-item', new TaskItemRenderer($container->get(
        \Milpa\Live\Contracts\Transport\StateTransferCodecInterface::class,
    )));

$container->registerService(TrialInputObserver::class, $hostObserver);

    return ['rooted' => ['<credential id>']];
   

    return ['bootstrap' => true, 'rooted' => []];   // config/identity.php, first run only
   

   'admin' => ['middleware' => [Milpa\AppRuntime\Web\PasskeyGateMiddleware::class]],
   

use Milpa\AppRuntime\Web\PasskeySessionMiddleware;
use Milpa\Auth\Contracts\CredentialVerifier;
use Milpa\Auth\Http\AuthenticateMiddleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

$container = $kernel->container();
$chain = [];
if ($container->has(CredentialVerifier::class)) {
    $chain[] = new AuthenticateMiddleware($container->get(CredentialVerifier::class));   // the Bearer decides first
}
if ($container->has(PasskeySessionMiddleware::class)) {
    $chain[] = $container->get(PasskeySessionMiddleware::class);                       // the cookie speaks when it said nothing
}
foreach (array_reverse($chain) as $middleware) {                                       // nest: first declared runs first
    $handler = new class ($middleware, $handler) implements RequestHandlerInterface {
        public function __construct(private readonly MiddlewareInterface $m, private readonly RequestHandlerInterface $next) {}
        public function handle(ServerRequestInterface $r): ResponseInterface { return $this->m->process($r, $this->next); }
    };
}
$response = $handler->handle($request);

use Milpa\AppRuntime\Agent\CandidateState;

$state = CandidateState::read($appRoot, $sessionStore->stream($sessionId), $workspaceId);