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

Dms Filter Laravel Package

dms/dms-filter

Filter and sanitize object properties via PHP attributes. Annotate fields with rules like Trim, StripTags, and StripNewlines, then run a Filter service to clean entity values automatically—ideal alongside Symfony Validator and for consistent input normalization.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Annotation-based filtering aligns well with Laravel’s doctrine/annotations and PHP 8 attributes support, enabling seamless integration with Eloquent models, DTOs, or API request payloads.
  • Decoupled design (filter rules as annotations) reduces coupling between business logic and filtering logic, adhering to SOLID principles (Single Responsibility, Open/Closed).
  • Potential overlap with Laravel’s built-in validation (e.g., Illuminate\Validation) or form request filtering, but this package offers pre-processing (e.g., sanitization) before validation.
  • Opportunity for extension: Custom filter rules can be added via annotations, making it adaptable to domain-specific needs (e.g., financial data scrubbing, PII redaction).

Integration Feasibility

  • Low friction for Laravel: Works natively with PHP 8+ attributes (no legacy annotation parser dependency if using PHP 8+).
  • Dependency conflicts: Minimal (only php and ext-json), but may require Doctrine Annotations for PHP <8.0 compatibility.
  • Service container integration: Can be registered as a Laravel service provider for dependency injection (e.g., binding DMS\Filter\Filter to app container).
  • ORM compatibility: Tested with Doctrine ORM (via annotations), but Laravel’s Eloquent uses attributes, so mapping layer may be needed for full Eloquent support.

Technical Risk

  • PHP 8+ requirement: If the project uses PHP <8.0, annotation parsing will require Doctrine Annotations or a polyfill, adding complexity.
  • Performance overhead: Annotation reflection adds runtime metadata resolution cost. Benchmark against alternatives like Laravel’s Str::* helpers or custom pipeline filters.
  • Limited Laravel-specific features: No built-in support for Laravel’s request lifecycle (e.g., middleware integration) or API resource transformation.
  • Testing effort: May need to validate edge cases (e.g., nested objects, recursive filtering) in Laravel’s context.

Key Questions

  1. Use case alignment:
    • Is this for input sanitization (e.g., user-generated content), data normalization, or API response filtering?
    • Does it replace or complement Laravel’s existing validation/validation rules?
  2. Performance constraints:
    • Will annotation reflection impact high-throughput endpoints (e.g., API rate-limited routes)?
  3. ORM strategy:
    • Should filtering apply to Eloquent models, DTOs, or raw request data?
  4. Customization needs:
    • Are built-in filters sufficient, or will custom rules be required?
  5. Migration path:
    • How will existing sanitization logic (e.g., Str::of($input)->replace(...)) transition to annotations?

Integration Approach

Stack Fit

  • PHP 8+: Native attribute support reduces boilerplate; leverage Laravel’s attribute reflection (e.g., app()->make(Attribute::class)).
  • Laravel Ecosystem:
    • Eloquent: Use model events (retrieved, saved) or accessors/mutators to apply filters.
    • API Resources: Integrate with toArray()/toJson() via macro or trait.
    • Form Requests: Apply filters in prepareForValidation() or sanitize() methods.
    • Middleware: Create middleware to filter request payloads before validation.
  • Alternatives:
    • For request filtering, compare with Illuminate\Validation or spatie/laravel-query-builder (for query-level filtering).
    • For response filtering, consider spatie/array-to-object or custom pipelines.

