SPL iterators with closure context switching

Some time ago I redi­sco­ve­red PHP SPL library. After reading Joshua Thijssen’s Maste­ring the SPL Library I found out that some­ti­mes I was reinven­ting the wheel in my code, sorry (employ­ers and custo­mers). Itera­tors are one of the SPL library compo­nents. To add more spice to code I’ll show some kind of Java­Script magic using closures.

Simplest and best itera­tor definition:

Itera­tors are PHP’s way of dealing with abstrac­ting away the traver­sal logic from the busi­ness logic. This, in one sentence, sums up what an itera­tor is. [J. Thijs­sen : Maste­ring…, p. 68]

My goal for today is to show you how to use Itera­to­rAg­gre­gate with Call­back­Fil­te­rI­te­ra­tors to filter out files not meeting our requ­ire­ments.

Feel free to use this class in your own projects.

Podobne wpisy:

  1. Using PHP traits to check class constants values
  2. 2 ways to check stream mimetype
  3. Writing custom stream filters
  4. Using stre­ams in multi process environment

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany.

Możesz użyć następujących tagów oraz atrybutów HTML-a: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>