예제 #1
0
파일: TokenFactory.php 프로젝트: payum/core
 /**
  * {@inheritDoc}
  */
 protected function generateUrl($path, array $parameters = [])
 {
     $newPath = $this->baseUrl->path->withTrailingSlash() . $path;
     $uri = $this->baseUrl->withPath($newPath);
     $uri = $this->addQueryToUri($uri, $parameters);
     return (string) $uri;
 }
예제 #2
0
 /**
  * @param HttpUri $uri
  * @param array $query
  *
  * @return HttpUri
  */
 protected function addQueryToUri(HttpUri $uri, array $query)
 {
     $query = array_replace($uri->query->toArray(), $query);
     $query = array_filter($query, function ($value) {
         return null !== $value;
     });
     return $uri->withQuery((string) Query::createFromArray($query));
 }
예제 #3
0
파일: ID.php 프로젝트: cs50/php
 /**
  * Authenticates user via CS50 ID. If user is returning from CS50 ID,
  * returns associative array of user's claims, else redirects to CS50 ID
  * for authentication.
  *
  * @param string client_id
  * @param string client_secret
  * @param string scope
  *
  * @return array claims
  */
 public static function authenticate($client_id, $client_secret, $scope = "openid profile")
 {
     // validate scope
     // https://tools.ietf.org/html/rfc6749#appendix-A.4
     if (!preg_match("/^[\\x{21}\\x{23}-\\x{5B}\\x{5D}-\\x{7E}]([ \\x{21}\\x{23}-\\x{5B}\\x{5D}-\\x{7E}])*\$/", $scope)) {
         trigger_error("invalid scope", E_USER_ERROR);
     }
     // redirection URI
     try {
         // sans username and password (and fragment)
         $uri = \League\Uri\Schemes\Http::createFromServer($_SERVER)->withUserInfo("");
         // sans code and state (which are reserved by OAuth2)
         $modifier = new \League\Uri\Modifiers\RemoveQueryKeys(["code", "state"]);
         $redirect_uri = $modifier->__invoke($uri)->__toString();
     } catch (\Exception $e) {
         trigger_error("unable to infer redirect_uri", E_USER_ERROR);
     }
     // configure client
     $id = new ID($client_id, $client_secret, $redirect_uri, $scope);
     // if user is returning from CS50 ID, return claims
     if (isset($_GET["code"], $_GET["state"])) {
         return $id->getUser();
     }
     // redirect to CS50 ID
     header("Location: " . $id->getLoginUrl());
     exit;
 }
예제 #4
0
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     /** @var $request Capture */
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     $response = ArrayObject::ensureArrayObject($httpRequest->request);
     if (isset($httpRequest->query['cancelled'])) {
         $newResponse['CANCELLED'] = true;
         $model->replace($newResponse);
         return;
     }
     if ($response['txn_id'] != null) {
         $response->validateNotEmpty(['payment_status', 'business', 'invoice', 'txn_id', 'mc_gross']);
         $this->gateway->execute(new Sync($response));
         $model->replace($response);
     } else {
         if ($model['cancel_return']) {
             $cancelUri = HttpUri::createFromString($model['cancel_return']);
             $modifier = new MergeQuery('cancelled=1');
             $cancelUri = $modifier($cancelUri);
             $model['cancel_return'] = (string) $cancelUri;
         }
         $this->gateway->execute(new CreateButtonPayment($model));
     }
 }
예제 #5
0
파일: UriBuilder.php 프로젝트: apivore/core
 public function create(string $uri, array $query)
 {
     $query = Query::createFromPairs($query);
     $uri = Http::createFromString($uri);
     $modifier = new MergeQuery($query->__toString());
     return (string) $modifier->__invoke($uri);
 }
 /**
  * @Route("/session/origins", name="oidc_get_origins")
  * @Method({"GET"})
  * @Template
  */
 public function getOriginsAction(Request $request)
 {
     $client = $this->getClient($request->get('client_id'));
     $uris = array();
     $uris[] = $client->getSiteUrl();
     $uris[] = $client->getTermsOfUseUrl();
     $uris[] = $client->getLandingPageUrl();
     if ($client->getMetadata()) {
         $meta = $client->getMetadata();
         $uris[] = $meta->getClientUri();
         $uris[] = $meta->getInitiateLoginUri();
         $uris[] = $meta->getPolicyUri();
         $uris[] = $meta->getSectorIdentifierUri();
         $uris[] = $meta->getTosUri();
         $uris = array_merge($uris, $meta->getRedirectUris(), $meta->getRequestUris());
     }
     $result = array_unique(array_map(function ($value) {
         if ($value === null) {
             return;
         }
         $uri = HttpUri::createFromString($value)->withFragment('')->withPath('')->withQuery('')->withUserInfo('');
         return $uri->__toString();
     }, array_filter($uris)));
     return new JsonResponse(array_values($result));
 }
 public function getAuthenticatedRequest($method, $url, $token, array $options = [])
 {
     $baseUri = HttpUri::createFromString($this->urlApiDomain);
     $relativeUri = HttpUri::createFromString($url);
     $modifier = new Resolve($baseUri);
     $newUri = $modifier->__invoke($relativeUri);
     return parent::getAuthenticatedRequest($method, $newUri, $token, $options);
 }
예제 #8
0
 public function testDateSetter()
 {
     $url = new LinkedEntity();
     $url->id = 2;
     $url->link = Uri\Schemes\Http::createFromString("http://github.com/kayladnls?q=is%3Aopen+is%3Apr+author%3Akayladnls");
     $this->em->persist($url);
     $this->em->flush();
 }
예제 #9
0
 public function fetch($url)
 {
     $url = Http::createFromString($url);
     if (!$this->parser instanceof ParserInterface) {
         throw new \Exception('Must be a Parse Interface object.');
     }
     if ($this->parser->checkUrl($url)) {
         $document = $this->getUrl($url);
         return $document;
     }
 }
예제 #10
0
 /**
  * Format an URL to be fully-qualified
  *
  * @param string $value
  * @return string
  **/
 public function format($value)
 {
     if (!$this->validate($value)) {
         throw new \InvalidArgumentException("`{$value}` is not a valid HTTP URI");
     }
     $url = Http::createFromString($value);
     if ($url->getScheme() == '') {
         $url = $url->withScheme('http');
     }
     return (string) $url;
 }
예제 #11
0
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request Capture */
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     $details->validateNotEmpty('PAYMENTREQUEST_0_PAYMENTACTION');
     $details->defaults(array('AUTHORIZE_TOKEN_USERACTION' => Api::USERACTION_COMMIT));
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     if (isset($httpRequest->query['cancelled'])) {
         $details['CANCELLED'] = true;
         return;
     }
     if (false == $details['TOKEN']) {
         if (false == $details['RETURNURL'] && $request->getToken()) {
             $details['RETURNURL'] = $request->getToken()->getTargetUrl();
         }
         if (false == $details['CANCELURL'] && $request->getToken()) {
             $details['CANCELURL'] = $request->getToken()->getTargetUrl();
         }
         if (empty($details['PAYMENTREQUEST_0_NOTIFYURL']) && $request->getToken() && $this->tokenFactory) {
             $notifyToken = $this->tokenFactory->createNotifyToken($request->getToken()->getGatewayName(), $request->getToken()->getDetails());
             $details['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyToken->getTargetUrl();
         }
         if ($details['CANCELURL']) {
             $cancelUri = HttpUri::createFromString($details['CANCELURL']);
             $modifier = new MergeQuery('cancelled=1');
             $cancelUri = $modifier($cancelUri);
             $details['CANCELURL'] = (string) $cancelUri;
         }
         $this->gateway->execute(new SetExpressCheckout($details));
         if ($details['L_ERRORCODE0']) {
             return;
         }
     }
     $this->gateway->execute(new Sync($details));
     if ($details['PAYERID'] && Api::CHECKOUTSTATUS_PAYMENT_ACTION_NOT_INITIATED == $details['CHECKOUTSTATUS'] && $details['PAYMENTREQUEST_0_AMT'] > 0) {
         if (Api::USERACTION_COMMIT !== $details['AUTHORIZE_TOKEN_USERACTION']) {
             $confirmOrder = new ConfirmOrder($request->getFirstModel());
             $confirmOrder->setModel($request->getModel());
             $this->gateway->execute($confirmOrder);
         }
         $this->gateway->execute(new DoExpressCheckoutPayment($details));
     }
     if (false == $details['PAYERID']) {
         $this->gateway->execute(new AuthorizeToken($details));
     }
     $this->gateway->execute(new Sync($details));
 }
 protected function applyFormatParameterToUrls(array $data)
 {
     return array_map(function ($value) {
         if (is_array($value)) {
             return $this->applyFormatParameterToUrls($value);
         }
         $pattern = sprintf('/%s.+/', preg_quote(url(config('transfugio.rootURL')), '/'));
         $format = config('transfugio.http.format');
         if (is_string($value) && preg_match($pattern, $value) && $format !== 'json_accept') {
             $url = Http::createFromString($value);
             //Url::createFromUrl($value);
             $modifiedQuery = new Query($url->getQuery());
             $modifiedQuery = $modifiedQuery->merge("format={$format}");
             $value = strval($url->withQuery($modifiedQuery->__toString()));
         }
         return $value;
     }, $data);
 }
예제 #13
0
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     //we are back from be2bill site so we have to just update model.
     if (empty($httpRequest->query['EXTRADATA'])) {
         throw new HttpResponse('The capture is invalid. Code Be2Bell1', 400);
     }
     $extraDataJson = $httpRequest->query['EXTRADATA'];
     if (false == ($extraData = json_decode($extraDataJson, true))) {
         throw new HttpResponse('The capture is invalid. Code Be2Bell2', 400);
     }
     if (empty($extraData['capture_token'])) {
         throw new HttpResponse('The capture is invalid. Code Be2Bell3', 400);
     }
     $this->gateway->execute($getToken = new GetToken($extraData['capture_token']));
     $uri = HttpUri::createFromString($getToken->getToken()->getTargetUrl());
     $uri = $uri->withQuery((string) Query::createFromArray($httpRequest->query));
     throw new HttpRedirect((string) $uri);
 }
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof ClientMetadata) {
         $this->context->buildViolation('Invalid class')->addViolation();
         return;
     }
     $redirectUris = $this->parseUris($value->getRedirectUris());
     if ($value->getSectorIdentifierUri() !== null) {
         $sectorIdentifier = HttpUri::createFromString();
     } else {
         $sectorIdentifier = null;
     }
     $hosts = array();
     foreach ($redirectUris as $uri) {
         @($hosts[$uri->getHost()] += 1);
     }
     if (!$sectorIdentifier instanceof HttpUri && count($hosts) > 1) {
         $message = 'sector_identifier_uri is required when multiple hosts are used in redirect_uris. (#rfc.section.8.1)';
         $this->context->buildViolation($message)->atPath('sector_identifier_uri')->setParameter('value', $message)->addViolation();
     }
 }
예제 #15
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     return Uri\Schemes\Http::createFromString($value);
 }
예제 #16
0
 /**
  * @return Http
  */
 public function url() : Http
 {
     return Http::createFromString(route('offers.view', [$this->id, $this->slug()]));
 }
예제 #17
0
         $_GET['url'] = substr($_GET['url'], 2);
     } else {
         $_GET['url'] = substr($_GET['url'], 1);
     }
 } elseif (substr($_GET['url'], 0, 25) == 'www.mallublog.vt.vc/goto/') {
     header('X-Notice: Known redirect host, autofix');
     //trigger_error('URL redirects, autofix. URL: '.$_GET['url'],E_USER_NOTICE);
     $_GET['url'] = substr($_GET['url'], 25);
 }
 try {
     if (substr($_GET['url'], 0, 4) == 'ssl:') {
         $_GET['url'] = substr($_GET['url'], 4);
         $uri = HttpUri::createFromString('https://' . $_GET['url']);
     } else {
         if (!substr($_GET['url'], 0, 5) == 'http:' && !substr($_GET['url'], 0, 6) == 'https:') {
             $uri = HttpUri::createFromString('http://' . $_GET['url']);
         } else {
             throw new RuntimeException('Invalid URL');
         }
     }
 } catch (RuntimeException $e) {
     header('HTTP/1.0 404 Not Found');
     header('Content-type: text/plain');
     echo 'Error 404: Server could not parse the ?url= that you were looking for, because it isn\'t a valid url.';
     trigger_error('URL failed, unable to parse. URL: ' . $_GET['url'], E_USER_WARNING);
     die;
 }
 // Create an image manager instance with favored driver (gd by default)
 $imageManager = new Intervention\Image\ImageManager(['driver' => 'imagick']);
 // Create an PHP HTTP client
 $client = new AndriesLouw\imagesweserv\Client(tempnam('/dev/shm', 'imo_'), ['user_agent' => 'Mozilla/5.0 (compatible; ImageFetcher/6.0; +http://images.weserv.nl/)', 'connect_timeout' => 5, 'timeout' => 10, 'max_image_size' => 0, 'max_redirects' => 10, 'allowed_mime_types' => []]);
예제 #18
0
 /**
  * @param $url
  * @param $params
  * @return string
  */
 protected function buildUrl($url, $params)
 {
     return HttpUri::createFromString($url)->withQuery(http_build_query($params))->__toString();
 }
/**
 * The noscheme modifier function
 * @param  string $string URL to parse
 * @return string URL without scheme
 */
