Exemplo n.º 1
0
 public function testSetterAccess()
 {
     $this->assertSame($this->url, $this->url->setScheme('https'));
     $this->assertSame($this->url, $this->url->setUser('login'));
     $this->assertSame($this->url, $this->url->setPass('pass'));
     $this->assertSame($this->url, $this->url->setHost('secure.example.com'));
     $this->assertSame($this->url, $this->url->setPort(443));
     $this->assertSame($this->url, $this->url->setPath('/test/query.php'));
     $this->assertSame($this->url, $this->url->setQuery('?kingkong=toto'));
     $this->assertSame($this->url, $this->url->setFragment('doc3'));
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 protected function generateUrl($path, array $parameters = array())
 {
     $url = Url::createFromUrl($this->baseUrl);
     $url->getPath()->set($path);
     $url->getQuery()->set($parameters);
     return (string) $url;
 }
Exemplo n.º 3
0
 /**
  * Joins a candidate uri to a base url if it is relative.
  *
  * @param string $baseUrl      the base url which SHOULD be absolute.
  * @param string $candidateUri a candidate relative or absolute URI.
  *
  * @return string               Absolute URL
  */
 public function join($baseUrl, $candidateUri)
 {
     if (preg_match('/:\\/\\//', $candidateUri) === 0) {
         $currentUrl = Url::createFromUrl($baseUrl);
         $pathParts = $output = preg_split("/(\\\\|\\/)/", $candidateUri);
         $resetPath = preg_match('/^(\\/|\\\\)/', $candidateUri) === 1;
         if ($resetPath) {
             $currentUrl->setPath(new Path());
         }
         foreach ($pathParts as $pathPart) {
             switch ($pathPart) {
                 case '..':
                     $lastElementPos = count($currentUrl->getPath()) - 1;
                     unset($currentUrl->getPath()[$lastElementPos]);
                     break;
                 case '':
                 case '.':
                     break;
                 default:
                     $currentUrl->getPath()->append($pathPart);
                     break;
             }
         }
         return (string) $currentUrl;
     }
     return $candidateUri;
 }
Exemplo n.º 4
0
 protected function parseHost($host)
 {
     if (!$this->domain && !$this->subdomain) {
         // Load the default domain
         $domain = Kohana::$config->load('multisite.domain');
         // If no host passed in, check the for HOST in environment
         if (!$host) {
             $host = getenv('HOST');
         }
         // If we still don't have a host
         if (!$host) {
             // .. parse the current URL
             $url = Url::createFromServer($_SERVER);
             // .. and grab the host
             $host = $url->getHost()->toUnicode();
         }
         // If $domain is set and we're at a subdomain of $domain..
         if ($domain and substr($host, strlen($domain) * -1) == $domain) {
             // .. grab just the subdomain
             $subdomain = substr($host, 0, strlen($domain) * -1 - 1);
         } else {
             // .. otherwise grab the whole domain
             $domain = $host;
             $subdomain = '';
         }
         $this->domain = $domain;
         $this->subdomain = $subdomain;
     }
 }
Exemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function createToken($gatewayName, $model, $targetPath, array $targetParameters = array(), $afterPath = null, array $afterParameters = array())
 {
     /** @var TokenInterface $token */
     $token = $this->tokenStorage->create();
     $token->setHash($token->getHash() ?: Random::generateToken());
     $token->setGatewayName($gatewayName);
     if ($model instanceof IdentityInterface) {
         $token->setDetails($model);
     } elseif (null !== $model) {
         $token->setDetails($this->storageRegistry->getStorage($model)->identify($model));
     }
     if (0 === strpos($targetPath, 'http')) {
         $targetUrl = Url::createFromUrl($targetPath);
         $targetUrl->getQuery()->set(array_replace(array('payum_token' => $token->getHash()), $targetUrl->getQuery()->toArray(), $targetParameters));
         $token->setTargetUrl((string) $targetUrl);
     } else {
         $token->setTargetUrl($this->generateUrl($targetPath, array_replace(array('payum_token' => $token->getHash()), $targetParameters)));
     }
     if ($afterPath && 0 === strpos($afterPath, 'http')) {
         $afterUrl = Url::createFromUrl($afterPath);
         $afterUrl->getQuery()->modify($afterParameters);
         $token->setAfterUrl((string) $afterUrl);
     } elseif ($afterPath) {
         $token->setAfterUrl($this->generateUrl($afterPath, $afterParameters));
     }
     $this->tokenStorage->update($token);
     return $token;
 }
Exemplo n.º 6
0
 /**
  * Overridden to allow paths be passed in and out
  * @param $url
  * @return null|string
  */
 protected static function sanitizeUrl($url)
 {
     if (strpos($url, '/') === 0) {
         return $url;
     }
     return parent::sanitizeUrl($url);
 }
Exemplo n.º 7
0
 public function testSameValueAs()
 {
     $url1 = Url::createFromUrl('example.com');
     $url2 = UrlImmutable::createFromUrl('//example.com');
     $url3 = UrlImmutable::createFromUrl('//example.com?foo=toto+le+heros');
     $this->assertTrue($url1->sameValueAs($url2));
     $this->assertFalse($url3->sameValueAs($url2));
 }
 /**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('League\\Url\\Url', function ($app, $parameters) {
         return Url::createFromUrl(array_values($parameters)[0]);
     });
     $this->app->singleton('resolver', function ($app) {
         return new Resolver(new Steps());
     });
 }
 /**
  * @param string $url       Url to generate access link for
  * @param int    $expires   Unix timestamp at which link should expire
  * @param string $secretKey The secret key set for file container
  *
  * @return string Url with embedded signature
  */
 public function signFileDownloadLink($url, $expires, $secretKey)
 {
     $method = 'GET';
     $url = Url::createFromUrl($url);
     $path = $url->getRelativeUrl();
     $body = sprintf("%s\n%s\n%s", $method, $expires, $path);
     $signature = hash_hmac('sha1', $body, $secretKey);
     $url->getQuery()->modify(['temp_url_sig' => $signature, 'temp_url_expires' => $expires]);
     return (string) $url;
 }
Exemplo n.º 10
0
 /**
  * @param string $uri URI to be parsed
  */
 public function __construct($uri)
 {
     // Hack, prevent infinite recursion
     if (!$uri instanceof AbstractSegment and 1 == func_num_args()) {
         $uri = static::createFromUrl($uri);
         parent::__construct($uri->getScheme(), $uri->getUser(), $uri->getPass(), $uri->getHost(), $uri->getPort(), $uri->getPath(), $uri->getQuery(), $uri->getFragment());
     } else {
         call_user_func_array('parent::__construct', func_get_args());
     }
 }
Exemplo n.º 11
0
 /**
  * Return an array with the Thumbs pictures url
  *
  * @param Crawler $node
  * @return array
  */
 public function getThumbs(Crawler $node = null)
 {
     if (!$node instanceof Crawler) {
         $node = $this->crawler;
     }
     $pictures = [];
     $node->filter('.lbcImages > meta[itemprop="image"]')->each(function (Crawler $link, $i) use(&$pictures) {
         $pictures[$i] = Url::createFromUrl($link->attr('content'))->setScheme('http')->__toString();
     });
     return $pictures;
 }
Exemplo n.º 12
0
 /**
  * Get the location of a redirect or false if none
  *
  * @param Url $url
  *
  * @return Url|false
  */
 protected function getRedirectLocation(Url $url)
 {
     /** @var ResponseInterface $response */
     $response = Guzzle::get((string) $url, ['allow_redirects' => false, 'verify' => env('REDIRECTS_VERIFY_SSL', true)]);
     if (!env('ALLOW_INSANE_STATUS_CODES', false) && ($response->getStatusCode() > 399 || $response->getStatusCode() < 300)) {
         return false;
     }
     $rawLocation = $response->getHeader('location');
     if (!$rawLocation) {
         return false;
     }
     $rawLocation = $rawLocation[0];
     $newUrl = $this->getUrlObject($rawLocation);
     if (!$newUrl->getHost()->get()) {
         $newUrl->setHost($url->getHost()->get());
         if ('/' !== $rawLocation[0]) {
             $newUrl->setPath(rtrim($url->getPath()->get(), '/') . '/' . ltrim($newUrl->getPath()->get(), '/'));
         }
     }
     return $newUrl;
 }
Exemplo n.º 13
0
 /**
  * Génère l'URL correspondant à une route nommée
  * @param  string $routeName Le nom de route
  * @param  mixed  $params    Tableau de paramètres optionnel de cette route
  * @param  boolean $absolute Retourne une url absolue si true (relative si false)
  * @return L'URL correspondant à la route
  */
 public static function generateUrl($routeName, $params = array(), $absolute = false)
 {
     $params = empty($params) ? array() : $params;
     $app = getApp();
     $router = $app->getRouter();
     $routeUrl = $router->generate($routeName, $params);
     $url = $routeUrl;
     if ($absolute) {
         $u = \League\Url\Url::createFromServer($_SERVER);
         $url = $u->getBaseUrl() . $routeUrl;
     }
     return $url;
 }
 public function __construct($url)
 {
     $this->url = Url::createFromUrl($url);
     /**
      * Clean the URL by removing every params (no need)
      */
     $query = $this->url->getQuery();
     foreach ($query->keys() as $paramName) {
         unset($query[$paramName]);
     }
     preg_match('/\\/(.*)\\/(.*)\\.htm/', parse_url($this->url, PHP_URL_PATH), $matches);
     $this->category = $matches[1];
     $this->id = $matches[2];
 }
Exemplo n.º 15
0
 /**
  * Determine the namespace of a type from the XMLSchema
  *
  * @param \Goetas\XML\XSDReader\Schema\Type\Type|\Sapone\Util\SimpleXMLElement $type
  * @return string
  */
 public function inflectNamespace($type)
 {
     if ($type instanceof Type) {
         if ($type->getSchema()->getTargetNamespace() === SchemaReader::XSD_NS) {
             // XMLSchema primitive types do not have a namespace
             $namespace = null;
         } else {
             $namespace = array();
             // prepend the base namespace
             if ($this->config->getNamespace()) {
                 $namespace[] = $this->config->getNamespace();
             }
             if ($this->config->isAxisNamespaces()) {
                 // append the XMLSchema namespace, formatted in Apache Axis style
                 $url = Url::createFromUrl($type->getSchema()->getTargetNamespace());
                 // the namespace is an url
                 $namespace = array_merge($namespace, array_reverse(explode('.', $url->getHost()->get())));
                 if (!empty($url->getPath()->get())) {
                     $namespace = array_merge($namespace, explode('/', $url->getPath()->get()));
                 }
             }
             $namespace = implode('\\', $namespace);
         }
         return $namespace;
     } elseif ($type instanceof SimpleXMLElement) {
         if ($type->getNamespace() === SchemaReader::XSD_NS) {
             // XMLSchema primitive types do not have a namespace
             $namespace = null;
         } else {
             $namespace = array();
             // prepend the base namespace
             if ($this->config->getNamespace()) {
                 $namespace[] = $this->config->getNamespace();
             }
             if ($this->config->isAxisNamespaces()) {
                 // append the XMLSchema namespace, formatted in Apache Axis style
                 $url = Url::createFromUrl($type->getNamespace());
                 // the namespace is an url
                 $namespace = array_merge($namespace, array_reverse(explode('.', $url->getHost()->get())));
                 if (!empty($url->getPath()->get())) {
                     $namespace = array_merge($namespace, explode('/', $url->getPath()->get()));
                 }
             }
             $namespace = implode('\\', $namespace);
         }
         return $namespace;
     } else {
         throw new \InvalidArgumentException('Expected an instance of Goetas\\XML\\XSDReader\\Schema\\Type\\Type or Sapone\\Util\\SimpleXMLElement');
     }
 }
 /**
  * {@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']) {
             $cancelUrl = Url::createFromUrl($details['CANCELURL']);
             $query = $cancelUrl->getQuery();
             $query->modify(['cancelled' => 1]);
             $cancelUrl->setQuery($query);
             $details['CANCELURL'] = (string) $cancelUrl;
         }
         $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));
 }
Exemplo n.º 17
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']));
     $url = Url::createFromUrl($getToken->getToken()->getTargetUrl());
     $url->setQuery($httpRequest->query);
     throw new HttpRedirect((string) $url);
 }
Exemplo n.º 18
0
 /**
  * Send request upstream
  *
  * @param  Request  $request
  *
  * @return Response
  * @throws HttpException
  */
 public static function makeRequest(Request $request)
 {
     try {
         $url = Url::createFromUrl($request->fullUrl());
         $host = static::getHostFromUrl($url);
         $client = new Client(['base_uri' => $url->getScheme() . '://' . $host]);
         $proxyRequest = new GuzzleRequest($request->method(), $request->path());
         $headers = $request->header();
         array_walk($headers, function ($value, $key) use($proxyRequest) {
             $proxyRequest->withHeader($key, $value);
         });
         $stream = \GuzzleHttp\Psr7\stream_for(json_encode($request->json()->all()));
         $response = $client->send($proxyRequest, ['timeout' => 2, 'body' => $stream, 'query' => $request->query(), 'form_params' => $request->input()]);
         return static::createLocalResponse($response);
     } catch (Exception $e) {
         if (get_class($e) == GuzzleException\ClientException::class) {
             return static::createLocalResponse($e->getResponse());
         }
         abort(404);
     }
 }
Exemplo n.º 19
0
 protected function handlePath(UrlInterface $url, $path, $args)
 {
     $path_object = $this->basePath($url, $path, $args);
     $components = parse_url($path);
     $reset = false;
     // Were we passed a built URL? If so, just return it.
     if ($string = array_get($components, 'scheme')) {
         try {
             $url = Url::createFromUrl($path);
             $path_object = $url->getPath();
             $reset = true;
         } catch (\Exception $e) {
         }
     }
     if (!$reset) {
         if ($string = array_get($components, 'path')) {
             $path_object->append($string);
         }
         if ($string = array_get($components, 'query')) {
             $url = $url->setQuery($string);
         }
         if ($string = array_get($components, 'fragment')) {
             $url = $url->setFragment($string);
         }
     }
     foreach ($args as $segment) {
         if (!is_array($segment)) {
             $segment = (string) $segment;
             // sometimes integers foul this up when we pass them in as URL arguments.
         }
         $path_object->append($segment);
     }
     if (!$reset) {
         $url_path = $url->getPath();
         $url_path->append($path_object);
     } else {
         $url_path = $path_object;
     }
     return $url->setPath($url_path);
 }
Exemplo n.º 20
0
 public function getDbConfig($host = NULL)
 {
     // Load the default domain
     $domain = Kohana::$config->load('multisite.domain');
     // If no host passed in, check the for HOST in environment
     if (!$host) {
         $host = getenv('HOST');
     }
     // If we still don't have a host
     if (!$host) {
         // .. parse the current URL
         $url = Url::createFromServer($_SERVER);
         // .. and grab the host
         $host = $url->getHost()->toUnicode();
     }
     // If $domain is set and we're at a subdomain of $domain..
     if ($domain and substr_compare($host, $domain, strlen($domain) * -1) !== FALSE) {
         // .. grab just the subdomain
         $subdomain = substr($host, 0, strlen($domain) * -1 - 1);
     } else {
         // .. otherwise grab the whole domain
         $domain = $host;
         $subdomain = '';
     }
     // .. and find the current deployment credentials
     $result = DB::select()->from('deployments')->where('subdomain', '=', $subdomain)->where('domain', '=', $domain)->limit(1)->offset(0)->execute($this->db);
     $deployment = $result->current();
     // No deployment? throw a 404
     if (!count($deployment)) {
         throw new HTTP_Exception_404("Deployment not found");
     }
     // Set new database config
     $config = Kohana::$config->load('database')->default;
     $config['connection'] = ['hostname' => $deployment['dbhost'], 'database' => $deployment['dbname'], 'username' => $deployment['dbuser'], 'password' => $deployment['dbpassword'], 'persistent' => $config['connection']['persistent']];
     return $config;
 }
Exemplo n.º 21
0
 protected function send_resetpassword($to, $params)
 {
     $site_name = Kohana::$config->load('site.name');
     $site_email = Kohana::$config->load('site.email');
     $multisite_email = Kohana::$config->load('multisite.email');
     $client_url = Kohana::$config->load('site.client_url');
     // @todo make this more robust
     if ($multisite_email) {
         $from_email = $multisite_email;
     } elseif ($site_email) {
         $from_email = $site_email;
     } else {
         $url = Url::createFromServer($_SERVER);
         $host = $url->getHost()->toUnicode();
         $from_email = 'noreply@' . $host;
     }
     $view = View::factory('email/forgot-password');
     $view->site_name = $site_name;
     $view->token = $params['token'];
     $view->client_url = $client_url;
     $message = $view->render();
     $subject = $site_name . ': Password reset';
     $email = Email::factory($subject, $message, 'text/html')->to($to)->from($from_email, $site_name)->send();
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function resolve($url)
 {
     $relative = Url\Url::createFromUrl($url);
     if ($relative->isAbsolute()) {
         return $relative->withoutDotSegments();
     }
     if (!$relative->host->isEmpty() && $relative->getAuthority() != $this->getAuthority()) {
         return $relative->withScheme($this->scheme)->withoutDotSegments();
     }
     return $this->resolveRelative($relative)->withoutDotSegments();
 }
Exemplo n.º 23
0
</td>
        			<td><?php 
            echo h($upa['upaHandle']);
            ?>
</td>
        			<td><?php 
            echo number_format($upa['upaDefaultPoints']);
            ?>
</td>
        			<td><?php 
            echo h($upa['gName']);
            ?>
</td>
        			<td style="text-align: right">
                        <?php 
            $delete_url = \League\Url\Url::createFromUrl($view->action('delete', $upa['upaID']));
            $delete_url = $delete_url->setQuery(array('ccm_token' => \Core::make('helper/validation/token')->generate('delete_action')));
            ?>
        			    <a href="<?php 
            echo $view->action($upa['upaID']);
            ?>
" class="btn btn-sm btn-default"><?php 
            echo t('Edit');
            ?>
</a>
        			    <a href="<?php 
            echo $delete_url;
            ?>
" class="btn btn-sm btn-danger"><?php 
            echo t('Delete');
            ?>
 public function getRepositoriesInternalDataProvider()
 {
     $repositoryUrlCacheMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\Bindings\\Browser\\RepositoryUrlCache')->setMethods(array('getRepositoryUrl', 'buildUrl', 'addRepository'))->disableProxyingToOriginalMethods()->getMock();
     $repositoryUrlCacheMock->expects($this->any())->method('buildUrl')->willReturn(Url::createFromUrl('http://foo.bar.baz'));
     $repositoryUrlCacheMockWithRepositoryUrlEntry = clone $repositoryUrlCacheMock;
     $repositoryUrlCacheMockWithRepositoryUrlEntry->expects($this->any())->method('getRepositoryUrl')->willReturn(Url::createFromUrl('http://foo.bar.baz'));
     $repositoryUrlCacheMockWithRepositoryUrlEntry->expects($this->once())->method('addRepository');
     return array('no repository id - repository url cache builds url' => array(null, $repositoryUrlCacheMock), 'with repository id - repository url cache does NOT return repository url - url is build' => array('repository-id', $repositoryUrlCacheMock), 'with repository id - repository url cache does return repository url - url is fetched from cache' => array('repository-id', $repositoryUrlCacheMockWithRepositoryUrlEntry));
 }
 /**
  * Return the thumb picture url
  *
  * @return null|string
  */
 public function getThumb()
 {
     $image = $this->node->filter('.item_imagePic .lazyload[data-imgsrc]')->first();
     if (0 === $image->count()) {
         return;
     }
     $src = $image->attr('data-imgsrc');
     return Url::createFromUrl($src)->setScheme('http')->__toString();
 }
 /**
  * Build an instance of \League\Url\Url for the given url
  *
  * @param string $url
  * @return Url
  */
 public function buildUrl($url)
 {
     return Url::createFromUrl($url);
 }
Exemplo n.º 27
0
 public function setUp()
 {
     $this->url = Url::createFromUrl('https://*****:*****@secure.example.com:443/test/query.php?kingkong=toto#doc3');
 }
Exemplo n.º 28
0
 /**
  * Set Default Uri
  *
  * @return void
  */
 protected function setDefaultUri()
 {
     $this->uri = Url::createFromServer($_SERVER);
 }
 /**
  * Data provider for updateType
  *
  * @return array
  */
 public function updateTypeDataProvider()
 {
     $typeDefinitionArrayRepresentation = array('foo' => 'bar');
     $typeDefinitionJsonRepresentation = '{"foo":"bar"}';
     return array(array(Url::createFromUrl(self::BROWSER_URL_TEST . '?cmisaction=updateType&type=' . $typeDefinitionJsonRepresentation), $typeDefinitionArrayRepresentation, 'repositoryId', new ItemTypeDefinition('typeId')));
 }
Exemplo n.º 30
0
 /**
  * @expectedException RuntimeException
  */
 public function testCreateFromUrlBadName2()
 {
     Url::createFromUrl('sdfsdfqsdfsdf');
 }