PHP code example of socialweb / atproto-lexicon

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

    

socialweb / atproto-lexicon example snippets


use SocialWeb\Atproto\Lexicon\Nsid\Nsid;
use SocialWeb\Atproto\Lexicon\Parser\DefaultParserFactory;
use SocialWeb\Atproto\Lexicon\Parser\DefaultSchemaRepository;
use SocialWeb\Atproto\Lexicon\Parser\LexiconParser;

$schemas = '/path/to/bluesky-social/lexicons';

$schemaRepository = new DefaultSchemaRepository($schemas);
$parser = new LexiconParser(new DefaultParserFactory($schemaRepository));

$nsid = new Nsid('app.bsky.feed.post');
$schemaFile = $schemaRepository->findSchemaPathByNsid($nsid);
$schemaContents = file_get_contents((string) $schemaFile);

$document = $parser->parse((string) $schemaContents);

use SocialWeb\Atproto\Lexicon\Types\LexResolvable;

foreach ($document->defs as $defId => $def) {
    if ($def instanceof LexResolvable) {
        $resolved = $def->resolve();
    }
}