Weave 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 Domain Parser Laravel Package

jeremykendall/php-domain-parser

Parse, validate, and normalize domains, subdomains, and suffixes using the Public Suffix List. Extract registrable domain vs. subdomain, handle IDNs and edge cases, and keep parsing rules current via PSL updates—ideal for URL processing, cookies, and security checks.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Enhanced Domain Handling: New methods (withRootLabel, withoutRootLabel, isAbsolute) improve support for absolute domain names (e.g., example.com. vs. example.com), critical for:
    • DNS/email validation (e.g., RFC-compliant domain checks).
    • Multi-tenant SaaS (e.g., distinguishing example.com vs. example.com. in routing).
    • Compliance tools (e.g., GDPR cookie domain scoping for absolute paths).
  • Conditional Domain Building: DomainName::when() enables dynamic domain construction (e.g., conditional subdomains), useful for:
    • Feature flags (e.g., staging.example.com vs. prod.example.com).
    • A/B testing (e.g., test-variant.example.com).
  • Private Domain Support: Fix for wildcarded subdomain suffixes (e.g., *.internal.company) aligns with:
    • Internal tooling (e.g., VPNs, private TLDs).
    • Hybrid cloud setups (e.g., *.aws.internal).

Integration Feasibility

  • Absolute Domain Methods:
    • Pros: Simplifies parsing for strict RFC compliance (e.g., Host headers in HTTP/3).
    • Cons: Requires explicit handling of trailing dots (e.g., example.com. vs. example.com).
    • Mitigation: Use isAbsolute() to normalize inputs in middleware/request validation.
  • Conditional Logic (when):
    • Pros: Reduces boilerplate for dynamic domain generation (e.g., locale-based subdomains).
    • Cons: Adds complexity if overused; prefer service-layer abstraction (e.g., DomainBuilder).
  • Private Suffix Fix:
    • Pros: Resolves edge cases for custom PSL entries (e.g., *.private).
    • Cons: Cache refresh required post-upgrade (see Operational Impact).
  • PHP 7+ Only:
    • Pros: Modern type hints improve IDE support and runtime safety.
    • Cons: Breaking for PHP 7.x users (though Laravel 10+ mandates PHP 8.1+).

Technical Risk

  • Cache Invalidation:
    • Risk: Private suffix fixes require manual cache refresh (php-domain-parser:clear-cache).
    • Mitigation: Add a post-upgrade script to clear cache in CI/CD:
      composer require jeremykendall/php-domain-parser:^6.4.0
      php artisan vendor:publish --provider="JeremyKendall\DomainParser\DomainParserServiceProvider" --tag="config"
      php artisan domain-parser:clear-cache
      
  • Absolute Domain Ambiguity:
    • Risk: Trailing dots (e.g., example.com.) may cause unexpected behavior in downstream systems.
    • Mitigation: Normalize domains in a service layer:
      $domain = $parser->parse($input)->withoutRootLabel();
      
  • Conditional Logic Complexity:
    • Risk: Overuse of when() could lead to hard-to-debug domain chains.
    • Mitigation: Document usage patterns (e.g., "Use only for dynamic subdomains").

Key Questions

  1. Absolute Domain Strategy:
    • How will you handle trailing dots in user inputs (e.g., example.com. from APIs)?
    • Do you need to enforce absolute domains for specific endpoints (e.g., DNS records)?
  2. Private Suffix Workflow:
    • Are you using custom PSL entries (e.g., *.internal)? If so, test the fix with your existing rules.
    • How will you automate cache refreshes in production (e.g., cron job, deploy hook)?
  3. Conditional Domain Use Cases:
    • Will when() be used for runtime logic (e.g., feature flags) or static configs?
    • Do you need immutable domain builders (e.g., for thread safety)?
  4. PHP Version Lock:
    • Are you blocked on PHP 7.x? If so, consider forking or using a legacy branch.
  5. Performance Impact:
    • Does the new when() method add overhead for high-frequency parsing (e.g., 10K+ RPS)?

Integration Approach

