Load another page of results into this pager.

@param $uri
@throws Recurly_Error
503734
protected function _loadFrom($uri) {
    if (empty($uri)) {
      return;
    }

    $response = $this->_client->request(Recurly_Client::GET, $uri);
    $response->assertValidResponse();

    $this->_objects = array();
    $this->__parseXmlToUpdateObject($response->body);
    $this->_afterParseResponse($response, $uri);
  }
1091092
public function parse($uri)
    {
        parent::parse($uri);

        if (empty($this->path)) {
            $this->path = '/';
        }

        return $this;
    }
1342932
public function uri($uri = null)
    {
        $page = $this->findPageByUri($uri);

        abort_if(!$page, '404');

        if ($page->private && !Auth::check()) {
            return redirect()->guest(route(app()->getLocale().'::login'));
        }

        if ($page->redirect && $page->subpages->count() > 0) {
            $childUri = $page->subpages->first()->uri();

            return redirect($childUri);
        }

        // get submenu
        $children = $this->repository->getSubMenu($page->uri);

        $templateDir = 'pages::'.config('typicms.template_dir', 'public').'.';
        $template = $page->template ?: 'default';

        if (!view()->exists($templateDir.$template)) {
            info('Template '.$template.' not found, switching to default template.');
            $template = 'default';
        }

        return response()->view($templateDir.$template, compact('children', 'page'));
    }
1211455
public function rewind()
    {
        $this->itemCount = 0;
        $this->position = 0;

        if ($this->config['firstPage']) {
            list($this->page, $shouldContinue) = $this->mapResults($this->config['firstPage']);
            $nextResultToken = $this->determineNextResultToken($this->page, $shouldContinue);
        } else {
            $this->page = null;
            $nextResultToken = $this->initialResultToken;
        }

        if ($nextResultToken) {
            $this->set($this->resultTokenPath, $this->callOptions, $nextResultToken);
        }
    }
243290
protected function prepareUrlForRequest($uri)
    {
        if (Str::startsWith($uri, '/')) {
            $uri = substr($uri, 1);
        }

        if (! Str::startsWith($uri, 'http')) {
            $uri = ($this->baseUrl ?? config('app.url')) . '/' . $uri;
        }

        return trim($uri, '/');
    }
314284
protected function fromString($uri)
    {
        if (empty($uri)) {
            return $this;
        }

        $this->fromArray(parse_url($uri));

        return $this;
    }
345991
public function load(UriInterface $uri)
    {
        if (!$uri instanceof HttpUriInterface) {
            throw new InvalidUriTypeException(
                $uri,
                'Eloquent\Schemer\Uri\HttpUriInterface'
            );
        }
        if (!$uri->isAbsolute()) {
            throw new RelativeUriException($uri);
        }

        $response = $this->browser()->get($uri->toString());
        if (!$response->isSuccessful()) {
            throw new LoadException($uri);
        }

        $mimeType = $this->mimeTypeByResponse($response);
        if (null === $mimeType) {
            $mimeType = $this->extensionMap()->getByPath(
                $this->pathFromUri($uri)
            );
        }

        return new Content($response->getContent(), $mimeType);
    }
228778
public function resetChildrenUri(Page $page)
    {
        foreach ($page->subpages as $subpage) {
            $uris = $subpage->getTranslations('uri');
            foreach ($uris as $locale => $uri) {
                $subpage->forgetTranslation('uri', $locale);
            }
            $subpage->save();
            $this->resetChildrenUri($subpage);
        }
    }
