Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class AdWizard
  4. {
  5.     protected $steps = array();
  6.  
  7.     // ...
  8.    
  9.     /**
  10.      * How to find a step with an identifier provided using array_filter function
  11.      */
  12.     public function step($identifier)
  13.     {
  14.         list($step) = \array_filter($this->steps, function($step) use ($identifier) {
  15.             return $step->getIdentifier() == $identifier;
  16.         });
  17.  
  18.         if (false == $step)) {
  19.             throw new \InvalidArgumentException('The step with identifier `'.$identifier.'` was not found');
  20.         }
  21.  
  22.         return $step;
  23.     }
  24. }