Stack Fit

  • Laravel Synergy:
    • Absolute Domains: Integrate with Request facade to normalize Host headers:
      $domain = app(DomainService::class)->parse(request()->host)->withoutRootLabel();
      
    • Conditional Logic: Use in dynamic route generation (e.g., Route::domain('{sub}.example.com')->when(fn() => config('features.subdomains'))).
  • Testing Tools:
    • Pest/Laravel: Test absolute domains with:
      it('parses absolute domains', function () {
          $parser = new DomainParser();
          expect($parser->parse('example.com.')->isAbsolute())->toBeTrue();
      });
      
  • Alternatives:
    • For legacy PHP 7.x, evaluate publicsuffixlist/publicsuffixlist-php (though less maintained).

Migration Path

  1. Pre-Upgrade:
    • Backup custom PSL rules (if any).
    • Test cache behavior: Verify php-domain-parser:clear-cache works in staging.
  2. Upgrade:
    • Update composer.json and run:
      composer update jeremykendall/php-domain-parser
      php artisan domain-parser:clear-cache
      
  3. Service Layer Update:
    • Extend DomainService to use new methods:
      class DomainService {
          public function normalize(string $domain): string {
              return $this->parser->parse($domain)->withoutRootLabel()->toString();
          }
          public function isAbsoluteDomain(string $domain): bool {
              return $this->parser->parse($domain)->isAbsolute();
          }
      }
      
  4. Middleware/Validation:
    • Update to handle absolute domains:
      // app/Http/Middleware/ParseDomain.php
      public function handle($request, Closure $next) {
          $domain = app(DomainService::class)->normalize($request->host);
          $request->merge(['normalized_domain' => $domain]);
          return $next($request);
      }
      

Compatibility

  • Laravel 10/11:
    • Fully compatible with PHP 8.1+ type hints.
    • No breaking changes for existing parsing logic (backward-compatible).
  • PHP 7.x:
    • Unsupported: Requires fork or downgrade to 6.3.x.
  • CI/CD:
    • Add cache-clearing to deploy scripts:
      # .github/workflows/deploy.yml
      - run: php artisan domain-parser:clear-cache
      

Sequencing

  1. Phase 1: Core Upgrade
    • Update package and clear cache.
    • Test private suffix resolution with existing custom rules.
  2. Phase 2: Absolute Domain Handling
    • Add withoutRootLabel() to all domain inputs (e.g., Host headers, user uploads).
    • Update validation rules to reject trailing dots if undesired.
  3. Phase 3: Conditional Logic
    • Implement when() for dynamic use cases (e.g., feature flags).
    • Document usage patterns to avoid over-engineering.
  4. Phase 4: Monitoring
    • Log absolute domain parsing to catch edge cases (e.g., example.com. in production).

Operational Impact

Maintenance

  • Cache Management:
    • Automate refreshes: Schedule php artisan domain-parser:clear-cache post-deploy or post-PSL-update.
    • Monitor failures: Alert on cache-related parsing errors (e.g., PrivateSuffixException).
  • Deprecation Tracking:
    • None yet, but monitor for future PHP 7.x drops.
  • Custom PSL:
    • Test thoroughly after upgrades (private suffix fixes may interact with custom rules).

Support

  • Debugging Tools:
    • Use isAbsolute() to audit domain inputs:
      $domain = $parser->parse($input);
      if ($domain->isAbsolute()) {
          logger()->warning("Absolute domain detected: {$domain}");
      }
      
    • Laravel Telescope: Track domain parsing metrics (e.g., parsed_domain events).
  • Documentation:
    • Add internal runbook for:
      • Cache refresh procedures.
      • Absolute domain normalization workflows.
    • Example:
      ## Domain Parsing Runbook
      1. **Cache Issues**: Run `php artisan domain-parser:clear-cache`.
      2.
      
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.
thuraaung2493/laravel-rulecraft
cyberwizard/schedule-catchup
livetennisapi/livetennisapi-laravel
roundly-consulting/notifications-for-laravel
flightsadmin/bootstrap-starter-kit
lasserafn/laravel-intempus
likyly/sdk
tdt/input
coreation/php-shapefile
coreation/gisconverter
primix/widgets
primix/notifications
primix/actions
primix/tables
primix/details
primix/forms
primix/support
marcelgwerder/laravel-api-handler
firebrikdotcom/conveyor-laravel-broadcaster
kanata-php/conveyor-laravel-broadcaster