function Smarty_Modifier_noscheme($string)
{
    $uri = HttpUri::createFromString($string);
    return (string) $uri->withScheme('');
}
예제 #20
0
 /**
  * @throws \RuntimeException
  *
  * @return Http
  */
 public function url() : Http
 {
     return Http::createFromString(route('category.view', [$this->publicId(), $this->slug()]));
 }
 private function getHost($uri)
 {
     return HttpUri::createFromString($uri)->getHost();
 }
 public function createUriObject($url = '')
 {
     return Http::createFromString($url);
 }
예제 #23
0
파일: Glide.php 프로젝트: trntv/yii2-glide
 /**
  * @param $url
  * @param array $params
  * @return string
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws InvalidConfigException
  */
 public function signUrl($url, array $params = [])
 {
     $uri = Http::createFromString($url);
     $paramsQuery = Query::createFromArray($params);
     $path = $uri->getPath();
     $query = $uri->query->merge($paramsQuery);
     $signature = $this->getHttpSignature()->generateSignature($path, $query->toArray());
     $query = $query->merge(Query::createFromArray(['s' => $signature]));
     $uri = $uri->withQuery((string) $query);
     return (string) $uri;
 }
예제 #24
0
 public function getSectorIdentifier()
 {
     $siUri = $this->getSectorIdentifierUri();
     if ($siUri) {
         $uri = $siUri;
     } else {
         $uris = $this->getRedirectUris();
         $uri = reset($uris);
     }
     return HttpUri::createFromString($uri)->getHost();
 }
 /**
  * @param string  $method
  * @param HttpUri $url
  * @param string  $queryString
  *
  * @return string
  */
 private function getHeaders($method, $url, $queryString)
 {
     $path = $method === 'GET' ? $url->getPath() . "?" . $queryString : $url->getPath();
     $headers = $method . " /" . $path . " HTTP/1.1\r\n";
     $headers .= "Host: " . $url->getHost() . "\r\n";
     $headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $headers .= "Content-Length: " . strlen($queryString) . "\r\n";
     $headers .= "Connection: Close\r\n";
     return $headers;
 }
/**
 * Sanitizes URLS by removing things and adding other things.
 * @param  [type] $url The URL to sanitize.
 * @return [type]      The sanitized URL.
 */
function sanitizeURL($url)
{
    $rulesetMinus = array('imdb.com' => ['ref_', 'pf_rd_m', 'pf_rd_s', 'pf_rd_p', 'pf_rd_r', 'pf_rd_t', 'pf_rd_i'], 'amazon.com' => ['ref_', 'pf_rd_m', 'pf_rd_s', 'pf_rd_p', 'pf_rd_r', 'pf_rd_t', 'pf_rd_i', 'qid', 'psc', 'keywords', 'sr', 'ref', 'refRID', 'btkr', 'ie', 'camp', 'creative', 'creativeASIN', 'linkCode', 'tag', 'linkID', 'redirect'], 'amazon.co.uk' => ['ref_', 'pf_rd_m', 'pf_rd_s', 'pf_rd_p', 'pf_rd_r', 'pf_rd_t', 'pf_rd_i', 'qid', 'psc', 'keywords', 'sr', 'ref', 'refRID', 'btkr', 'ie', 'camp', 'creative', 'creativeASIN', 'linkCode', 'tag', 'linkID', 'redirect']);
    $rulesetPlus = array('amazon.com' => ['tag=csicon-20'], 'amazon.co.uk' => ['tag=csicon-21']);
    $uri = HttpUri::createFromString($url);
    $domain = $uri->host->getRegisterableDomain();
    if (array_key_exists($domain, $rulesetMinus)) {
        $uri = HttpUri::createFromString($url);
        $modifier = new removeQueryKeys($rulesetMinus[$domain]);
        $url = $modifier->__invoke($uri);
    }
    if (array_key_exists($domain, $rulesetPlus)) {
        foreach ($rulesetPlus[$domain] as $key) {
            $uri = HttpUri::createFromString($url);
            $modifier = new MergeQuery(strval($key));
            $url = $modifier->__invoke($uri);
        }
    }
    return $url;
}
예제 #27
0
 public function callAction(Element $element)
 {
     $url = Uri::createFromString($element->getAttribute('href'));
     $action = new Action($this, $url, $element);
     $params = explode(':', urldecode($url->getFragment()));
     array_shift($params);
     // slice away the needle
     $actionName = array_shift($params);
     $action->setParameters($params);
     $actions = $this->getLinkActions();
     if (array_key_exists($actionName, $actions)) {
         $config = $actions[$actionName];
         if (is_string($config)) {
             $config = ['call' => $config];
         }
         $action->setConfig($config);
         $action->call();
     }
 }