/** * @param StrategyInterface $strategy */ public function add(StrategyInterface $strategy) { if ($strategy === $this) { throw new InvalidArgumentException("Cannot add strategy to itself."); } $this->elements[$strategy->getName()] = $strategy; }
/** * @param StrategyInterface $strategy * @param null|int $priority * * @return DelegateStrategy */ public function add(StrategyInterface $strategy, $priority = null) { if ($strategy === $this) { throw new InvalidArgumentException("Cannot add strategy to itself."); } if (is_null($priority)) { $priority = static::DEFAULT_PRIORITY; } $this->ordered = false; $this->elements[$strategy->getName()] = [static::STRATEGY_KEY => $strategy, static::PRIORITY_KEY => $priority]; return $this; }