/** * Perform action and generate response * * @param RequestInterface $request * @return ResponseInterface|\Magento\Framework\Controller\ResultInterface * @throws \LogicException */ public function dispatch(RequestInterface $request) { \Magento\Framework\Profiler::start('routers_match'); $routingCycleCounter = 0; $result = null; while (!$request->isDispatched() && $routingCycleCounter++ < 100) { /** @var \Magento\Framework\App\RouterInterface $router */ foreach ($this->_routerList as $router) { try { $actionInstance = $router->match($request); if ($actionInstance) { $request->setDispatched(true); $this->response->setNoCacheHeaders(); if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) { $result = $actionInstance->dispatch($request); } else { $result = $actionInstance->execute(); } break; } } catch (\Magento\Framework\Exception\NotFoundException $e) { $request->initForward(); $request->setActionName('noroute'); $request->setDispatched(false); break; } } } \Magento\Framework\Profiler::stop('routers_match'); if ($routingCycleCounter > 100) { throw new \LogicException('Front controller reached 100 router match iterations'); } return $result; }
/** * Generate the oauth_signature parameter * @return string */ public function generateSignature() { $keyString = rawurlencode($this->consumer->getSecret()) . '&'; if ($this->accessCredential !== null) { $keyString .= \rawurlencode($this->accessCredential->getSecret()); } $baseString = $this->request->getBaseString(self::SIGNATURE_METHOD); return \base64_encode(hash_hmac('sha1', $baseString, $keyString, true)); }
/** * Assemble a base path for this page request. * For whatever reason, php doesn't include this concept natively. * * @return string */ public function render() { $return = $this->http_request->getUriForPath('/'); if (!is_null($this->scheme)) { $return = $this->scheme . substr($return, strpos($return, ':')); } $this->scheme = null; return $return; }
public function __construct(RequestInterface &$request) { if (!\in_array($request->getProtocolVersion(), ['HTTP/1.0', 'HTTP/1.1'], true)) { $this->setStatus(505); $this->isComplete = true; } $this->request = $request; $this->protocolVersion = $request->getProtocolVersion(); $this->headers = new HeaderCollection(HeaderCollection::FOR_RESPONSE); }
/** * @param array $ips * @return bool */ protected function searchEngineCheck(array $ips) { // Search engines don't use IPv6 I guess if ($this->request->getIp()->isV6()) { return false; } if ($this->request->getIp()->matchCidr($ips) === false) { return true; } return false; }
/** * Constructor. * * @param CentralAuthenticationStore $cas Shared instance of the CentralAuthenticationStore class. * @param LoggerInterface $logger Shared instance of a Logger class. * @param Curl $curl Shared instance of the Curl class. * @param RequestInterface $request Shared instance of a Request class. */ public function __construct($cas, $logger, $curl, $request) { parent::__construct($cas, $logger, $curl); $this->state = $request->get_get_data('state'); $this->code = $request->get_get_data('code'); $this->redirect_uri = $request->base_url . $request->call; $this->scope = NULL; $this->token_expires = 0; if ($this->state === NULL) { $this->state = md5(uniqid(rand(), TRUE)); } }
/** * Testcase Constructor. */ public function setUp() { $this->cas = $this->getMock('Lunr\\Spark\\CentralAuthenticationStore'); $this->curl = $this->getMock('Lunr\\Network\\Curl'); $this->logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->request = $this->getMock('Lunr\\Corona\\RequestInterface'); $this->response = $this->getMockBuilder('Lunr\\Network\\CurlResponse')->disableOriginalConstructor()->getMock(); $this->request->expects($this->at(0))->method('get_get_data')->with($this->equalTo('state'))->will($this->returnValue('String')); $this->request->expects($this->at(1))->method('get_get_data')->with($this->equalTo('code'))->will($this->returnValue('String')); $this->request->expects($this->exactly(2))->method('__get')->will($this->onConsecutiveCalls('http://localhost/', 'controller/method/')); $this->class = new Authentication($this->cas, $this->logger, $this->curl, $this->request); $this->reflection = new ReflectionClass('Lunr\\Spark\\Facebook\\Authentication'); }
/** * Perform action and generate response * * @param RequestInterface $request * @return ResponseInterface|\Magento\Framework\Controller\ResultInterface * @throws \LogicException */ public function dispatch(RequestInterface $request) { \Magento\Framework\Profiler::start('routers_match'); $routingCycleCounter = 0; $result = null; while (!$request->isDispatched() && $routingCycleCounter++ < 100) { $result = $this->processRequest($request); } \Magento\Framework\Profiler::stop('routers_match'); if ($routingCycleCounter > 100) { throw new \LogicException('Front controller reached 100 router match iterations'); } return $result; }
/** * @param $store * @param $country * @return array */ protected function _fetchHppMethods($store, $country) { $skinCode = $this->_adyenHelper->getAdyenHppConfigData('skin_code'); $merchantAccount = $this->_adyenHelper->getAdyenAbstractConfigData('merchant_account'); if (!$skinCode || !$merchantAccount) { return []; } $adyFields = ["paymentAmount" => (int) $this->_adyenHelper->formatAmount($this->_getCurrentPaymentAmount(), $this->_getCurrentCurrencyCode($store)), "currencyCode" => $this->_getCurrentCurrencyCode($store), "merchantReference" => "Get Payment methods", "skinCode" => $skinCode, "merchantAccount" => $merchantAccount, "sessionValidity" => date(DATE_ATOM, mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y"))), "countryCode" => $this->_getCurrentCountryCode($store, $country), "shopperLocale" => $this->_getCurrentLocaleCode($store)]; $responseData = $this->_getDirectoryLookupResponse($adyFields, $store); $paymentMethods = []; if (isset($responseData['paymentMethods'])) { foreach ($responseData['paymentMethods'] as $paymentMethod) { $paymentMethodCode = $paymentMethod['brandCode']; $paymentMethod = $this->_fieldMapPaymentMethod($paymentMethod); // check if payment method is an openinvoice method $paymentMethod['isPaymentMethodOpenInvoiceMethod'] = $this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($paymentMethodCode); // add icon location in result if ($this->_adyenHelper->showLogos()) { $params = []; // use frontend area $params = array_merge(['area' => 'frontend', '_secure' => $this->_request->isSecure()], $params); $asset = $this->_assetRepo->createAsset('Adyen_Payment::images/logos/' . $paymentMethodCode . '.png', $params); $placeholder = $this->_assetSource->findSource($asset); $icon = null; if ($placeholder) { list($width, $height) = getimagesize($asset->getSourceFile()); $icon = ['url' => $asset->getUrl(), 'width' => $width, 'height' => $height]; } $paymentMethod['icon'] = $icon; } $paymentMethods[$paymentMethodCode] = $paymentMethod; } } return $paymentMethods; }
/** * @param $methodName * @param RequestInterface $request * @return mixed */ public function call($endpoint, $request) { $client = new Client(['verify' => false]); $parameters = array_merge($this->config->getParameterArray(), $request->getParameterArray()); try { $res = $client->request($request->method, $this->url . $endpoint, array_merge(['headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json', 'Client-Secret' => $this->config->clientSecret, 'Access-Token' => $this->config->accessToken]], $parameters)); $this->response = $res; return $res; } catch (\Exception $e) { preg_match('/{"ErrorInformation":{"Error":(\\d+),"Message":"(.+)","Code":(\\d+)}/i', $e->getMessage(), $matches); if (isset($matches[0])) { throw new Exception(sprintf("ERROR: %s (%s)", Util::removeUnicodeSequences($matches[2]), $matches[3]), $matches[3]); } throw $e; } return false; }
/** * @return bool */ protected function httpbl() { if ($this->request->getIp()->isV6()) { return false; } $httpbl = new HttpBL($this->settings['httpbl_key']); $result = $httpbl->query($this->request->getIp()); }
/** * Delete chunks dir */ public function deleteChunks() { $totalChunks = $this->request->getTotalChunks(); for ($i = 1; $i <= $totalChunks; $i++) { $path = $this->getChunkPath($i); if (file_exists($path)) { unlink($path); } } }
/** * Parse URI to determine controller, action and params part of the URI * * @return void */ protected function parseUri() { if (empty($_SERVER["REQUEST_URI"])) { return false; } // Get request URL without the forward slash "/" $path = trim(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/"); // The URL consists of controller, action and an array of parameters @(list($this->url['controller'], $this->url['action'], $this->url['params']) = explode("/", $path, 3)); // Check if controller is present if (!empty($this->url['controller'])) { $this->setController($this->url['controller']); } // Check if action is present if (!empty($this->url['action'])) { $this->setAction($this->url['action']); } // Check if parameters are present if (!empty($this->url['params'])) { $this->request->setParams(explode("/", $this->url['params'])); } }
/** * Rendering layout * * @param string $output * @return $this */ public function renderLayout($output = '') { if ($this->_actionFlag->get('', 'no-renderLayout')) { return $this; } \Magento\Framework\Profiler::start('LAYOUT'); \Magento\Framework\Profiler::start('layout_render'); if ('' !== $output) { $this->getLayout()->addOutputElement($output); } $this->_eventManager->dispatch('controller_action_layout_render_before'); $this->_eventManager->dispatch('controller_action_layout_render_before_' . $this->_request->getFullActionName()); $this->page->renderResult($this->_response); \Magento\Framework\Profiler::stop('layout_render'); \Magento\Framework\Profiler::stop('LAYOUT'); return $this; }
/** * Do request and return response. * * @return object * * @throws \Exception */ protected function fire() { $response = null; try { $url = $this->getRequestUrl(); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } try { $response = $this->requester->doRequest($url); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } if ($response) { $jsonResponse = json_decode($response); if (isset($jsonResponse->error)) { throw new \Exception('API error: ' . $jsonResponse->error); } return $jsonResponse; } throw new \Exception('Empty response'); }
/** * @param Order $order */ public function completePayment(Order $order) { $resultCode = $this->request->get('ResCode'); $referenceId = $this->request->get('RefId'); $orderId = $this->request->get('SaleOrderId'); $referenceCode = $this->request->get('SaleReferenceId'); $cardHolderInfo = $this->request->get('CardHolderInfo'); $cardHolderPan = $this->request->get('CardHolderPan'); if ($resultCode != '0') { throw new BankWebserviceException($resultCode); } $order->setCardHolderInfo($cardHolderInfo); $order->setCardHolderPan($cardHolderPan); $order->setReferenceId($referenceId); $order->setReferenceCode($referenceCode); $order->setOrderId($orderId); if ($this->verifyOrder($order)) { $this->gateway->settlePayment($order); } else { $this->gateway->refundPayment($order); } }
/** * Builds canonical string from request. * * @param RequestInterface $request Request to get canonical string from. * * @return string */ public function getCanonicalString($request) { $parts = array($request->getHeader('content-type'), $request->getHeader('content-md5'), $request->getPath() . $request->getQuery(), $request->getHeader('date')); return join(',', $parts); }
/** * Given a request object, return an array of the various request * fragments that would correspond to the various route types. This is * useful for evaluating the request against the routes. * * @param RequestInterface $request * * @return array */ public static function getPathsByRouteType(RequestInterface $request) { $entire_uri_without_queries = strpos($request->getUri(), '?') !== false ? substr($request->getUri(), 0, strpos($request->getUri(), '?')) : $request->getUri(); $return = array(Route::ROUTE_TYPE_ABSOLUTE_PROTOCOL => $entire_uri_without_queries, Route::ROUTE_TYPE_ABSOLUTE_PROTOCOL_WITH_WILDCARDS => $entire_uri_without_queries, Route::ROUTE_TYPE_ABSOLUTE_DOMAIN => '//' . $request->getHost() . $request->getPathInfo(), Route::ROUTE_TYPE_ABSOLUTE_DOMAIN_WITH_WILDCARDS => '//' . $request->getHost() . $request->getPathInfo(), Route::ROUTE_TYPE_ABSOLUTE_PATH => $request->getPathInfo(), Route::ROUTE_TYPE_ABSOLUTE_PATH_WITH_WILDCARDS => $request->getPathInfo()); return $return; }
/** * Generate chunk identifier * * @param RequestInterface $request * * @return string */ public static function hashNameCallback(RequestInterface $request) { return sha1($request->getIdentifier()); }
public function isSpambot(RequestInterface $request) { return $this->checkUri($request->getRequestUri()) || $this->checkUserAgent($request->getUserAgent()); }
/** * @param RequestInterface $request */ public function add(RequestInterface $request) { $this->requests[$request->getId()] = $request; }
/** * Send the response to the client. * @param RequestInterface|null $req optional request object that triggered this response * @return self * @codeCoverageIgnore */ public function send(RequestInterface $req = null) { $seekBeg = 0; $seekEnd = -1; // modify response according to request if ($req) { // process cached response (not modified) if ($req->hasHeader('If-Modified-Since') && $this->hasHeader('Last-Modified')) { $cached = strtotime($req->getHeader('If-Modified-Since')); $current = strtotime($this->getHeader('Last-Modified')); if ($cached === $current) { $this->setStatusCode(304); } } // process cached response (ETag) if ($req->hasHeader('If-None-Match') && $this->hasHeader('ETag')) { if ($req->getHeader('If-None-Match') === $this->getHeader('ETag')) { $this->setStatusCode(304); } } // process chunks if ($req->hasHeader('Range') && $this->hasHeader('Content-Length')) { $size = (int) $this->getHeader('Content-Length'); $range = $req->getHeader('Range'); $this->setHeader('Accept-Ranges', 'bytes'); try { if (!preg_match('@^bytes=\\d*-\\d*(,\\d*-\\d*)*$@', $range)) { throw new \Exception('Invalid range'); } $range = current(explode(',', substr($range, 6))); list($seekBeg, $seekEnd) = explode('-', $range, 2); $seekBeg = max((int) $seekBeg, 0); $seekEnd = !(int) $seekEnd ? $size - 1 : min((int) $seekEnd, $size - 1); if ($seekBeg > $seekEnd) { throw new \Exception('Invalid range'); } $this->setStatusCode(206); $this->setHeader('Content-Range', 'bytes ' . $seekBeg . '-' . $seekEnd . '/' . $size); $seekEnd = $seekEnd - $seekBeg; } catch (\Exception $e) { $this->setStatusCode(416); $this->setHeader('Content-Range', 'bytes * /' . $size); $this->body = null; } } } if (!headers_sent()) { if ($this->getHeader('Location') && $this->code !== 201 && $this->code !== 202 && floor($this->code / 100) !== 3) { $this->setStatusCode(302); } http_response_code($this->code); foreach ($this->getHeaders() as $k => $v) { header($k . ': ' . $v); } foreach ($this->cookies as $k => $v) { header('Set-Cookie: ' . $k . '=' . urlencode($v[0]) . '; ' . $v[1], false); } } if ($this->body && !in_array($this->getStatusCode(), [204, 304, 416]) && (!$req || $req->getMethod() !== 'HEAD')) { $out = fopen('php://output', 'w'); stream_copy_to_stream($this->body, $out, $seekEnd, $seekBeg); fclose($out); } return $this; }
/** * Get controller key * * @return string */ protected function _getControllerKey() { return $this->_request->getRouteName() . '_' . $this->_request->getControllerName(); }
/** * Test that an actual HTTP-request is sent (and received) * */ public function testRequestIsSent() { $this->assertSame('1', $this->method->request($this->serverUrl, true)); }