PHP code example of accordsync / server

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

    

accordsync / server example snippets



// accord.php
use Accord\Core\Schema;
use Accord\Server\{Access, AccordServer, Auth, ScopedRecord};

return AccordServer::define(
    schema: Schema::define([
        'dossier' => [
            'agent' => Schema::lww(),
            'visits' => Schema::counter(),
            'docs' => Schema::set(),
            'status' => Schema::conflict(),
        ],
    ]),
    // The scope keys of a record, from its current fields.
    scopes: ['dossier' => fn (ScopedRecord $r) => ScopedRecord::key('agent', $r->fields['agent'] ?? null)],
    // The scope keys a user may read and write, from their verified JWT claims.
    access: fn (array $claims) => new Access(read: ["agent:{$claims['sub']}"], write: ["agent:{$claims['sub']}"]),
    auth: Auth::jwks('https://auth.example.com/.well-known/jwks.json', issuer: 'https://auth.example.com/', audience: 'accord'),
);


// public/index.php
dServer, Database};
use Accord\Server\RateLimit\FileRateLimiter;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;

$factory = new Psr17Factory();
$handler = AccordServer::handler(
    by every PHP worker on this host.
    rateLimiter: new FileRateLimiter(sys_get_temp_dir() . '/accord-rate-limits.json'),
);

$response = $handler->handle((new ServerRequestCreator($factory, $factory, $factory, $factory))->fromGlobals());

http_response_code($response->getStatusCode());
foreach ($response->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header("$name: $value", false);
    }
}
echo $response->getBody();