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

Autoload Validation Laravel Package

phpcq/autoload-validation

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Complementary to Laravel’s Dependency Model: Validates Composer’s autoload configuration without interfering with Laravel’s service container or routing. Aligns with Laravel’s reliance on PSR-4 autoloading for classes (e.g., App\Services\*) and classmaps for framework-specific files (e.g., config/, routes/).
  • Pre-Deployment Safety Net: Acts as a static analysis layer to prevent ClassNotFoundException in production, reducing reliance on Laravel’s ClassLoader runtime checks or config/app.php overrides.
  • Monorepo Support: Can validate autoload paths across multiple Laravel/Lumen projects sharing a composer.json, addressing a common pain point in large-scale PHP projects.

Integration Feasibility

  • Zero Laravel Core Modifications: Operates purely on composer.json and filesystem structures, requiring no changes to Laravel’s AppServiceProvider, Bootstrap, or composer.lock.
  • CLI-Driven Workflow: The binary (check-autoloading.php) can be invoked via:
    • Composer Scripts: Add to composer.json scripts for local/dev validation:
      "scripts": {
        "post-autoload-dump": "php vendor/bin/check-autoloading.php",
        "validate": "php vendor/bin/check-autoloading.php && @php artisan test"
      }
      
    • Artisan Command: Wrap the binary in a Laravel command for developer convenience (see Integration Approach).
    • CI/CD Hooks: Integrate into GitHub Actions, GitLab CI, or CircleCI as a pre-test or pre-deploy step.
  • Dependency Isolation: No conflicts with Laravel’s dependencies (e.g., illuminate/, symfony/) or other PHP tools (e.g., PHPStan, Psalm).

Technical Risk

  • Laravel-Specific Autoload Edge Cases:
    • Framework Classes: May flag Laravel’s internal classes (e.g., Illuminate\Foundation\Application) if not explicitly defined in composer.json. Mitigation: Exclude vendor/laravel/ or whitelist Laravel’s autoload paths.
    • Dynamic Class Loading: Ignores classes loaded at runtime (e.g., via ClassLoader::addPsr4() or eval). Mitigation: Document limitations or extend the tool to support dynamic paths.
    • Classmap Overrides: Laravel’s config/app.php may override autoload paths (e.g., ClassLoader::addClassMap()). Mitigation: Validate against the final classmap after Laravel’s bootstrapping.
  • Performance:
    • Filesystem traversal could add 1–5 seconds to CI pipelines for large projects (>50k files). Mitigation: Run in parallel with other tools or cache results.
  • False Positives:
    • May incorrectly flag excluded directories (e.g., tests/, resources/lang/) if not configured in composer.json. Mitigation: Use autoload-exclude or suppress warnings via CLI flags.

Key Questions

  1. Validation Granularity:
    • Should the tool validate only the project’s autoload paths or also Laravel’s framework autoloads (e.g., Illuminate\*)? If the latter, how to handle Laravel’s evolving class structure across versions?
  2. Dynamic vs. Static Classes:
    • How to handle classes generated at runtime (e.g., API Platform resources, Fractal transformers)? Should these be excluded or dynamically added to the validation?
  3. CI/CD Enforcement:
    • Should validation failures block deployments (e.g., GitHub Actions if: failure()) or be logged as warnings? What’s the acceptable false-positive rate?
  4. Tooling Synergy:
    • How to integrate with Laravel’s existing validation tools (e.g., php artisan optimize, phpstan, pint)? Should this replace or complement them?
  5. Maintenance Ownership:
    • Who will update validation rules if Laravel’s autoload structure changes (e.g., new framework classes in Laravel 11+)? TPM, DevOps, or developers?

Integration Approach

