PHP code example of particle-academy / prism-workspace

1. Go to this page and download the library: Download particle-academy/prism-workspace 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/ */

    

particle-academy / prism-workspace example snippets


use Prism\Workspace\Facades\PrismWorkspace;

$workspace = PrismWorkspace::for($session);

$workspace->write('reports/q1.md', $content);
$workspace->read('reports/q1.md');
$workspace->list();                       // streamed, not materialised

use Prism\Workspace\Security\CorpusRunner;

$report = (new CorpusRunner)->against(PrismWorkspace::for($session));

if (! $report->passed()) {
    throw new RuntimeException($report->summary());
}

try {
    $workspace->write($pathFromTheModel, $content);
} catch (PathRefused $refused) {
    Log::warning('agent tried to leave its workspace', [
        'code' => $refused->refusal->value,   // path_traverses_outside_workspace
        'path' => $refused->path,
    ]);
}

// config/prism-workspace.php
'authorize' => true,

Gate::define('workspace.write', fn (?User $user, Workspace $workspace, ?string $path) => ...);
bash
php artisan vendor:publish --tag=prism-workspace-config