digipolisgent/domainator9k-apptype-generic-bundle
Installation Add the bundle via Composer:
composer require district09/domainator9k-apptype-generic-bundle
Enable it in config/bundles.php (Symfony) or config/app.php (Laravel via Symfony bridge):
return [
// ...
District09\Domainator9kApptypeGenericBundle\District09Domainator9kApptypeGenericBundle::class => ['all' => true],
];
First Use Case: Defining a Generic App Type Create a custom command or service to register a new app type:
use District09\Domainator9kApptypeGenericBundle\Domainator9kApptypeGenericBundle;
use District09\Domainator9kApptypeGenericBundle\Domainator9kApptypeGenericEvents;
// In a service or command:
$bundle = new Domainator9kApptypeGenericBundle();
$bundle->registerAppType('my_custom_app', [
'name' => 'My Custom App',
'description' => 'A generic app type for custom use cases',
'icon' => 'fa-cog',
'configurable_fields' => [
'field1' => ['type' => 'text', 'label' => 'Field 1'],
'field2' => ['type' => 'select', 'label' => 'Field 2', 'options' => ['opt1', 'opt2']],
],
]);
Triggering Events Listen for app type events (e.g., creation, update) via Symfony's event dispatcher:
// In a service provider or event subscriber:
$dispatcher->addListener(Domainator9kApptypeGenericEvents::APP_TYPE_CREATED, function ($event) {
// Handle app type creation logic
});
Registration
Use the bundle’s Domainator9kApptypeGenericBundle to dynamically register app types at runtime (e.g., via a CLI command or admin panel).
$bundle->registerAppType('blog', [
'configurable_fields' => [
'title' => ['type' => 'text', 'required' => true],
'theme' => ['type' => 'select', 'options' => ['dark', 'light']],
],
]);
Configuration Storage
Store app type configurations in a database table (e.g., app_types) with JSON fields for configurable_fields. Example migration:
Schema::create('app_types', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
$table->json('config')->nullable();
$table->timestamps();
});
Integration with Laravel Controllers Fetch and validate app type configurations in controllers:
public function store(Request $request, $appTypeName)
{
$appType = $this->appTypeRepository->findByName($appTypeName);
$validated = $request->validate($this->buildValidationRules($appType->config));
// Process validated data...
}
private function buildValidationRules(array $config): array
{
$rules = [];
foreach ($config['configurable_fields'] ?? [] as $field => $options) {
$rules[$field] = $options['required'] ? 'required' : 'nullable';
if (isset($options['type']) && $options['type'] === 'email') {
$rules[$field] .= '|email';
}
}
return $rules;
}
Dynamic Form Generation Use Blade to render forms based on app type configurations:
@foreach($appType->config['configurable_fields'] ?? [] as $field => $options)
<div class="form-group">
<label for="{{ $field }}">{{ $options['label'] }}</label>
@if($options['type'] === 'select')
<select name="{{ $field }}" id="{{ $field }}" class="form-control">
@foreach($options['options'] ?? [] as $option)
<option value="{{ $option }}">{{ $option }}</option>
@endforeach
</select>
@elseif($options['type'] === 'text')
<input type="text" name="{{ $field }}" id="{{ $field }}" class="form-control">
@endif
</div>
@endforeach
Domainator9kApptypeGenericEvents to extend behavior (e.g., logging, notifications).configurable_fields for dynamic rules.Route::get('/app-types/{name}', [AppTypeController::class, 'show']);
public function show($name)
{
return new AppTypeResource($this->appTypeRepository->findByName($name));
}
Deprecated Bundle
Lack of Documentation
src/District09/Domainator9kApptypeGenericBundle) for undocumented features.php artisan dump-autoload and inspect the bundle’s Domainator9kApptypeGenericBundle class for methods like registerAppType().Event Dispatcher Assumption
EventDispatcherInterface. In Laravel, use the Symfony bridge:use Symfony\Component\EventDispatcher\EventDispatcher;
$dispatcher = new EventDispatcher();
Database Schema Ambiguity
app_types and related data.Schema::json() for configurable_fields to avoid serialization issues.$dispatcher->addListener(Domainator9kApptypeGenericEvents::APP_TYPE_CREATED, function ($event) {
\Log::debug('App type created:', ['event' => $event->getAppType()]);
});
configurable_fields structure early:
if (!isset($config['configurable_fields'][$field]['type'])) {
throw new \InvalidArgumentException("Field '$field' requires a 'type'.");
}
Custom App Type Logic
Override bundle behavior by extending its core classes (e.g., Domainator9kApptypeGenericEvents):
class CustomAppTypeEvents extends Domainator9kApptypeGenericEvents
{
const APP_TYPE_VALIDATED = 'app_type.validated';
}
Field Type Plugins
Add support for custom field types (e.g., date, checkbox) by extending the bundle’s field validation logic.
Laravel Service Provider Integration Bind the bundle’s services to Laravel’s container:
public function register()
{
$this->app->bind(
District09\Domainator9kApptypeGenericBundle\Domainator9kApptypeGenericBundle::class
);
}
$appType = Cache::remember("app_type.{$name}", now()->addHours(1), function () use ($name) {
return $this->appTypeRepository->findByName($name);
});
Schema::table('app_types', function (Blueprint $table) {
$table->json('config')->index();
});
How can I help you explore Laravel packages today?