Stack Fit

  • Laravel Ecosystem Compatibility:
    • Works with Laravel 5.8+, Lumen, and custom PHP applications using Composer.
    • Compatible with Laravel Forge/Envoyer (run as a pre-deploy hook) and Laravel Vapor (validate before deployment).
    • Integrates with Laravel Mix or Vite workflows by ensuring frontend-related classes (e.g., MixManifest) are correctly autoloaded.
  • CI/CD Platforms:
    • GitHub Actions: Add to a dedicated job or matrix step:
      - name: Validate Autoload
        run: php vendor/bin/check-autoloading.php
      
    • GitLab CI: Include in the test or deploy stage:
      validate-autoload:
        script: php vendor/bin/check-autoloading.php
        allow_failure: true # Initially non-blocking
      
    • CircleCI: Run after composer install:
      - run:
          name: Validate Autoload
          command: php vendor/bin/check-autoloading.php
      
  • Local Development:
    • Composer Scripts: Add to composer.json for local validation:
      "scripts": {
        "post-install-cmd": ["@validate-autoload"],
        "validate-autoload": "php vendor/bin/check-autoloading.php"
      }
      
    • Artisan Command: Create a custom command for developer workflows:
      // app/Console/Commands/ValidateAutoload.php
      namespace App\Console\Commands;
      use Illuminate\Console\Command;
      class ValidateAutoload extends Command {
          protected $signature = 'autoload:validate';
          protected $description = 'Validate Composer autoload paths';
          public function handle() {
              $exitCode = shell_exec('php vendor/bin/check-autoloading.php');
              if ($exitCode !== 0) {
                  $this->error('Autoload validation failed!');
                  exit($exitCode);
              }
              $this->info('Autoload validation passed.');
          }
      }
      
    • Pre-Commit Hooks: Use Husky or Laravel Git to run validation before commits:
      # package.json
      "husky": {
        "hooks": {
          "pre-commit": "composer validate-autoload"
        }
      }
      

Migration Path

  1. Pilot Phase (Week 1):
    • Add to require-dev and test in a staging environment or feature branch.
    • Document exceptions (e.g., excluded directories) in composer.json:
      "autoload-exclude": [
        "tests/",
        "resources/lang/",
        "vendor/laravel/framework/src/Illuminate/Foundation/"
      ]
      
    • Run manually to identify false positives/negatives:
      ./vendor/bin/check-autoloading.php --verbose
      
  2. CI/CD Integration (Week 2):
    • Add to CI/CD as a non-blocking step (log warnings):
      # GitHub Actions example
      - name: Validate Autoload (Warning)
        run: php vendor/bin/check-autoloading.php || true
      
    • Monitor failure rates for 2 sprints before enforcing.
  3. Enforcement Phase (Week 3+):
    • Update CI/CD to block deployments on failures:
      - name: Validate Autoload (Blocking)
        run: php vendor/bin/check-autoloading.php
      
    • Add to pre-deploy hooks (Forge/Envoyer) or GitHub branch protection rules.
  4. Laravel-Specific Tweaks:
    • Exclude Laravel’s vendor/ directory by passing a custom root path:
      ./vendor/bin/check-autoloading.php ./app
      
    • Or configure composer.json to ignore Laravel’s autoload paths:
      "autoload-exclude": ["vendor/laravel/**"]
      

Compatibility

  • Laravel Versions: Compatible with Laravel 5.8–11.x (PHP 7.2–8.2) due to Composer 1.x/2.x support.
  • Monorepos: Requires path adjustments if projects use non-standard directory structures (e.g., packages/*).
  • Windows/Linux/macOS: Tested via CI, but filesystem paths may need escaping in Windows (e.g., ./vendor/bin/check-autoloading.php .).
  • Docker/Containerized Environments: Works seamlessly as long as the composer.json and filesystem structure match the host.

Sequencing

  1. Order in CI/CD Pipeline:
    • Run after composer install and composer dump-autoload but before tests or deployment:
      composer install → composer dump-autoload → validate-autoload → run-tests → deploy
      
    • Example GitHub Actions workflow:
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
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