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

Class Alias Loader Laravel Package

typo3/class-alias-loader

Adds Composer-powered class aliasing for PHP libraries that rename classes. Reads alias maps from composer.json, rewrites vendor/autoload.php on dump-autoload, and registers a loader that calls class_alias() so old class names keep working transparently.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Compatibility: The package is framework-agnostic but aligns perfectly with Laravel’s Composer-based autoloading and deprecation patterns (e.g., Facades, Helpers). It complements Laravel’s native aliasing (e.g., config/app.php) without redundancy.
  • Backward Compatibility Layer: Ideal for gradual migrations (e.g., Laravel 8→11) where legacy code must coexist with new APIs. Acts as a controlled deprecation mechanism for third-party libraries (e.g., Symfony, Doctrine).
  • Monorepo/Shared Vendor Support: Enables framework-agnostic aliasing in environments where Laravel and Symfony share a vendor/ directory, resolving class name conflicts (e.g., Symfony\Component\Debug\DebugSymfony\Component\Debug\Debugger).
  • Performance-Conscious: Zero runtime overhead when no aliases are used; opcache-optimized in v2.0+ for static alias maps.

Integration Feasibility

  • Low-Coupling Design: Operates at the Composer autoloader level, requiring no application code changes. Integrates via composer.json and alias map files.
  • Laravel-Specific Workarounds:
    • Facades: Requires manual AppServiceProvider overrides (package cannot alias Facades natively; see Avoid When).
    • Service Container: Static aliases bypass Laravel’s DI, so container-bound services must use bind() or alias() in AppServiceProvider.
  • Third-Party Libraries: Automates compatibility for aggressively refactored libraries (e.g., PHPUnit, Monolog) without manual patching.

Technical Risk

Risk Category Risk Level Mitigation Strategy
Autoload Conflicts High Test composer dump-autoload --optimize post-integration; backup vendor/autoload.php.
Facades/DI Breakage Medium Use Facade::alias() in AppServiceProvider for Facade-specific mappings.
Namespace Collisions Medium Enforce fully qualified names in alias maps (e.g., \App\Old\Class).
Composer Plugin Conflicts Low Isolate testing in a dedicated branch; avoid other Composer plugins that modify autoload.php.
Debugging Complexity Low Implement a custom Artisan command to list active aliases.
PHP Version Lock-In Low Pin to v2.0.1 (bugfixed) or v1.2.2 for legacy PHP support.

Key Questions for TPM

  1. Deprecation Strategy:

    • Are we actively migrating away from deprecated Laravel components (e.g., Facades, Helpers), or is this a temporary compatibility layer?
    • How long do we need to support legacy class names (e.g., 1 year, 2 years)?
  2. Third-Party Dependencies:

    • Which third-party libraries (e.g., Symfony, Doctrine, PHPUnit) are undergoing aggressive refactoring that would benefit from this?
    • Are these libraries direct dependencies or transitive dependencies (e.g., via Laravel packages like Backpack)?
  3. Laravel-Specific Needs:

    • Do we need to alias Facades (e.g., Input::old()request()->old())? If yes, this package cannot handle it—require AppServiceProvider overrides.
    • Are we using container-bound services that rely on dynamic class resolution? If yes, static aliases may break DI.
  4. Operational Constraints:

    • Can we modify composer.json in all environments (dev/staging/prod), or is this blocked by immutable vendor/ policies (e.g., Docker)?
    • Do we have early bootstrap hooks (e.g., bootstrap/app.php overrides) that might conflict with the loader’s autoload.php injection?
  5. Performance Impact:

    • Will we enable always-add-alias-loader? If yes, measure autoload time in production (should be negligible with opcache).
    • Are we using PHP 8.1+? If not, pin to v1.2.2 for legacy support.
  6. Testing Strategy:

    • How will we verify aliases work without breaking existing code? (Suggest: property-based testing of alias maps.)
    • Do we need runtime alias validation (e.g., a middleware to log alias usage)?
  7. Rollback Plan:

    • How will we revert if aliases cause unexpected behavior? (Suggest: feature flag or composer.json toggle.)

Integration Approach

Stack Fit

  • Laravel: Partial fit. Works for static class aliases (e.g., Old\ClassApp\New\Class) but cannot replace Laravel’s Facade aliasing or container binding.
  • Symfony/Doctrine: Excellent fit for third-party library compatibility (e.g., Symfony 6→7 class renames).
  • Plain PHP: Full fit for monorepos or shared vendor/ environments.
  • Composer Ecosystem: Native fit—integrates via composer.json and autoload maps.

Migration Path

  1. Assessment Phase (1–2 weeks):

    • Audit deprecated classes in codebase (e.g., grep -r "Input::" app/, php artisan vendor:purge).
    • Identify third-party libraries with aggressive refactoring (e.g., Symfony, Doctrine).
    • Create a proof-of-concept alias map (e.g., app/Compatibility/LaravelAliasMap.php).
  2. Integration Phase (2–3 weeks):

    • Add to composer.json:
      "extra": {
        "typo3/class-alias-loader": {
          "class-alias-maps": [
            "app/Compatibility/LaravelAliasMap.php",
            "vendor/symfony/http-foundation/alias-map.php"
          ],
          "always-add-alias-loader": true
        }
      }
      
    • Run composer install --no-dev and test in a staging environment.
    • Verify:
      • vendor/autoload.php includes the loader.
      • Legacy class names resolve correctly (e.g., new Old\Class() works).
      • No performance regression (measure with composer dump-autoload --optimize).
  3. Laravel-Specific Workarounds:

    • For Facades, add to AppServiceProvider:
      public function register()
      {
          Facade::alias('Input', Request::class);
      }
      
    • For container-bound services, use bind():
      $this->app->bind('Old\Service', function ($app) {
          return new App\New\Service();
      });
      
  4. Rollout Phase (1 week):

    • Deploy to staging, monitor for autoload errors.
    • Gradually enable in production via feature flag or composer.json toggle.
    • Deprecate legacy classes in phases (e.g., log warnings via error_log when old classes are used).

Compatibility

Component Compatibility Status Notes
Laravel Facades ❌ Not supported Use AppServiceProvider::alias() instead.
Laravel DI Container ⚠️ Partial Static aliases bypass DI; use bind() for container-bound services.
Symfony/Doctrine ✅ Full Ideal for third-party library compatibility.
Plain PHP ✅ Full Works in any Composer-based PHP project.
PHP 8.1+ ✅ Full Use v2.0.1 (bugfixed).
PHP < 8.1 ⚠️ Limited Use v1.2.2 (drops PHP 8.4 support).
Case-Insensitive Loading ❌ Removed (v2.0+) Use v1.2.2 for legacy support.

Sequencing

  1. Start with non-critical paths (e.g., legacy admin panels, deprecated APIs).
  2. Test third-party libraries first (e.g., Symfony, Doctrine) before Laravel-specific aliases.
  3. Avoid enabling always-add-alias-loader in production until thoroughly tested.
  4. Phase out legacy classes after confirming
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.
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
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