235920
public function parse($uri)
	{
		// Initialise variables
		$retval = false;

		// Set the original URI to fall back on
		$this->uri = $uri;

		// Parse the URI and populate the object fields.  If URI is parsed properly,
		// set method return value to true.
		if ($parts = parse_url($uri))
		{
			$retval = true;
		}

		// We need to replace &amp; with & for parse_str to work right...
		if (isset($parts['query']) && strpos($parts['query'], '&amp;'))
		{
			$parts['query'] = str_replace('&amp;', '&', $parts['query']);
		}

		$data = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment');
		foreach ($data as $part)
		{
			$this->$part = isset($parts[$part]) ? $parts[$part] : null;
		}

		// Parse the query
		if (isset($parts['query']))
		{
			parse_str($parts['query'], $this->vars);
		}

		return $retval;
	}
1226975
function loadURIRoot( $uri, $displayErrors = true, &$extraParameters )
    {
        $res = "";
        $template = "";
        $resobj = $this->resourceFor( $uri, $res, $template );

        if ( !is_object( $resobj ) )
        {
            if ( $displayErrors )
                $this->warning( "", "No resource handler for \"$res\" and no default resource handler, aborting." );
            return null;
        }

        $canCache = true;
        if ( !$resobj->servesStaticData() )
            $canCache = false;
        if ( !$this->isCachingAllowed() )
            $canCache = false;

        $resourceData = $this->loadURIData( $resobj, $uri, $res, $template, $extraParameters, $displayErrors );

        if ( $resourceData )
        {
            eZTemplate::appendTemplateToStatisticsIfNeeded( $resourceData['template-name'], $resourceData['template-filename'] );
            $this->appendTemplateFetch( $resourceData['template-filename'] );

            if ( !$resourceData['compiled-template'] and
                 $resourceData['root-node'] === null )
            {
                $resourceData['root-node'] = array( eZTemplate::NODE_ROOT, false );
                $templateText = $resourceData["text"];
                $keyData = $resourceData['key-data'];
                $this->setIncludeText( $uri, $templateText );
                $rootNamespace = '';
                $this->parse( $templateText, $resourceData['root-node'], $rootNamespace, $resourceData );

                if ( eZTemplate::isDebugEnabled() )
                {
                    $this->appendDebugNodes( $resourceData['root-node'], $resourceData );
                }

                if ( $canCache )
                    $resobj->setCachedTemplateTree( $keyData, $uri, $res, $template, $extraParameters, $resourceData['root-node'] );
            }
            if ( !$resourceData['compiled-template'] and
                 $canCache and
                 $this->canCompileTemplate( $resourceData, $extraParameters ) )
            {
                $generateStatus = $this->compileTemplate( $resourceData, $extraParameters );
                if ( $generateStatus )
                    $resourceData['compiled-template'] = true;
            }
        }

        return $resourceData;
    }
580934
static protected function discoverXRDS ( $uri, $recur = 0 )
	{
		// Bail out when we are following redirects
		if ($recur > 10)
		{
			return false;
		}
		
		$data = self::curl($uri);

		// Check what we got back, could be:
		// 1. The XRDS discovery file itself (check content-type)
		// 2. The X-XRDS-Location header
		
		if (is_string($data) && !empty($data))
		{
			list($head,$body) = explode("\r\n\r\n", $data);
			$body = trim($body);
			$m	  = false;

			// See if we got the XRDS file itself or we have to follow a location header
			if (	preg_match('/^Content-Type:\s*application\/xrds+xml/im', $head)
				||	preg_match('/^<\?xml[^>]*\?>\s*<xrds\s/i', $body)
				||	preg_match('/^<xrds\s/i', $body)
				)
			{
				$xrds = $body;
			}
			else if (	preg_match('/^X-XRDS-Location:\s*([^\r\n]*)/im', $head, $m)
					||	preg_match('/^Location:\s*([^\r\n]*)/im', $head, $m))
			{
				// Recurse to the given location
				if ($uri != $m[1])
				{
					$xrds = self::discoverXRDS($m[1], $recur+1);
				}
				else
				{
					// Referring to the same uri, bail out
					$xrds = false;
				}
			}
			else
			{
				// Not an XRDS file an nowhere else to check
				$xrds = false;
			}
		}
		else
		{
			$xrds = false;
		}
		return $xrds;
	}
