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

Zend Filter Laravel Package

zendframework/zend-filter

Filtering and normalization utilities for PHP from Zend Framework. Provides a range of filters to sanitize, convert, and transform input (strings, numbers, arrays, etc.), with extensible interfaces for custom filters—useful for validation pipelines and data processing.

View on GitHub
Deep Wiki
Context7

Getting Started

The zendframework/zend-filter package is a legacy component from the Zend Framework ecosystem, archived since 2019. While no longer actively maintained, it remains useful in older Laravel applications that depend on Zend Framework components. To begin:

  • Install via Composer: composer require zendframework/zend-filter:^2.10
  • Review the original documentation (archived but still accessible) for core filters like StringTrim, ToInt, HtmlEntities, Alnum, and Digits.
  • In Laravel, you’ll typically use this for form/input validation scenarios not fully covered by built-in validation rules, especially legacy or complex transformations where Laravel’s Illuminate\Support\Str falls short.
  • First use case: stripping non-numeric characters from phone numbers before database storage.

Implementation Patterns

  • Laravel Form Requests: Inject a filter chain in rules() or withValidator() to sanitize inputs before validation. Example:
    $validator->after(function ($validator) {
        $input = $validator->getData();
        $filter = new \Zend\Filter\FilterChain();
        $filter->attach(new \Zend\Filter\StringTrim())
               ->attach(new \Zend\Filter\Alpha(['allowWhitespace' => true]));
        $validator->setData(['name' => $filter->filter($input['name'])]);
    });
    
  • Custom Casts: Extend Illuminate\Database\Eloquent\Casts\Attribute to apply filters on model attribute access.
  • API Request Sanitization: Use middleware to run a FilterChain on request input before controllers.
  • Batch Processing: Apply filters to arrays or objects using FilterChain::filter() with nested arrays or RecursiveFilter.

Gotchas and Tips

  • ⚠️ Deprecated & Unmaintained: This package is superseded by laminas/laminas-filter (Laminas Project). In new projects, migrate to laminas/laminas-filter or use Laravel-native alternatives.
  • ⚠️ Autoloading Conflicts: If using modern Laravel, ensure no namespace collisions between Zend\, Laminas\, and Symfony\Component\Validator. Use Composer’s replace or autoload exclusions if needed.
  • ⚠️ No Laravel Integration Out-of-the-Box: No service provider or config file — you must manually instantiate filters and chains.
  • 💡 Filter Chains Are Powerful: Chain filters with append()/prepend() for reusable logic (e.g., trim → lower → alnum for usernames).
  • 💡 Use Callback filters sparingly: For edge cases, \Zend\Filter\Callback lets you wrap custom logic but avoid overuse — prefer standard filters for maintainability.
  • 🔧 Extensibility: Extend \Zend\Filter\FilterInterface for domain-specific filters (e.g., SanitizePostalCode), but document them thoroughly.
  • 🔍 Debugging Tip: Wrap filters in a try/catch — some filters (e.g., Compress\Gz) throw silent failures on invalid input. Use var_dump() in custom filters or log filtered vs. raw values for regression checks.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport