, , , . , . , 0,1,2,3. , , .
public function __construct() {
$this->selectedStrategies = array(
);
}
public function load(array $userStrategies) {
for( $i=0; $i<3; $i++ ) {
try {
$rc = new ReflectionClass($userStrategies[$i]);
if( $rc->implementsInterface('Iterator') ) {
$this->selectedStrategies[$i] = new $userStrategies[$i];
} else {
throw new InvalidArgumentException('Not a Strategy');
}
} catch(ReflectionException $e) {
throw new InvalidArgumentException('Not a Class');
}
}
}
, ,
$this->selectedStrategies[0]->execute();
..
class StrategyCollection
{
protected $strategies;
public function __construct() {
$this->strategies = new SplFixedArray(4);
}
public function add(IStrategy $strategy) {
$this->strategies[] = $strategy;
return $this;
}
}
/ . type IStrategy , , , . Reflection . SplFixedArray , Runtime Exception .
selectbox. , selectbox , , . .