1. Go to this page and download the library: Download ottosmops/ocfl 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/ */
use Ottosmops\Ocfl\Storage\StorageRoot;
use Ottosmops\Ocfl\Storage\HashedNTupleStorageLayout;
$root = StorageRoot::create(
path: '/path/to/storage',
layout: new HashedNTupleStorageLayout(),
);
$root->createObject('urn:example:foo')
->newVersion()
->addContents('hello.txt', 'hi')
->commit();
// Later, in another process:
$root = StorageRoot::open('/path/to/storage');
$object = $root->getObject('urn:example:foo');
$ids = $root->listObjects();
$object->checkout('/tmp/snapshot-v1', 'v1');
// Materialises the logical state of v1 into /tmp/snapshot-v1, verifying
// every content digest during the copy.
use Ottosmops\Ocfl\Validation\ErrorCode;
$report = OcflObject::open('/path/to/object')->validate();
$report->isValid(); // bool — no errors
$report->hasWarnings(); // bool
$report->hasError(ErrorCode::E040); // bool
foreach ($report->errors() as $issue) {
echo "[{$issue->code->value}] {$issue->message}\n";
}
use Aws\S3\S3Client;
use League\Flysystem\Filesystem as LeagueFilesystem;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use Ottosmops\Ocfl\Filesystem\FlysystemFilesystem;
use Ottosmops\Ocfl\Storage\StorageRoot;
use Ottosmops\Ocfl\Storage\HashedNTupleStorageLayout;
$client = new S3Client([...]);
$league = new LeagueFilesystem(new AwsS3V3Adapter($client, 'my-bucket'));
$fs = new FlysystemFilesystem($league);
$root = StorageRoot::create('/archive', new HashedNTupleStorageLayout(), $fs);
$root->createObject('urn:example:foo')
->newVersion()
->addContents('doc.txt', 'content')
->withUser('Alice', 'mailto:[email protected]')
->commit();
// app/Providers/OcflServiceProvider.php
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem as LeagueFilesystem;
use Ottosmops\Ocfl\Filesystem\FlysystemFilesystem;
use Ottosmops\Ocfl\Filesystem\LocalFilesystem;
use Ottosmops\Ocfl\Storage\HashedNTupleStorageLayout;
use Ottosmops\Ocfl\Storage\StorageRoot;
final class OcflServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(StorageRoot::class, function () {
$disk = Storage::disk(config('ocfl.disk', 'local'));
// Laravel's Storage::disk() returns its own Filesystem wrapper;
// grab the underlying Flysystem operator and adapt it.
$fs = $disk->getDriver() instanceof LeagueFilesystem
? new FlysystemFilesystem($disk->getDriver())
: new LocalFilesystem();
return StorageRoot::open(
path: config('ocfl.root', storage_path('ocfl')),
fs: $fs,
);
});
}
}