/** * Cleanup the cookie support check */ public function cleanupCheck() { if ($this->request->getUrl()->hasParam('_checkCookie') && isset($_COOKIE[self::CHECK_COOKIE])) { $requestUri = $this->request->getUrl()->without('_checkCookie'); $this->request->getResponse()->redirectAndExit($requestUri); } }
/** * @param Request $request * @return void * @throws RendererException */ public function render(Request $request) { $response = $request->getResponse(); $contentType = $request->getContentType(); if ('json' === $contentType) { $renderer = new JsonRenderer(); } else { if ('xml' === $contentType) { $renderer = new XmlRenderer(); } else { if ('rss' === $contentType) { $renderer = new RssRenderer(); } else { if ('html' === $contentType) { $renderer = new HtmlRenderer(); } else { $renderer = new HtmlRenderer(); $e = new RendererException('Content type missing or invalid', Response::NOT_FOUND); $response->setException($e); } } } } $body = $renderer->render($request, $response); $response->sendHeaders(); exit($body); }
public function dispatch(Request $request) { if (!$request->isInit()) { $request->init(); } $request->process(); return $this->lastResponse = $request->getResponse(); }
function generateJson() { date_default_timezone_set('Asia/Dhaka'); $time1 = new DateTime(date('Y-m-d h:i:s')); $time2 = new DateTime(date('Y-m-d h:i:s', filectime('cache/dseData.json'))); $interval = $time1->diff($time2); if ($interval->i > 0 || file_exists('cache/dseData.json') === false) { unlink('cache/dseData.json'); $api = new Request(); saveCache('cache', "dseData.json", $api->getResponse('json')); } }
public function createConsignment(ConsignmentRequest $consignmentRequest) { $recipient = $consignmentRequest->getRecipient(); if ($recipient == null) { $recipient = new Recipient(); } $labelsRequest = $consignmentRequest->getLabelsRequest(); $consignmentArray = array('transport_service_id' => $consignmentRequest->getTransportServiceId(), 'address_state' => $recipient->getCountry(), 'register_branch_id' => $consignmentRequest->getRegisterBranchId(), 'destination_branch_id' => $consignmentRequest->getDestinationBranchId(), 'order_number' => $consignmentRequest->getOrderNumber(), 'partner_consignment_id' => $consignmentRequest->getPartnerConsignmentId(), 'parcel_count' => $consignmentRequest->getParcelCount(), 'weight' => $consignmentRequest->getWeight(), 'cash_on_delivery' => $consignmentRequest->getCashOnDelivery(), 'insurance' => $consignmentRequest->getInsurance(), 'stated_price' => $consignmentRequest->getStatedPrice(), 'currency' => $consignmentRequest->getCurrency(), 'variable' => $consignmentRequest->getValiable(), 'password' => $consignmentRequest->getPassword(), 'customer_name' => $recipient->getName(), 'customer_surname' => $recipient->getSurname(), 'company_name' => $recipient->getCompany(), 'customer_phone' => $recipient->getPhone(), 'customer_email' => $recipient->getEmail(), 'address_street' => $recipient->getStreet(), 'address_town' => $recipient->getTown(), 'address_zip' => $recipient->getZip(), 'allow_card_payment' => $consignmentRequest->getAllowCardPayment() ? 1 : 0, 'require_full_age' => $consignmentRequest->getRequireFullAge() ? 1 : 0, 'note' => $consignmentRequest->getNote()); if (isset($labelsRequest)) { $consignmentArray['labels'] = array('type' => $labelsRequest->getType(), 'first_position' => $labelsRequest->getFirstPosition(), 'labels_per_page' => $labelsRequest->getLabelsPerPage()); } $request = new Request($this->apiUrl, $this->shopId, $this->apiKey); $request->setType('POST'); $request->setResource(self::CONSIGNMENT_RESOURCE); $request->setData($consignmentArray); $response = $request->getResponse(); if ($response->isError()) { $this->errors = $response->getErrors(); return false; } else { $data = $response->getData(); return new Consignment($data[0]); } }
public function createByPath($path, RequestOptions $options) { return parent::getResponse(self::METHOD_POST, $path, $options); }
public static function deleteByPath($path, RequestOptions $options = null) { return parent::getResponse(self::METHOD_DELETE, $path, $options); }
public function execute() { $from_class = $this->from; $url = new URL($this->app, $from_class::getResourceURI()); $request = new Request($this->app, $url, Request::METHOD_GET); $where = $this->getWhere(); if (!empty($where)) { $request->setParameter('where', $where); } if ($this->order !== null) { $request->setParameter('order', $this->order); } if ($this->modifiedAfter !== null) { $request->setHeader('If-Modified-Since', $this->modifiedAfter); } if ($this->page !== null) { $request->setParameter('page', $this->page); } if ($this->offset !== null) { $request->setParameter('offset', $this->offset); } $request->send(); $elements = array(); foreach ($request->getResponse()->getElements() as $element) { $built_element = new $from_class($this->app); $built_element->fromStringArray($element); $elements[] = $built_element; } return $elements; }
/** * Perform a GET request to the API * * @param $path * @param RequestOptions $options * * @return string */ public static function getByPath($path, RequestOptions $options = null) { return parent::getResponse(self::METHOD_GET, $path, $options); }