Exemple #1
0
 /**
  * Shortcut for rendering a template
  * @param string $templateName the name of the template
  * @param array $params the template parameters in key => value structure
  * @param string $renderAs user renders a full page, blank only your template
  *                          admin an entry in the admin settings
  * @param array $headers set additional headers in name/value pairs
  * @return \OCA\Music\AppFramework\Http\TemplateResponse containing the page
  */
 public function render($templateName, array $params = array(), $renderAs = 'user', array $headers = array())
 {
     $response = new TemplateResponse($this->api, $templateName);
     $response->setParams($params);
     $response->renderAs($renderAs);
     foreach ($headers as $name => $value) {
         $response->addHeader($name, $value);
     }
     return $response;
 }
 /**
  * If an AmpacheException is being caught, the appropiate ampache
  * exception response is rendered
  * @param Controller $controller the controller that is being called
  * @param string $methodName the name of the method that will be called on
  *                           the controller
  * @param \Exception $exception the thrown exception
  * @throws \Exception the passed in exception if it cant handle it
  * @return Response a Response object or null in case that the exception could not be handled
  */
 public function afterException($controller, $methodName, \Exception $exception)
 {
     if ($exception instanceof AmpacheException && $this->isAmpacheCall) {
         $response = new TemplateResponse($this->api, 'ampache/error');
         $response->renderAs('blank');
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
         $response->setparams(array('code' => $exception->getCode(), 'message' => $exception->getMessage()));
         return $response;
     }
     throw $exception;
 }