public function execute(Request $request, ResponseBag $bag)
 {
     $authentication = new AnonymousAuthenticationToken();
     $this->securityContext->setAuthentication($authentication);
     $bag->set(AuthenticationLayer::VAR_NAME, $authentication);
     return "success";
 }
Exemplo n.º 2
0
 protected function buildResponseFromResponseBag(ResponseBag $responseBag)
 {
     $result = $responseBag->getResult();
     $resultCode = $responseBag->getResultCode();
     $headers = $responseBag->getHeaders();
     $type = $responseBag->getType();
     if ($type === ResponseBag::TYPE_DEFAULT) {
         return new Response($result, $resultCode, $headers);
     }
     if ($type === ResponseBag::TYPE_STREAMED) {
         $callback = $responseBag->getCallback();
         if (null === $callback) {
             throw new \Exception('Streamed response need callback');
         }
         return new StreamedResponse($callback, $resultCode, $headers);
     }
     if ($type === ResponseBag::TYPE_BINARY) {
         $filepath = $responseBag->get(BinaryOutputBuilder::FILEPATH, null);
         $visibility = $responseBag->get(BinaryOutputBuilder::VISIBILITY_PUBLIC, true);
         $autoEtag = $responseBag->get(BinaryOutputBuilder::AUTO_ETAG, false);
         $autoLastModified = $responseBag->get(BinaryOutputBuilder::AUTO_LAST_MODIFIED, true);
         $contentDisposition = $responseBag->get(BinaryOutputBuilder::CONTENT_DISPOSITION, null);
         return new BinaryFileResponse($filepath, $contentDisposition, $visibility, $autoEtag, $autoLastModified);
     }
 }
Exemplo n.º 3
0
 public function after(ResponseBag $bag)
 {
     $format = $bag->get('format');
     $builder = isset($this->outputBuilders[$format]) ? $this->outputBuilders[$format] : $this->defaultOutputBuilder;
     $data = $builder->buildOutput($bag);
     $headers = $builder->getHeaders($bag);
     foreach ($headers as $header) {
         header($header);
     }
     $bag->setResult($data);
 }
Exemplo n.º 4
0
 public function before(ResponseBag $responseBag, Request $request)
 {
     if ($format = $this->getFormatFromQuery($request)) {
         $responseBag->set('format', $format);
         return;
     }
     if ($format = $this->getFormatFromHeaders($request)) {
         $responseBag->set('format', $format);
         return;
     }
     $responseBag->set('format', $this->defaultFormat);
 }
 public function execute(Request $request, ResponseBag $bag)
 {
     $email = $request->get($this->emailFieldName);
     $password = $request->get($this->passwordFieldName);
     $authenticationToken = $this->serviceAuthentication->login($email, $password);
     if ($this->serviceAuthentication->isLoggedIn($authenticationToken)) {
         $bag->set(AuthenticationLayer::VAR_NAME, $authenticationToken);
         $this->securityContext->setAuthentication($authenticationToken);
         return "success";
     }
     $bag->set('error', 'notfound');
     return "failure";
 }
Exemplo n.º 6
0
 public function after(ResponseBag $bag)
 {
     $this->bag = $bag;
     $actionResult = $bag->get(ResponseBag::ACTION_RESULT, false);
     $hasActionResult = !(false === $actionResult);
     $this->bag->set('request', $this->request);
     if (!$hasActionResult && $this->hasDefaultTemplate()) {
         $bag->setResult($this->getDefaultTemplate());
         return;
     }
     if ($this->hasTemplate($actionResult)) {
         $bag->setResult($this->renderTemplate($actionResult));
         return;
     }
 }
 public function get(Request $request, ResponseBag $bag)
 {
     $restConfiguration = $bag->get('__PyRestConfiguration', new PyRestConfiguration());
     $resourceName = $restConfiguration->getConfig(ResourceNameParser::NAME);
     $resourceId = $restConfiguration->getConfig(ResourceIdParser::NAME);
     $service = $this->getBertheService($resourceName);
     // run query against DAL
     try {
         $result = $service->getById($resourceId);
         $bag->set('data', $result);
         return $result;
     } catch (\Berthe\Exception\NotFoundException $exception) {
         throw new \Pyrite\PyRest\Exception\NotFoundException('Main resource not found', $exception, array('resource' => $resourceName, 'id' => $resourceId));
     }
 }
Exemplo n.º 8
0
 protected function after(ResponseBag $bag)
 {
     $out = self::PLACEHOLDER_DEFAULT;
     $template = $this->config[0];
     if (count($this->config) > 1) {
         $out = $this->config[1];
     }
     $path = $this->viewPath . '/' . $template;
     $view = new View($path, $bag);
     $content = $view->render();
     if ($out == self::PLACEHOLDER_DEFAULT) {
         $bag->setResult($content);
     } else {
         $bag->set('__placeholder__' . $out, $content);
     }
 }
Exemplo n.º 9
0
 /**
  * @param ResponseBag $bag
  * @param string|null        $filepath
  * @param null|bool        $disposition
  * @param bool|true   $visibility
  * @param bool|false  $autoEtag
  * @param bool|true   $autoLastModified
  */
 public static function makeBinaryResponse(ResponseBag $bag, $filepath = null, $disposition = null, $visibility = true, $autoEtag = false, $autoLastModified = true)
 {
     $bag->set(BinaryOutputBuilder::AUTO_ETAG, $autoEtag);
     $bag->set(BinaryOutputBuilder::VISIBILITY_PUBLIC, $visibility);
     $bag->set(BinaryOutputBuilder::AUTO_LAST_MODIFIED, $autoLastModified);
     $bag->set(BinaryOutputBuilder::FILEPATH, $filepath);
     $bag->set(BinaryOutputBuilder::CONTENT_DISPOSITION, $disposition);
 }
Exemplo n.º 10
0
 /**
  * @param             $actionResult
  * @param ResponseBag $bag
  */
 public function redirect($actionResult, ResponseBag $bag)
 {
     $redirectionPath = $bag->get(RedirectionFromBagLayer::REDIRECTION_BAG_KEY);
     $bag->setResultCode(Response::HTTP_FOUND);
     $bag->addHeader('Location', $redirectionPath);
 }
Exemplo n.º 11
0
 public function optionsItem(ResponseBag $bag)
 {
     $metaSerializer = $this->container->get('PyRestMetaSerializer');
     $this->pycfg->parseRequest($this->request);
     $bag->set('__PyRestConfiguration', $this->pycfg);
     $result = $this->nextLayer($bag);
     $resultRest = $this->transform(array($result));
     $output = $metaSerializer->serializeOne(reset($resultRest), array());
     $bag->set('data', array("meta" => $output));
     return $bag;
 }
Exemplo n.º 12
0
 public function getHeaders(ResponseBag $bag)
 {
     if (!$bag->has(self::FILENAME)) {
         throw new \Exception('Missing filename for streamed response');
     }
     $bag->addHeader('X-Sendfile', $bag->get(self::FILENAME));
     $bag->addHeader('X-Accel-Buffering', 'no');
     $bag->addHeader('Transfer-Encoding', 'chunked');
     $bag->addHeader('Content-Type', 'application/force-download');
     $bag->addHeader('Content-Disposition', sprintf('%s; filename="%s"', $bag->get(self::ATTACHMENT_DISPOSITION, 'attachment'), $bag->get(self::FILENAME)));
     return $bag->getHeaders();
 }
Exemplo n.º 13
0
 public function after(ResponseBag $bag)
 {
     $view = sprintf("<h1>DEBUG MODE</h1>\n<br />%s %s %s %s %s", $this->getRequest(), $this->getServer(), $this->getPost(), $this->getGet(), $this->getSession());
     $bag->set('view', $bag->get('view') . $view);
 }
Exemplo n.º 14
0
 public function buildOutput(ResponseBag $bag)
 {
     return xmlrpc_encode($bag->get('data'));
 }
Exemplo n.º 15
0
 public function redirect($actionResult, ResponseBag $bag)
 {
     $redirectionPath = $bag->get(RedirectionFromBagLayer::REDIRECTION_BAG_KEY);
     $bag->setResultCode(302);
     header("Location: " . $redirectionPath);
 }
Exemplo n.º 16
0
 public function buildOutput(ResponseBag $bag)
 {
     return '<pre>' . print_r($bag->get('data'), true) . '</pre>';
 }
Exemplo n.º 17
0
 public function redirect($redirectionPath, ResponseBag $responseBag)
 {
     $responseBag->addHeader('Location', $redirectionPath);
 }
Exemplo n.º 18
0
 public function getHeaders(ResponseBag $bag)
 {
     return $bag->getHeaders();
 }
Exemplo n.º 19
0
 public function buildOutput(ResponseBag $bag)
 {
     return json_encode($bag->get('data'), JSON_NUMERIC_CHECK);
 }