337154
protected function httpGet($uri)
    {
        $results = [];
        // Start requesting at page 1
        $page = 1;
        $pageSize = 100;
        // We dont know how many pages there are, so assume 1 until we know
        $pagecount = 1;
        while ($page <= $pagecount) {
            //echo('fetching page '.$page.' of '.$pagecount.' current result size is '.count($results).PHP_EOL);
            $this->log[] = [
                        'request' => [
                                    'method' => 'GET',
                                    'uri'    => $uri.'?page='.$page.'&per_page='.$pageSize,
                                    ],
                        ];
            $response = \Httpful\Request::get($uri.'?page='.$page)
                                                    ->basicAuth($this->username, $this->password)
                                                    ->expectsType(\Httpful\Mime::JSON)
                                                    ->parseWith(function ($body) {
                                                        return \Metaclassing\Utility::decodeJson($body);
                                                    })
                                                    ->send()
                                                    ->body;
            $this->log[count($this->log) - 1]['response'] = $response;

            $resultKey = '';
            if (isset($response['zones'])) {
                $resultKey = 'zones';
            }
            if (isset($response['resource_records'])) {
                $resultKey = 'resource_records';
            }
            if (!$resultKey) {
                throw new \Exception('Unhandled results key, check dns client logs for details');
            }
            foreach ($response[$resultKey] as $result) {
                array_push($results, $result);
            }
            // Now that we KNOW the pagecount, update that and increment our page counter
            if (isset($response['total_count'])) {
                $totalResults = $response['total_count'];
                $pagecount = ceil($totalResults / $pageSize);
            }
            // And get the next page ready for the next request
            $page++;
        }

        return $results;
    }
835843
public static function run(string $uri = null): void
    {
        static::init($uri);

        if (!KOLDY_CLI) {
            // this is normal HTTP request that came from Web Server, so we'll handle it

            $uri = $uri ?? $_SERVER['REQUEST_URI'] ?? null;
            if ($uri == null) {
                static::terminateWithError('Something went wrong, $uri is not set');
            }

            static::$uri = $uri;

            try {
                $route = static::route();
                $route->prepareHttp(static::$uri);

                /*
                 NOTE: CSRF will not be handled automatically by framework any more
                if (Csrf::isEnabled() && (!Csrf::hasTokenStored() || !Csrf::hasCookieToken())) {
                    Csrf::generate();
                }
                */

                $response = $route->exec();

                if ($response instanceof AbstractResponse) {
                    $response->flush();

                } else {
                    print $response;
                }

            } catch (Throwable $e) { // something threw up

                // otherwise, route should handle exception
                // because of this, you can customize almost everything
                static::$routing->handleException($e);

            }

        } else {

            // and this is case when you're dealing with CLI request
            // scripts are stored in /application/scripts, but before that, we need to determine which script is called

            global $argv;
            // $argv[0] - this should be "index.php", but we don't need this at all

            try {
                // so, if you run your script as "php cli.php backup", you'll have only two elements
                // in the future, we might handle different number of parameters, but until that, we won't

                // you can also call script in module using standard colon as separator
                // example: php cli.php user:backup   -> where "user" is module and "backup" is script name

                if (!isset($argv[1])) {
                    throw new CliException('Script name is not set in your script call. Please use notation: php index.php script-name');
                }

                $script = $argv[1]; // this should be the second parameter
                static::$cliName = $script;

                if (preg_match('/^([a-zA-Z0-9\_\-\:]+)$/', $script)) {
                    $scriptName = $script;
                    $module = null;

                    if (strpos($script, ':') !== false) {
                        // script name has colon - it means that the script needs to be looked for in modules
                        $tmp = explode(':', $script);
                        $cliScriptPath = static::getApplicationPath("modules/{$tmp[0]}/scripts/{$tmp[1]}.php");
                        $scriptName = $tmp[0] . ':' . $tmp[1];
                        $module = $tmp[0];

                        if (is_dir(static::getApplicationPath("modules/{$module}"))) {
                            static::registerModule($module);
                        }
                    } else {
                        if ($script == 'koldy') {
                            $script = static::$cliName = Cli::getParameterOnPosition(2);

                            if ($script === null) {
                                throw new CliException('Unable to run Koldy script; script name not passed after \'koldy\' part');
                            }

                            $cliScriptPath = __DIR__ . '/Cli/Scripts/' . $script . '.php';
                        } else {
                            $cliScriptPath = static::$scriptsPath . $script . '.php';
                        }
                    }

                    static::$cliScriptPath = $cliScriptPath;

                    if (!is_file($cliScriptPath)) {
                        throw new CliException("CLI script={$scriptName} on path={$cliScriptPath} does not exists");
                    } else {
                        Log::notice("Started CLI script: {$scriptName}");
                        require $cliScriptPath;
                        Log::notice("Done with CLI script: {$scriptName}");
                    }
                } else {
                    throw new CliException("CLI script={$script} contains invalid characters; please stick to english letters, numbers, dashes and underlines");
                }

                exit(0);

            } catch (Throwable $e) {
                if (!Log::isEnabledLogger('\Koldy\Log\Adapter\Out')) {
                    echo "{$e->getMessage()} in {$e->getFile()}:{$e->getLine()}\n\n{$e->getTraceAsString()}";
                }
                Log::critical($e);

                exit(1);
            }
        }

    }