Migration Path

  1. Pilot Phase:
    • Start with non-critical entities (e.g., User, Post) to test annotation performance and edge cases.
    • Replace simple Str::* sanitization with annotations (e.g., #[Filter\Trim] instead of trim($request->input('name'))).
  2. Incremental Adoption:
    • Phase 1: Input sanitization (form requests, API payloads).
    • Phase 2: Model-level filtering (Eloquent accessors/mutators).
    • Phase 3: API response filtering (via resources or middleware).
  3. Tooling:
    • Use PHPStan or Psalm to detect missing annotations in CI.
    • Generate migration scripts to retroactively add annotations to existing models.

Compatibility

  • Laravel Versions:
    • Tested with Laravel 9+ (PHP 8.0+). For Laravel 8, use dnoegel/php-xdg-base-dir for annotation parsing.
    • Lumen: Possible with manual service container setup.
  • Dependencies:
    • Conflict risk with doctrine/annotations if using PHP <8.0 (resolve via composer overrides).
    • No conflicts with Laravel’s core components.
  • Database:
    • Filters operate on PHP objects, not SQL queries (avoids database-specific quirks).

Sequencing

  1. Setup:
    • Install package: composer require dms/dms-filter.
    • Register service provider (if needed) to bind DMS\Filter\Filter to Laravel’s container.
  2. Annotation Migration:
    • Add annotations to DTOs or Eloquent models (prioritize input-heavy fields).
    • Example:
      #[Filter\StripTags]
      #[Filter\EscapeHtml]
      public string $description;
      
  3. Integration Points:
    • Request Filtering: Apply in App\Http\Middleware\FilterRequests:
      public function handle(Request $request, Closure $next) {
          $filtered = (new Filter())->filter($request->all());
          $request->merge($filtered);
          return $next($request);
      }
      
    • Model Filtering: Use accessors:
      public function getNameAttribute(string $name): string {
          return (new Filter())->filter($this->name);
      }
      
  4. Testing:
    • Validate filters in unit tests (mock annotations).
    • Test edge cases (e.g., nested objects, empty strings).

Operational Impact

Maintenance

  • Pros:
    • Declarative: Annotations centralize filtering logic, reducing scattered Str::* calls.
    • Extensible: Add custom filters via annotations without modifying core logic.
    • MIT License: No vendor lock-in; can fork or replace if needed.
  • Cons:
    • Annotation bloat: Overuse may clutter entity classes (mitigate with grouped annotations or interfaces).
    • Debugging: Reflection-based filters may obscure stack traces (log filtered values for debugging).
  • Tooling:
    • Use IDE hints (PHPStorm) to discover available filters.
    • Document custom filter rules in a FILTER_RULES.md file.

Support

  • Learning Curve:
    • Team must understand annotation-based configuration (vs. imperative filtering).
    • Provide code examples for common use cases (e.g., API requests, form submissions).
  • Troubleshooting:
    • Common issues:
      • Missing annotations: Static analysis (PHPStan) can catch this.
      • Performance bottlenecks: Profile with Xdebug to identify slow reflections.
    • Fallback: Implement a configurable whitelist to disable annotations in production if needed.

Scaling

  • Performance:
    • Cold start impact: Annotation reflection adds ~5–10ms per request (benchmark with laravel-debugbar).
    • Warmup: Use OPcache to mitigate reflection overhead.
    • Caching: Cache filtered results for read-heavy endpoints (e.g., API responses).
  • Horizontal Scaling:
    • Stateless filters scale horizontally with Laravel’s queue workers or API servers.
    • Database impact: None (filters operate in-memory).
  • Load Testing:
    • Simulate high concurrency to validate reflection performance under load.

Failure Modes

  • Runtime Errors:
    • Invalid annotations: Catch with @throws in custom filters.
    • Recursive filtering: Handle circular references in objects (e.g., #[Filter\Recursive]).
  • Data Corruption:
    • Over-aggressive filters: Test with malformed input (e.g., null, false, nested arrays).
    • Backup strategy: Log original vs. filtered values for auditing.
  • Downtime Risk:
    • Low: Filters are pure functions; failures won’t crash the app (graceful degradation via try-catch).

Ramp-Up

  • Onboarding:
    • Documentation:
      • Add a Laravel-specific guide to the project’s docs/ folder.
      • Include migration steps from Str::* to annotations.
    • Workshops:
      • Hands-on session to annotate 2–3 entities live.
      • Compare before/after performance metrics.
  • **Team Adoption
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