title: How to design filters for a generic, pluggable collection?
body: <p>I am developing a web application that features a timeline, much like a Facebook timeline. The timeline itself is completely generic and pluggable. It's just a generic collection of items. Anything with the proper interface (<code>Dateable</code>) can be added to the collection and displayed on the timeline.</p>
  
  <p>Other components (Symfony bundles) define models that implement the <code>Dateable</code> interface and set up a provider that can find and return these models. The code is much like this:</p>
  
  <pre><code>class Timeline
  {
      private $providers = []; // Filled by DI
  
      public function find(/* ... */)
      {
          $result = [];
          foreach ($this-&gt;providers as $provider) {
              $result = array_merge($result, $provider-&gt;find(/* ... */));
          }
  
          return $result;
      }
  }
  </code></pre>
  
  <p>The problem is that there needs to be a set of filters next to the timeline. Some filter options (like <code>date</code>) apply to all providers. But most options do not. For example, most providers will be able to use the <code>author</code> filter option, but not all. Some notification item are dynamically generated and don't have an author.</p>
  
  <p>Some filter options just apply to a single provider. For example, only event items have a <code>location</code> property.</p>
  
  <p>I can't figure out how to design a filter form that is just as modular as the timeline itself. Where should the available filter options be defined? Bundle-specific filter options could probably come from the bundle itself, but how about filter options (like <code>user</code>) that can be used by multiple bundles? And what if some filter options later become usable by multiple bundles? For example, only events have a <code>location</code> now, but what if another module is added that also has items with a location?</p>
  
  <p>And how will each provider determine if the submitted filter form only contains options it understands? If I set a location in the filter then the <code>BlogPostProvider</code> should not return any messages, because blog posts have no location. But I can't check for <code>location</code> in the filter because the BlogPostBundle shouldn't know about other providers and their filtering options.</p>
  
  <p>Any ideas on how I can design such a filter form?</p>