/** * @param $tierOrder * @param $executable Executable|callable */ public function addExecutableToTier($tierOrder, $callableOrExecutable) { if ($tierOrder >= self::TIER_NUMBER_LIMIT) { $message = sprintf("Cannot add tier past ExecutableListByTier::TIER_NUMBER_LIMIT which is %d", self::TIER_NUMBER_LIMIT); throw new TierException($message, TierException::INCORRECT_VALUE); } if ($callableOrExecutable instanceof \Tier\Executable) { $executable = $callableOrExecutable; } else { if (is_callable($callableOrExecutable) === true) { $executable = new Executable($callableOrExecutable); $executable->setAllowedToReturnNull(true); } else { $message = sprintf('Executable or callable required, instead have: %s', gettype($callableOrExecutable)); throw new TierException($message); } } if (array_key_exists($tierOrder, $this->executablesByTier) === true) { throw new TierException("Executable already set for tier {$tierOrder}"); } $this->executablesByTier[$tierOrder] = $executable; ksort($this->executablesByTier); }
/** * @param $tierOrder * @param $executable Executable|callable */ public function addExecutableToTier($tierOrder, $callableOrExecutable) { if ($tierOrder >= self::TIER_NUMBER_LIMIT) { $message = sprintf("Cannot add tier past ExecutableListByTier::TIER_NUMBER_LIMIT which is %d", self::TIER_NUMBER_LIMIT); throw new TierException($message, TierException::INCORRECT_VALUE); } if (is_a($callableOrExecutable, 'Tier\\Executable') === true) { $executable = $callableOrExecutable; } else { if (is_callable($callableOrExecutable) === true) { $executable = new Executable($callableOrExecutable); $executable->setAllowedToReturnNull(true); } else { $message = sprintf('Executable or callable required, instead have: %s', substr(var_export($callableOrExecutable, true), 0, 50)); throw new TierException($message); } } if (isset($this->executableListByTier[$tierOrder]) === false) { $this->executableListByTier[$tierOrder] = new ExecutableList(); } $this->executableListByTier[$tierOrder]->addExecutable($executable); ksort($this->executableListByTier); }