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

Interop Config Laravel Package

sandrokeil/interop-config

Framework-agnostic PHP library for configuration-driven factories. Validates config structure, merges defaults, enforces required options, reduces factory boilerplate, supports auto-discovery of factories, and can generate configuration files from factory classes.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The package (interop-config) remains a strong fit for Laravel’s ecosystem, particularly with PHP 8 support in v2.2.0, which aligns with Laravel 9+ and PHP 8.x/8.1/8.2. The addition of PHP 8 features (e.g., union types, named arguments) can enhance type safety and modernize the package’s integration with Laravel’s service container and dependency injection. The package’s factory-based validation and mandatory option enforcement continue to complement Laravel’s native config system by introducing runtime schema validation, reducing runtime errors in complex configurations (e.g., third-party APIs, microservices, or multi-tenant setups).

  • Separation of Concerns: The package’s focus on factory-based instantiation with validation remains aligned with Laravel’s ServiceProvider bootstrapping. PHP 8’s improvements (e.g., attributes, constructor property promotion) could further refine how factories are defined and resolved. For example:

    • Use PHP 8 attributes to annotate config schemas (e.g., @ConfigSchema).
    • Leverage constructor injection for cleaner factory definitions:
      class MyServiceFactory {
          public function __construct(
              private readonly ConfigValidatorInterface $validator,
          ) {}
      
          public function create(array $config): MyService {
              $this->validator->validate($config);
              return new MyService($config['api_key'], $config['timeout']);
          }
      }
      
    • This reduces boilerplate and improves maintainability.
  • Laravel-Specific Gaps: The package still bridges critical gaps in Laravel’s native config system, such as:

    • Lack of mandatory field validation (e.g., enforcing required fields in config/*.php).
    • No built-in factory-based instantiation for configs (e.g., resolving configs as objects with validation).
    • PHP 8’s union types could enable more expressive config schemas (e.g., string|int $timeout).

Integration Feasibility

  • Core Compatibility:

    • PHP 8 Support: Laravel 9+ fully supports PHP 8, eliminating version conflicts. The package’s PHP 8 features (e.g., union types, named arguments) can be leveraged for:
      • Stricter type hints in factories and validators.
      • Named arguments in factory methods for better readability.
    • PSR-11/PSR-4: Unchanged; the package remains compliant with Laravel’s standards.
    • Service Container: PHP 8’s constructor injection can simplify bindings:
      $this->app->bind(MyServiceFactory::class);
      $this->app->bind(MyService::class, fn($c) => $c->make(MyServiceFactory::class)->create($c['config']['services.my_service']));
      
  • Potential Friction Points:

    • Laravel’s Config Caching: Runtime validation may still conflict with config:cache. Mitigation:
      • Use PHP 8’s never return type in validators to enforce exhaustive validation:
        public function validate(array $config): never {
            if (!isset($config['required_field'])) {
                throw new ConfigException('Missing required field');
            }
            // ...
        }
        
      • Cache only validated configs (e.g., via a ConfigCache decorator).
    • Legacy Config Structures: Refactoring remains necessary, but PHP 8’s deprecation attributes (#[Deprecated]) can ease migration:
      #[Deprecated('Use interop-config instead', '2023-01-01')]
      function oldConfigHelper() { ... }
      
    • Performance Overhead: PHP 8’s JIT compilation may offset validation costs. Benchmark with:
      php -d opcache.jit_buffer_size=100M artisan config:benchmark
      
  • Technical Risk:

    Risk Area Severity Mitigation Strategy
    Schema Drift High Use PHP 8’s attributes to version schemas (e.g., @SchemaVersion("2.0")).
    Service Container Pollution Medium Scope bindings with PHP 8’s readonly properties and contextual binding (Laravel 10+).
    Validation Overhead Low Optimize with lazy validation (e.g., validate only when config changes).
    Dependency Bloat Low Package remains lightweight; PHP 8 reduces LOC via constructor promotion.
    Testing Complexity Medium Use PHP 8’s data provider attributes (#[DataProvider]) for validation tests.

Key Questions

  1. Use Case Clarity:
    • With PHP 8, should the package support configs as objects with immutability (e.g., readonly properties)?
    • Example:
      final readonly class MyServiceConfig {
          public function __construct(
              public string $apiKey,
              public int $timeout,
          ) {}
      }
      
  2. Validation Granularity:
    • Should PHP 8’s union types enable dynamic schema validation (e.g., array<string, int|string> $mapping)?
  3. Laravel Integration Depth:
    • Can the package integrate with Laravel’s new app:resolve (Laravel 10+) for contextual configs?
    • Example:
      $config = app()->resolve(ConfigurableInterface::class, ['key' => 'my_service']);
      
  4. Error Handling:
    • Should ConfigException leverage PHP 8’s exception interfaces (e.g., Throwable) for better error handling?
  5. Future-Proofing:
    • Will Laravel’s Pipelines or Contextual Binding (Laravel 10+) reduce reliance on this package?
    • Should the package add support for PHP 8.2’s array_key_first/array_key_last for config traversal?

Integration Approach

Stack Fit

  • Laravel Ecosystem Synergy:

    • PHP 8 Features:
      • Use constructor property promotion in factories:
        class MyServiceFactory {
            public function __construct(
                private ConfigValidatorInterface $validator,
            ) {}
        
            public function create(array $config): MyService {
                $this->validator->validate($config);
                return new MyService(...$config);
            }
        }
        
      • Leverage union types in validators:
        public function validate(array $config): void {
            if ($config['timeout'] is int) {
                // ...
            }
        }
        
      • Attributes for metadata: Annotate configs with @ConfigSchema:
        #[ConfigSchema([
            'api_key' => 'required|string',
            'timeout' => 'required|int',
        ])]
        class MyServiceConfig {}
        
    • Service Container: Bind factories with PHP 8’s readonly:
      $this->app->bind(MyService::class, fn($c) => $c->make(MyServiceFactory::class)->create($c['config']['services.my_service']));
      
  • Alternative Stacks:

    • Lumen: Limited PHP 8 support; focus on Laravel 9+.
    • Livewire/Inertia: Use PHP 8’s union types for client-side validation (e.g., string|int props).
    • Queues/Jobs: Validate configs during job dispatch with PHP 8’s finally clauses:
      try {
          $config = app(ConfigFactory::class)->create($rawConfig);
          ProcessJob::dispatch($config);
      } finally {
          // Cleanup
      }
      

Migration Path

  1. Phase 1: Pilot Module (PHP 8 Upgrade)
    • Upgrade the pilot module to PHP 8 and refactor factories to use:
      • Constructor property promotion.
      • Union types in validation logic.
    • Example:
      // Before (PHP 7.4)
      public function __construct(ConfigValidatorInterface $validator) {
          $this->validator = $validator;
      }
      
      // After (PHP 8)
      public function __construct(
          private ConfigValidatorInterface $validator,
      ) {}
      
  2. Phase 2: Core Integration (PHP 8 Features)
    • Replace config() calls with factory-resolved configs using PHP 8’s readonly:
      $this->app->bind(MyServiceConfig::class, fn($c) => new MyServiceConfig(
          $c['config']['services.my_service']['api_key'],
          $c['config']['services.my_service']['timeout'],
      ));
      
    • Use attributes for schema definitions:
      #[ConfigSchema(['timeout' => 'required|int'])]
      class MyServiceConfig {}
      
  3. Phase 3: Full Adoption (PHP 8 + Laravel 10+)
    • Migrate all
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor