Exemplo n.º 1
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.º 2
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";
 }
 public function execute(Request $request, ResponseBag $bag)
 {
     $authentication = new AnonymousAuthenticationToken();
     $this->securityContext->setAuthentication($authentication);
     $bag->set(AuthenticationLayer::VAR_NAME, $authentication);
     return "success";
 }
 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.º 6
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.º 7
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.º 8
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;
 }