610442
public function callStaticRoute($uri)
    {
        $params = array_slice($this->getUrlSegments(), 2);

        return $this->callController([$uri, $params]);
    }
580560
public function fillCache($uri)
    {
        $cacheKey = $uri . '@cache';

        if (!isset($this->cache[$cacheKey])) {
            $this->cache[$cacheKey] = true;

            $iterator = new \RecursiveIteratorIterator($this->getRecursiveIterator($uri), \RecursiveIteratorIterator::SELF_FIRST);

            /** @var UniformResourceIterator $uri */
            foreach ($iterator as $item) {
                $key = $item->getUrl() . '@010';
                $this->cache[$key] = $item->getPathname();
            }
        }

        return $this;
    }
85230
public function it_throws_circular_redirection_exception_on_alternating_redirect(
        UriInterface $uri,
        UriInterface $redirectUri,
        RequestInterface $request,
        ResponseInterface $redirectResponse1,
        ResponseInterface $redirectResponse2,
        RequestInterface $modifiedRequest
    ) {
        $redirectResponse1->getStatusCode()->willReturn(302);
        $redirectResponse1->hasHeader('Location')->willReturn(true);
        $redirectResponse1->getHeaderLine('Location')->willReturn('/redirect');

        $redirectResponse2->getStatusCode()->willReturn(302);
        $redirectResponse2->hasHeader('Location')->willReturn(true);
        $redirectResponse2->getHeaderLine('Location')->willReturn('/original');

        $next = function (RequestInterface $currentRequest) use ($request, $redirectResponse1, $redirectResponse2): Promise {
            return ($currentRequest === $request->getWrappedObject())
                ? new HttpFulfilledPromise($redirectResponse1->getWrappedObject())
                : new HttpFulfilledPromise($redirectResponse2->getWrappedObject())
            ;
        };

        $redirectPlugin = $this;
        $firstCalled = false;
        $first = function (RequestInterface $request) use (&$firstCalled, $redirectPlugin, $next, &$first) {
            if ($firstCalled) {
                throw new \Exception('only one redirect expected');
            }
            $firstCalled = true;

            return $redirectPlugin->getWrappedObject()->handleRequest($request, $next, $first);
        };

        $request->getUri()->willReturn($uri);
        $uri->__toString()->willReturn('/original');

        $modifiedRequest->getUri()->willReturn($redirectUri);
        $redirectUri->__toString()->willReturn('/redirect');

        $uri->withPath('/redirect')->willReturn($redirectUri);
        $redirectUri->withFragment('')->willReturn($redirectUri);
        $redirectUri->withQuery('')->willReturn($redirectUri);

        $redirectUri->withPath('/original')->willReturn($uri);
        $uri->withFragment('')->willReturn($uri);
        $uri->withQuery('')->willReturn($uri);

        $request->withUri($redirectUri)->willReturn($modifiedRequest);
        $request->getMethod()->willReturn('GET');
        $modifiedRequest->withUri($uri)->willReturn($request);
        $modifiedRequest->getMethod()->willReturn('GET');

        $promise = $this->handleRequest($request, $next, $first);
        $promise->shouldReturnAnInstanceOf(HttpRejectedPromise::class);
        $promise->shouldThrow(CircularRedirectionException::class)->duringWait();
    }
