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

Aliaser Laravel Package

sindyko/aliaser

Laravel package for elegant alias management across Eloquent models, Livewire forms, DTOs, collections, and enums. Use short aliases and the Entity facade (Entity::user(1)), auto-sync morph maps, and optimize Livewire snapshots with custom synthesizers.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Eloquent-Centric Design: Perfectly aligns with Laravel's Eloquent ecosystem, leveraging the Entity facade to abstract model access. The ModelProxy pattern enables seamless integration with query builder methods while maintaining compatibility with static methods (e.g., create(), all()).
  • Livewire Optimization: Targeted snapshot reduction (up to 50%) via custom synthesizers (ModelAliasSynth, FormAliasSynth, etc.) addresses a critical pain point in Livewire-heavy applications. The morph map integration further reduces payload size in polymorphic relations.
  • Registry-Based Abstraction: Five specialized registries (ModelRegistry, FormRegistry, etc.) enforce type safety and bidirectional mapping (alias ↔ class), reducing boilerplate in controllers and services.
  • CLI-Driven Workflow: Artisan commands (aliaser:list, aliaser:install) streamline alias management, aligning with Laravel’s convention-over-configuration philosophy.

Integration Feasibility

  • Low Friction: Installation requires one Composer command and a single AppServiceProvider registration, with zero breaking changes to existing Eloquent/Livewire code.
  • Backward Compatibility: The Entity facade wraps native model calls, ensuring existing queries (e.g., User::where(...)) remain functional. Livewire snapshots are opt-in via synthesizers.
  • Morph Map Sync: Automatically updates polymorphic relations (e.g., commentable_type: 'post' instead of 'App\Models\Post'), reducing database bloat without manual migration.
  • DTO/Enum Support: Extends beyond models to forms, collections, and enums, making it versatile for API responses and domain-driven design.

Technical Risk

  • Alias Collisions: Without allow_overwrite: true, duplicate aliases throw exceptions. Mitigation: Enforce naming conventions (e.g., snake_case) and validate during CI.
  • Livewire Version Lock: Requires Livewire 3.x; older versions lack synthesizer support. Risk: Deprecation if Livewire 4.x drops backward compatibility.
  • Performance Overhead: Static method caching (via Reflection) adds ~1μs on first call but is negligible for most applications. Memory usage is ~50KB for 1,000 aliases, which is acceptable.
  • Testing Complexity: Livewire snapshot optimizations may require updated snapshot tests if aliases change. Use aliaser:list --json to audit aliases pre-deployment.

Key Questions

  1. Alias Naming Strategy:

    • How will aliases be named (e.g., user vs. app_user)? Document conventions to avoid collisions.
    • Recommendation: Use short, globally unique names (e.g., user, post) and reserve prefixes (e.g., admin_) for namespaces.
  2. Livewire Adoption:

    • Is Livewire a core dependency? If not, prioritize model/DTO aliasing first to justify the package.
    • Recommendation: Start with modelsMap() and objectsMap(), then enable Livewire features incrementally.
  3. Morph Map Trade-offs:

    • Will polymorphic relations use aliases (e.g., post) or FQCNs? Aliases reduce storage but may complicate debugging.
    • Recommendation: Enable use_morph_map: true in config and monitor query performance.
  4. Migration Path:

    • How will existing codebases replace User::find() with Entity::user(1)?
    • Recommendation: Use IDE refactoring tools (e.g., PHPStorm’s "Rename") and static analysis (e.g., PHPStan) to enforce adoption.
  5. Security:

    • Are aliases exposed in frontend templates (e.g., via Livewire)? Ensure they don’t leak sensitive information.
    • Recommendation: Use obfuscated aliases (e.g., mdl-alias keys) and avoid exposing raw aliases in API responses.

Integration Approach

Stack Fit

  • Laravel 10/11/12: Native support with zero framework modifications required.
  • Livewire 3.x: Optional but highly recommended for snapshot optimization. Conflicts unlikely given Livewire’s plugin architecture.
  • Eloquent: Deep integration with query builder, morph maps, and collections. No conflicts with Laravel’s core.
  • DTOs/Enums: Complements packages like spatie/laravel-data or ramsey/uuid for structured data.
  • Testing: Works with Pest/PHPUnit via ModelProxy::clearStaticMethodsCache().

Migration Path

  1. Phase 1: Core Aliases (2–4 weeks)

    • Register models (modelsMap()) and DTOs (objectsMap()) in AppServiceProvider.
    • Replace direct model calls (e.g., User::find()) with Entity::user() in controllers/services.
    • Tools: Use aliaser:list to audit coverage.
  2. Phase 2: Livewire Optimization (1–2 weeks)

    • Enable Livewire synthesizers by installing the package in a feature branch.
    • Update snapshot tests to reflect alias-based payloads (e.g., class: "user" instead of "App\Models\User").
    • Validation: Measure snapshot size reduction with php artisan livewire:test.
  3. Phase 3: Polymorphic Relations (1 week)

    • Enable use_morph_map: true in config/aliaser.php.
    • Update seeder/migration tests to verify alias-based polymorphic types.

Compatibility

  • No Laravel Core Conflicts: Uses facades, service providers, and artisan commands—standard Laravel patterns.
  • Third-Party Packages:
    • Livewire: Tested with Livewire 3.x; no known conflicts.
    • Eloquent: Works alongside Scout, MediaLibrary, or Tenancy packages.
    • API Resources: Aliases do not affect toArray()/toJson() unless explicitly used in responses.
  • PHP 8.1+: Leverages named arguments, attributes, and enums safely.

Sequencing

Step Action Dependencies Risk
1 Install package Laravel 10+ Low
2 Register aliases in AppServiceProvider - Low
3 Replace Model::method() with Entity::alias() - Medium (refactoring)
4 Enable Livewire synthesizers Livewire 3.x Medium (snapshot tests)
5 Enable morph map sync - Low
6 Update CI/CD to validate aliases - Low

Operational Impact

Maintenance

  • Alias Management:
    • Pros: Centralized via AppServiceProvider or separate config file (e.g., config/aliaser.php).
    • Cons: Manual updates required if class names change (e.g., App\Models\UserApp\Models\Customer).
    • Mitigation: Use aliasForClass() to dynamically fetch aliases and CI checks to detect orphaned aliases.
  • Livewire Snapshots:
    • Pros: Reduced payload size automatically maintained.
    • Cons: Snapshot tests may need updates if aliases change.
    • Mitigation: Use aliaser:list --json to track aliases and feature flags for gradual rollout.

Support

  • Debugging:
    • Pros: aliaser:help provides topic-specific documentation.
    • Cons: Stack traces may reference aliases instead of FQCNs, complicating debugging.
    • Mitigation: Log both alias and FQCN in error contexts (e.g., Entity::user(1)App\Models\User).
  • Performance:
    • Pros: Static method caching reduces Reflection overhead.
    • Cons: First-call latency (~1μs) may affect cold starts.
    • Mitigation: Benchmark in staging; cache warm-up in queue workers.

Scaling

  • Alias Registry:
    • Memory: ~50KB for 1,000 aliases (negligible).
    • CPU: Reflection caching amortizes static method calls.
  • Livewire:
    • Snapshot Size: 50% reduction scales bandwidth and response times.
    • Concurrency: No shared state; synthesizers are per-request.
  • Database:
    • Morph Map: Smaller type columns reduce storage (e.g., post vs. App\Models\Post).

Failure Modes

Scenario Impact Mitigation
Alias collision AliaserException breaks application Enable allow_overwrite: true in
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony