public function __invoke($error, Request $request, Response $response, callable $next) { /* If $error is not an exception, it will use the response status if it already indicates an error (ie., >= 400 status), or will use a 500 status, and return the response directly with the reason phrase. */ if ($error instanceof \Exception) { $className = $error->getTrace(); if (isset($className[0]['class'])) { $className = $className[0]['class']; } if ($error instanceof ResourceNotFoundException) { $error = $this->getErrorArray($error->getMessage(), $this->getErrorCode($error, $className), $error->getResourceDO()); return new NotFoundResponse($error); } else { if ($error instanceof WrongRequestException) { /** @see \Zend\Diactoros\Response::$phrases */ return $this->response(400, $error->getMessage(), ExceptionCodes::code($className) . '.' . $error->getCode()); } else { $message = $this->config->get('error_handler', false) ? $error->getMessage() : 'Internal error'; /** @see \Zend\Diactoros\Response::$phrases */ return $this->response(503, $message, $this->getErrorCode($error, $className)); } } } else { $next($request, $response, $next); } }
/** * @return \AudioManager\Adapter\AdapterInterface * @throws RuntimeException */ public function __invoke() { $adapterName = strtolower($this->config->get('voice.provider', self::VOICE_PROVIDER_GOOGLE)); switch ($adapterName) { case self::VOICE_PROVIDER_GOOGLE: $adapter = new Google(); $adapter->getOptions()->setLanguage('en'); $adapter->getOptions()->setEncoding('UTF-8'); break; case self::VOICE_PROVIDER_IVONA: $secretKey = $this->config->get('voice.' . $adapterName . '.secret_key', ''); $accessKey = $this->config->get('voice.' . $adapterName . '.access_key', ''); $adapter = new Ivona(); $adapter->getOptions()->setSecretKey($secretKey); $adapter->getOptions()->setAccessKey($accessKey); break; default: throw new ErrorException('Not implemented functionality for voice provider: ' . $adapterName); } return $adapter; }