431400
protected function loadSystemUris($requestUri = null)
	{
		// Set the request URI.
		// @codeCoverageIgnoreStart
		if (!empty($requestUri))
		{
			$this->set('uri.request', $requestUri);
		}
		else
		{
			$this->set('uri.request', $this->detectRequestUri());
		}

		// @codeCoverageIgnoreEnd

		// Check to see if an explicit base URI has been set.
		$siteUri = trim($this->get('site_uri'));

		if ($siteUri != '')
		{
			$uri = new Uri($siteUri);
		}
		else
		// No explicit base URI was set so we need to detect it.
		{
			// Start with the requested URI.
			$uri = new Uri($this->get('uri.request'));

			// If we are working from a CGI SAPI with the 'cgi.fix_pathinfo' directive disabled we use PHP_SELF.
			if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI']))
			{
				// We aren't expecting PATH_INFO within PHP_SELF so this should work.
				$uri->setPath(rtrim(dirname($_SERVER['PHP_SELF']), '/\\'));
			}
			else
			// Pretty much everything else should be handled with SCRIPT_NAME.
			{
				$uri->setPath(rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\'));
			}

			// Clear the unused parts of the requested URI.
			$uri->setQuery(null);
			$uri->setFragment(null);
		}

		// Get the host and path from the URI.
		$host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
		$path = rtrim($uri->toString(array('path')), '/\\');

		// Check if the path includes "index.php".
		if (strpos($path, 'index.php') !== false)
		{
			// Remove the index.php portion of the path.
			$path = substr_replace($path, '', strpos($path, 'index.php'), 9);
			$path = rtrim($path, '/\\');
		}

		// Set the base URI both as just a path and as the full URI.
		$this->set('uri.base.full', $host . $path . '/');
		$this->set('uri.base.host', $host);
		$this->set('uri.base.path', $path . '/');

		// Set the extended (non-base) part of the request URI as the route.
		$this->set('uri.route', substr_replace($this->get('uri.request'), '', 0, strlen($this->get('uri.base.full'))));

		// Get an explicitly set media URI is present.
		$mediaURI = trim($this->get('media_uri'));

		if ($mediaURI)
		{
			if (strpos($mediaURI, '://') !== false)
			{
				$this->set('uri.media.full', $mediaURI);
				$this->set('uri.media.path', $mediaURI);
			}
			else
			{
				// Normalise slashes.
				$mediaURI = trim($mediaURI, '/\\');
				$mediaURI = !empty($mediaURI) ? '/' . $mediaURI . '/' : '/';
				$this->set('uri.media.full', $this->get('uri.base.host') . $mediaURI);
				$this->set('uri.media.path', $mediaURI);
			}
		}
		else
		// No explicit media URI was set, build it dynamically from the base uri.
		{
			$this->set('uri.media.full', $this->get('uri.base.full') . 'media/');
			$this->set('uri.media.path', $this->get('uri.base.path') . 'media/');
		}
	}