private function secure() { $data = $this->request->getBasicAuth(); if (!$data || !(isset($data['username']) && $data['username'] == $this->config->auth->username && (isset($data['password']) && $data['password'] == $this->config->auth->password))) { $response = new Response(); $response->status = $response::STATUS_FORBIDDEN; $response->code = $response::CODE_ERROR; $response->addError('not right username and password'); return $response->toArray(); } }
public function signupAction() { $this->view->disable(); if ($this->request->isAjax()) { $data = $this->request->getPost(); $response = new Response(); $response->assign(array('uuid' => $this->gen_uuid())); if ($response->save()) { // $this->persistent->uuid = $response->uuid; echo json_encode($response->toArray()); // echo json_encode(true); } else { echo json_encode(false); } } }
public static function create($data) { $response = new Response(); try { $data = json_decode($data, true); /** @var Products $products */ $category = new Categories(); $category->setAttributes($data); $response->data = $category->create(); $response->status = $response::STATUS_CREATED; } catch (Exception $e) { $response->setException($e); } finally { return $response->toArray(); } }
public static function create($data) { $response = new Response(); try { $data = json_decode($data, true); /** @var Robots $robot */ $robot = new Robots(); $robot->setAttributes($data); $response->data = $robot->create(); $response->status = $response::STATUS_CREATED; } catch (Exception $e) { $response->setException($e); } finally { return $response->toArray(); } }
/** * Import values from external Response instance * * Calling import() will clear all previously assigned values before assigning those from the * new Response instance. * * @param \Arya\Response $response * @return Response Returns the current object instance */ public function import(Response $response) { $this->clear(); foreach ($response->toArray() as $key => $value) { $this->offsetSet($key, $value); } return $this; }
public function testGetCurlInfoFromArray() { $curlOptions = array('option' => 'value'); $response = new Response(200); $response->setInfo($curlOptions); $restoredResponse = Response::fromArray($response->toArray()); $this->assertEquals($curlOptions, $restoredResponse->getInfo()); }
public static function create($data) { $response = new Response(); try { $data = json_decode($data, true); $category = Categories::findFirst($data->categoryId); if ($category !== FALSE) { /** @var Products $products */ $product = new Products(); $product->setAttributes($data); $response->data = $product->create(); $response->status = $response::STATUS_CREATED; } else { $response->status = $response::STATUS_BAD_REQUEST; $response->addError('CATEGORIES_NOT_FOUND'); } } catch (Exception $e) { $response->setException($e); } finally { return $response->toArray(); } }
/** * @param Request $request * @param Response $response * @return string */ public function render(Request $request, Response $response) { $response->setContentTypeHeader('rss'); $data = $response->toArray(); $body = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"; $body .= '<rss version="2.0">' . "\r\n"; $body .= ' <channel>' . "\r\n"; if (isset($response->channel) && is_array($response->channel)) { foreach ($response->channel as $key => $value) { $body .= ' <' . $key . '>' . htmlspecialchars($value) . '</' . $key . '>' . "\r\n"; } } if (isset($response->items) && is_array($response->items)) { $body .= $this->serialize($response->items, 1); } $body .= ' </channel>' . "\r\n"; $body .= '</rss>' . "\r\n"; return $body; }