/** * @param int $code * @param string|null $message * @param string $httpVersion * @return void * @throws \Hahns\Exception\StatusMessageCannotFindException * @throws \InvalidArgumentException */ public function status($code = Response::CODE_OK, $message = null, $httpVersion = '1.1') { IntegerValidator::hasTo($code, 'code'); StringValidator::hasToBeStringOrNull($message, 'message'); StringValidator::hasTo($httpVersion, 'httpVersion'); // get message if (is_null($message)) { $constantName = sprintf('\\Hahns\\Response::MSG_%d', $code); if (!defined($constantName)) { $message = sprintf('Status message for code `%d` cannot find', $code); throw new StatusMessageCannotFindException($message); } $message = constant($constantName); } header(sprintf('HTTP/%s %d %s', $httpVersion, $code, $message)); }
/** * @param int $handler * @param array $args * @throws \InvalidArgumentException */ protected function trigger($handler, $args = []) { IntegerValidator::hasTo($handler, 'handler'); if (isset($this->eventHandler[$handler])) { $eventHandler = $this->eventHandler[$handler]; ArrayValidator::hasTo($eventHandler, 'eventHandler'); foreach ($eventHandler as $handler) { CallableValidator::hasTo($handler, 'handler'); call_user_func_array($handler, $args); } } }