Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add configuration and service provider

+191 -46
+174 -1
config/schema.php
··· 1 1 <?php 2 2 3 3 return [ 4 - // 4 + 5 + /* 6 + |-------------------------------------------------------------------------- 7 + | Schema Sources 8 + |-------------------------------------------------------------------------- 9 + | 10 + | Paths to local lexicon directories. Schemas are searched in the order 11 + | specified below. Use absolute paths or Laravel path helpers. 12 + | 13 + */ 14 + 15 + 'sources' => [ 16 + // Application-specific lexicons 17 + resource_path('lexicons'), 18 + 19 + // Bundled official lexicons (included with package) 20 + __DIR__.'/../resources/lexicons', 21 + ], 22 + 23 + /* 24 + |-------------------------------------------------------------------------- 25 + | Include Bundled Lexicons 26 + |-------------------------------------------------------------------------- 27 + | 28 + | Whether to include the official AT Protocol lexicons bundled with this 29 + | package. Disable if you want to manage lexicons manually. 30 + | 31 + */ 32 + 33 + 'include_bundled' => env('SCHEMA_INCLUDE_BUNDLED', true), 34 + 35 + /* 36 + |-------------------------------------------------------------------------- 37 + | Generation Settings 38 + |-------------------------------------------------------------------------- 39 + | 40 + | Configure how Data classes are generated from Lexicon schemas. 41 + | 42 + */ 43 + 44 + 'generation' => [ 45 + // Output directory for generated Data classes 46 + 'output_path' => env('SCHEMA_OUTPUT_PATH', app_path('Data')), 47 + 48 + // Base namespace for generated classes 49 + 'base_namespace' => env('SCHEMA_BASE_NAMESPACE', 'App\\Data'), 50 + 51 + // Use readonly properties (PHP 8.1+) 52 + 'readonly_properties' => env('SCHEMA_READONLY_PROPERTIES', true), 53 + 54 + // Generate fluent setters for immutable updates 55 + 'fluent_setters' => env('SCHEMA_FLUENT_SETTERS', true), 56 + 57 + // Generate comprehensive PHPDoc blocks 58 + 'generate_phpdoc' => env('SCHEMA_GENERATE_PHPDOC', true), 59 + ], 60 + 61 + /* 62 + |-------------------------------------------------------------------------- 63 + | Caching Configuration 64 + |-------------------------------------------------------------------------- 65 + | 66 + | Configure caching for parsed schemas and resolved lexicons. 67 + | TTL values are in seconds. 68 + | 69 + */ 70 + 71 + 'cache' => [ 72 + // Enable or disable schema caching 73 + 'enabled' => env('SCHEMA_CACHE_ENABLED', true), 74 + 75 + // Cache driver to use (inherits from config/cache.php if null) 76 + 'driver' => env('SCHEMA_CACHE_DRIVER', null), 77 + 78 + // Cache TTL for parsed schemas (1 hour) 79 + 'schema_ttl' => env('SCHEMA_CACHE_TTL', 3600), 80 + 81 + // Cache TTL for DNS resolution results (24 hours) 82 + 'dns_ttl' => env('SCHEMA_DNS_CACHE_TTL', 86400), 83 + 84 + // Cache key prefix 85 + 'prefix' => env('SCHEMA_CACHE_PREFIX', 'schema'), 86 + ], 87 + 88 + /* 89 + |-------------------------------------------------------------------------- 90 + | Validation Settings 91 + |-------------------------------------------------------------------------- 92 + | 93 + | Configure validation behavior for records against Lexicon schemas. 94 + | 95 + */ 96 + 97 + 'validation' => [ 98 + // Default validation mode: strict, optimistic, lenient 99 + 'mode' => env('SCHEMA_VALIDATION_MODE', 'strict'), 100 + 101 + // Validate on Data class construction 102 + 'validate_on_construct' => env('SCHEMA_VALIDATE_ON_CONSTRUCT', false), 103 + ], 104 + 105 + /* 106 + |-------------------------------------------------------------------------- 107 + | Blob Handling 108 + |-------------------------------------------------------------------------- 109 + | 110 + | Configure blob storage and handling for ATProto blob references. 111 + | 112 + */ 113 + 114 + 'blobs' => [ 115 + // Storage disk for blobs 116 + 'disk' => env('SCHEMA_BLOB_DISK', 'local'), 117 + 118 + // Lazy load blob content (don't download until accessed) 119 + 'lazy_load' => env('SCHEMA_BLOB_LAZY_LOAD', true), 120 + 121 + // Blob URL signing (for temporary access URLs) 122 + 'signed_urls' => env('SCHEMA_BLOB_SIGNED_URLS', true), 123 + 124 + // Signed URL expiration (in minutes) 125 + 'signed_url_expiration' => env('SCHEMA_BLOB_URL_EXPIRATION', 60), 126 + ], 127 + 128 + /* 129 + |-------------------------------------------------------------------------- 130 + | DNS-Based Lexicon Resolution 131 + |-------------------------------------------------------------------------- 132 + | 133 + | Configure DNS-based lexicon resolution for third-party schemas. 134 + | Requires socialdept/atp-beacon package for DID resolution. 135 + | 136 + */ 137 + 138 + 'dns_resolution' => [ 139 + // Enable DNS-based lexicon resolution 140 + 'enabled' => env('SCHEMA_DNS_RESOLUTION_ENABLED', true), 141 + 142 + // Use Beacon for DID resolution (requires socialdept/atp-beacon) 143 + 'use_beacon' => env('SCHEMA_USE_BEACON', true), 144 + 145 + // Fallback behavior when schema not found: fail, warn, allow 146 + 'fallback' => env('SCHEMA_DNS_FALLBACK', 'warn'), 147 + 148 + // DNS nameservers (null = system default) 149 + 'nameservers' => env('SCHEMA_DNS_NAMESERVERS', null), 150 + 151 + // DNS query timeout (seconds) 152 + 'timeout' => env('SCHEMA_DNS_TIMEOUT', 5), 153 + 154 + // Auto-generate Data classes for resolved schemas 155 + 'auto_generate' => env('SCHEMA_DNS_AUTO_GENERATE', false), 156 + ], 157 + 158 + /* 159 + |-------------------------------------------------------------------------- 160 + | HTTP Client Configuration 161 + |-------------------------------------------------------------------------- 162 + | 163 + | Configure HTTP client used for schema retrieval via XRPC. 164 + | 165 + */ 166 + 167 + 'http' => [ 168 + // Request timeout (seconds) 169 + 'timeout' => env('SCHEMA_HTTP_TIMEOUT', 10), 170 + 171 + // Connection timeout (seconds) 172 + 'connect_timeout' => env('SCHEMA_HTTP_CONNECT_TIMEOUT', 5), 173 + 174 + // User agent for HTTP requests 175 + 'user_agent' => env('SCHEMA_HTTP_USER_AGENT', 'SocialDept/Schema'), 176 + ], 177 + 5 178 ];
+17 -45
src/SchemaServiceProvider.php
··· 7 7 class SchemaServiceProvider extends ServiceProvider 8 8 { 9 9 /** 10 - * Perform post-registration booting of services. 11 - * 12 - * @return void 10 + * Register any package services. 13 11 */ 14 - public function boot(): void 12 + public function register(): void 15 13 { 16 - // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'social-dept'); 17 - // $this->loadViewsFrom(__DIR__.'/../resources/views', 'social-dept'); 18 - // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); 19 - // $this->loadRoutesFrom(__DIR__.'/routes.php'); 14 + $this->mergeConfigFrom(__DIR__.'/../config/schema.php', 'schema'); 20 15 21 - // Publishing is only necessary when using the CLI. 22 - if ($this->app->runningInConsole()) { 23 - $this->bootForConsole(); 24 - } 16 + // Singleton bindings will be added in subsequent commits as we create the implementations 25 17 } 26 18 27 19 /** 28 - * Register any package services. 29 - * 30 - * @return void 20 + * Bootstrap the application services. 31 21 */ 32 - public function register(): void 22 + public function boot(): void 33 23 { 34 - $this->mergeConfigFrom(__DIR__.'/../config/schema.php', 'schema'); 35 - 36 - // Register the service the package provides. 37 - $this->app->singleton('schema', function ($app) { 38 - return new Schema(); 39 - }); 24 + if ($this->app->runningInConsole()) { 25 + $this->bootForConsole(); 26 + } 40 27 } 41 28 42 29 /** 43 30 * Get the services provided by the provider. 44 31 * 45 - * @return array 32 + * @return array<string> 46 33 */ 47 - public function provides() 34 + public function provides(): array 48 35 { 49 36 return ['schema']; 50 37 } 51 38 52 39 /** 53 40 * Console-specific booting. 54 - * 55 - * @return void 56 41 */ 57 42 protected function bootForConsole(): void 58 43 { 59 - // Publishing the configuration file. 44 + // Publish config 60 45 $this->publishes([ 61 46 __DIR__.'/../config/schema.php' => config_path('schema.php'), 62 - ], 'schema.config'); 47 + ], 'schema-config'); 63 48 64 - // Publishing the views. 65 - /*$this->publishes([ 66 - __DIR__.'/../resources/views' => base_path('resources/views/vendor/social-dept'), 67 - ], 'schema.views');*/ 68 - 69 - // Publishing assets. 70 - /*$this->publishes([ 71 - __DIR__.'/../resources/assets' => public_path('vendor/social-dept'), 72 - ], 'schema.assets');*/ 73 - 74 - // Publishing the translation files. 75 - /*$this->publishes([ 76 - __DIR__.'/../resources/lang' => resource_path('lang/vendor/social-dept'), 77 - ], 'schema.lang');*/ 78 - 79 - // Registering package commands. 80 - // $this->commands([]); 49 + // Publish stubs (will be created in later commits) 50 + $this->publishes([ 51 + __DIR__.'/../stubs' => base_path('stubs/schema'), 52 + ], 'schema-stubs'); 81 53 } 82 54 }