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

Php Matcher Laravel Package

coduo/php-matcher

Flexible PHP pattern-matching library for testing and validating complex data structures. Compare arrays, JSON and objects against readable expectations, with rich mismatch descriptions to pinpoint differences. Useful for API response assertions and custom validation rules.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pattern Matching Use Case: The package remains ideal for structured data validation, transformation, or extraction in Laravel, with no changes to its core value proposition. The new release introduces PHP 8.5 support and Symfony 8.0 compatibility, reinforcing its alignment with modern Laravel ecosystems (Laravel 11+ leverages PHP 8.5+ and Symfony components). The declarative syntax (matcher()->match($data, $pattern)) continues to fit service-layer, command-bus, and API validation patterns.
  • Domain-Specific Fit:
    • API/HTTP Layer: Enhanced compatibility with Symfony 8.0 components (e.g., HttpFoundation) improves integration with Laravel’s HTTP stack (e.g., Illuminate\Http\Request).
    • Data Processing: PHP 8.5 features (e.g., enums, typed properties) may enable more expressive patterns for modern Laravel applications.
    • Testing: No changes to core functionality, but Symfony 8.0 compatibility could simplify testing with symfony/http-client.
  • Anti-Patterns:
    • PHP Version Constraint: Dropped support for PHP < 8.3 may require upgrades for legacy Laravel 8/9 projects (though Laravel 9+ already requires PHP 8.1+).
    • Performance: Still not suited for high-frequency trading or real-time systems (regex/PCRE remains faster for trivial cases).

Integration Feasibility

  • Laravel Ecosystem Synergy:
    • Symfony 8.0 Compatibility: Seamless integration with Laravel’s Symfony-based components (e.g., Illuminate/Foundation uses Symfony HttpKernel). Example:
      use Symfony\Component\HttpFoundation\Request;
      $matcher->match($request->toArray(), ['query' => ['page' => 'integer']]);
      
    • PHP 8.5 Features: Leverage typed patterns (e.g., ['id' => 'int']) or enums for stricter validation.
    • Service Providers: Register with Laravel’s container as before, but now with PHP 8.5’s array_unpack or fn() improvements for cleaner DI.
  • PHP Version Compatibility:
    • Breaking Change: Dropped PHP < 8.3 support requires Laravel 9+ (PHP 8.1+) or Laravel 10+ (PHP 8.2+) projects to adopt this version. For Laravel 8 (PHP 7.4), use 5.x branch.
    • New Features: PHP 8.5’s array_is_list or Stringable may enable richer pattern syntax (e.g., ['name' => 'string:min:3']).
  • Database Integration: Unchanged, but Symfony 8.0’s Doctrine components could improve Eloquent collection validation.

Technical Risk

Risk Area Mitigation Strategy Update for 6.0.18
Performance Overhead Benchmark against native PHP/PCRE; cache compiled patterns. PHP 8.5’s JIT may improve performance—re-test critical paths.
Pattern Complexity Document edge cases (e.g., recursive structures). Symfony 8.0’s Attribute system could enable annotated patterns (future-proofing).
Dependency Bloat Audit for transitive dependencies (e.g., symfony/yaml). Symfony 8.0 components are now explicitly allowed; audit for symfony/options-resolver.
Maintenance Burden Align with Laravel LTS (test against Laravel 11+). PHP 8.5 support ensures compatibility with upcoming Laravel releases.
Security Validate patterns at runtime to prevent injection. Symfony 8.0’s Stringable may reduce XSS risks in dynamic patterns.
PHP Version Risk NEW: Breaking for PHP < 8.3—migrate or pin to 5.x branch.

Key Questions

  1. Use Case Clarity:
    • Updated: Will this replace Symfony Validator or Laravel’s Validator for complex nested data? Symfony 8.0 compatibility may overlap with Laravel’s built-in validation.
  2. Pattern Design:
    • Updated: Can we use PHP 8.5 enums or typed properties in patterns (e.g., ['status' => Status::Active])?
  3. Error Handling:
    • Unchanged: How will mismatches integrate with Laravel’s App\Exceptions\Handler?
  4. Testing Strategy:
    • Updated: Can we leverage Symfony 8.0’s TestCase for pattern assertions?
  5. Alternatives:
    • Updated: Compare with Symfony Validator 6.4+ or Laravel’s Validator (now with Symfony 8.0 under the hood).

Integration Approach

Stack Fit

  • Laravel-Specific Integrations:
    • Symfony 8.0 Components: Integrate with Illuminate/Foundation’s Symfony-based HTTP stack (e.g., validate Request objects using Symfony\Component\HttpFoundation\Request).
    • PHP 8.5 Features:
      • Use enums in patterns:
        enum UserRole { ADMIN, EDITOR }
        $pattern = ['role' => UserRole::ADMIN];
        
      • Leverage typed arrays for stricter validation:
        $pattern = ['metadata' => ['tags' => 'array<int, string>']];
        
    • Middleware: Combine with Laravel’s ValidateRequests middleware for API gateways.
  • Non-Laravel PHP:
    • Symfony 8.0 Projects: Native integration with symfony/http-client or symfony/validator.
    • Lumen/Slim: Use as a standalone library with PHP 8.5’s improved error handling.

Migration Path

  1. Pilot Phase:
    • Updated: Start with Laravel 11+ projects (PHP 8.5) or Symfony 8.0 services.
    • Replace Symfony Validator or Laravel Validator for nested data (e.g., API payloads).
  2. Incremental Adoption:
    • Step 1: Add to composer.json with ^6.0; register as a service provider.
    • Step 2: Create a PHP 8.5-compatible facade (e.g., Matcher::match($data, ['key' => 'string'])).
    • Step 3: Refactor Symfony Validator rules to patterns:
      // Before (Symfony Validator)
      $validator->validate($data, [
          'email' => 'email',
          'role'  => new UserRoleEnum(),
      ]);
      // After (php-matcher)
      $matcher->match($data, [
          'email' => 'string:email',
          'role'  => UserRole::ADMIN,
      ]);
      
  3. Testing:
    • Updated: Use Symfony 8.0’s Assert for pattern validation:
      use Symfony\Component\Validator\Assert;
      Assert::isValidPattern($pattern, $data);
      

Compatibility

  • Laravel Versions:
    • Laravel 11+ (PHP 8.5): Full compatibility; leverage new features.
    • Laravel 10 (PHP 8.2): Works but misses PHP 8.5 optimizations.
    • Laravel 9 (PHP 8.1): Use 5.x branch (PHP < 8.3 not supported in 6.0.x).
  • Package Conflicts:
    • Updated: Symfony 8.0 components may conflict with older Laravel versions (e.g., symfony/options-resolver). Use composer why symfony to detect.
    • Avoid conflicts with ext-xml or spatie/array-to-object if parsing non-JSON data.
  • IDE Support:
    • Updated: PHP 8.5’s typed patterns get better autocompletion in PHPStorm (e.g., UserRole:: suggestions).

Sequencing

Phase Task Tools/Libraries Update for 6.0.18
Discovery Audit for Symfony Validator or Laravel Validator usage. git grep, phpstan Prioritize Laravel 11+/Symfony 8.0 projects.
Setup Install ^6.0; configure service provider. Composer, Laravel Service Provider Ensure PHP 8.5+ runtime.
Pilot Replace Symfony Validator rules in a feature branch. PHP
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
andydefer/laravel-cluster
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