Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Domainator9K Apptype Symfony Bundle Laravel Package

digipolisgent/domainator9k-apptype-symfony-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer in your Symfony project:

    composer require district09/domainator9k-apptype-symfony-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        District09\Domainator9kApptypeBundle\Domainator9kApptypeBundle::class => ['all' => true],
    ];
    
  2. Configuration Publish the default config (if needed):

    php bin/console config:dump-reference District09\Domainator9kApptypeBundle
    

    Override defaults in config/packages/domainator9k_apptype.yaml:

    district09_domainator9k_apptype:
        app_types: ['web', 'api']  # Example: Define allowed app types
    
  3. First Use Case Use the AppTypeChecker service to validate app types in controllers:

    use District09\Domainator9kApptypeBundle\Service\AppTypeChecker;
    
    class MyController extends AbstractController
    {
        public function __construct(private AppTypeChecker $appTypeChecker) {}
    
        public function index()
        {
            $this->appTypeChecker->validate('web'); // Throws exception if invalid
            // Proceed with logic
        }
    }
    

Implementation Patterns

Core Workflows

  1. App Type Validation

    • Use AppTypeChecker in controllers/services to enforce allowed app types:
      $this->appTypeChecker->validate($request->get('app_type'));
      
    • Integrate with Symfony’s event system (e.g., kernel.request) to auto-validate:
      $event->setResponse($this->appTypeChecker->validate($event->getRequest()->attributes->get('app_type')));
      
  2. Dynamic Configuration

    • Override allowed app types per environment (e.g., dev vs. prod):
      # config/packages/dev/domainator9k_apptype.yaml
      district09_domainator9k_apptype:
          app_types: ['web', 'cli']  # Extend for development
      
  3. Dependency Injection

    • Bind custom logic to the AppTypeChecker interface:
      services:
          District09\Domainator9kApptypeBundle\Service\AppTypeChecker:
              arguments:
                  $allowedTypes: '%district09_domainator9k_apptype.app_types%'
                  $customValidator: '@app.custom_app_type_validator'
      
  4. API Gateway Integration

    • Use middleware to validate app types in API routes:
      $container->get('kernel')->addControllerMiddleware(
          new AppTypeMiddleware($container->get('district09_domainator9k_apptype.app_type_checker'))
      );
      

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Version

    • The bundle was last updated in 2018 and may not support Symfony 5.4+/6.x.
    • Workaround: Fork the repo and update dependencies (e.g., symfony/dependency-injection to ^5.0).
  2. No Built-in Exception Handling

    • The validate() method throws generic InvalidArgumentException. Override the service to customize:
      class CustomAppTypeChecker extends AppTypeChecker
      {
          protected function createException(string $type): \Exception
          {
              return new \RuntimeException("App type '$type' is not allowed.");
          }
      }
      
  3. Configuration Overrides

    • Ensure config/packages/domainator9k_apptype.yaml is loaded after the default config to avoid precedence issues.
  4. Circular Dependencies

    • Avoid injecting the bundle’s services into other bundles’ compilers/passess (Symfony’s autowiring may fail).

Debugging Tips

  • Check Loaded Config:
    php bin/console debug:config district09_domainator9k_apptype
    
  • Log Validation Failures:
    try {
        $this->appTypeChecker->validate($type);
    } catch (\Exception $e) {
        $this->logger->error('Invalid app type', ['type' => $type]);
        throw $e;
    }
    

Extension Points

  1. Custom Validators Extend AppTypeChecker to add logic (e.g., database-backed types):

    class DatabaseAppTypeChecker extends AppTypeChecker
    {
        public function __construct(private EntityManagerInterface $em) {}
    
        protected function getAllowedTypes(): array
        {
            return $this->em->getRepository(AppType::class)->findAll()->map(fn($t) => $t->getName())->toArray();
        }
    }
    
  2. Event Listeners Trigger events on validation (e.g., log app type changes):

    // src/EventListener/AppTypeListener.php
    class AppTypeListener implements EventSubscriberInterface
    {
        public static function getSubscribedEvents(): array
        {
            return [
                AppTypeValidatedEvent::class => 'onAppTypeValidated',
            ];
        }
    
        public function onAppTypeValidated(AppTypeValidatedEvent $event): void
        {
            $this->logger->info('App type validated', ['type' => $event->getType()]);
        }
    }
    
  3. Twig Integration Pass app types to templates:

    {% if app.request.attributes.get('_app_type') in app_types %}
        <div class="app-type-badge">{{ app.request.attributes.get('_app_type') }}</div>
    {% endif %}
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle