Installation
composer require aeruz/app-registry
Add the service provider to config/app.php:
'providers' => [
Aeruz\AppRegistry\Providers\AppRegistryServiceProvider::class,
],
Publish Config & Migrations
php artisan vendor:publish --provider="Aeruz\AppRegistry\Providers\AppRegistryServiceProvider" --tag="config"
php artisan vendor:publish --provider="Aeruz\AppRegistry\Providers\AppRegistryServiceProvider" --tag="migrations"
Run migrations:
php artisan migrate
First Use Case: Registering an App
use Aeruz\AppRegistry\Contracts\AppRegistry;
use Aeruz\AppRegistry\Models\App;
$registry = app(AppRegistry::class);
$app = $registry->create([
'name' => 'My Awesome App',
'description' => 'Does amazing things',
'owner_id' => auth()->id(),
]);
Lifecycle Management
// Draft → Published (with validation)
$app->publish(); // Throws \Aeruz\AppRegistry\Exceptions\AppValidationException if invalid
// Published → Draft (soft delete)
$app->draft();
Locking Mechanism
// Acquire lock for exclusive operations (e.g., config updates)
$lock = $app->lock();
try {
// Critical section
$app->updateConfig(['key' => 'value']);
} finally {
$lock->release();
}
Access Control
// Check if current user can manage the app
if ($registry->canManage($app, auth()->user())) {
// Proceed with operations
}
AppPublished, AppDrafted, or AppLocked events for notifications/analytics.
Event::listen(AppPublished::class, function ($event) {
Log::info("App published: {$event->app->name}");
});
AppResource for consistent JSON responses.
return new AppResource($app);
AppPolicy for custom authorization logic.Locking Deadlocks
finally block to avoid orphaned locks.tryLock() for non-blocking attempts:
$lock = $app->tryLock(5); // Timeout after 5 seconds
Validation Overrides
App model and overriding rules():
protected function rules(): array
{
return array_merge(parent::rules(), [
'custom_field' => 'required|unique:apps',
]);
}
Migration Conflicts
apps table, run:
php artisan app-registry:migrate-extend
config/app-registry.php:
'debug' => [
'locks' => env('APP_REGISTRY_DEBUG_LOCKS', false),
],
AppRegistry::debugEvents(true) to log all events.App::created(function ($app) {
$app->customFields()->create(['key' => 'theme', 'value' => 'dark']);
});
Aeruz\AppRegistry\Contracts\WebhookHandler for external notifications:
class SlackWebhook implements WebhookHandler
{
public function handle(AppEvent $event): void
{
// Send Slack notification
}
}
Route::middleware(['throttle:10,1'])->group(function () {
// Rate-limited routes
});
How can I help you explore Laravel packages today?