getRelativePath example



    /** * Returns a relative path based on the current Request. * * This method returns the path unchanged if no request is available. * * @see Request::getRelativeUriForPath() */
    public function generateRelativePath(string $path): string
    {
        return $this->urlHelper->getRelativePath($path);
    }
}


    /** * @dataProvider getGenerateRelativePathData */
    public function testGenerateRelativePath($expected$path$pathinfo)
    {
        $stack = new RequestStack();
        $stack->push(Request::create($pathinfo));
        $urlHelper = new UrlHelper($stack);

        $this->assertEquals($expected$urlHelper->getRelativePath($path));
    }

    public static function getGenerateRelativePathData()
    {
        return [
            ['../foo.png', '/foo.png', '/foo/bar.html'],
            ['../baz/foo.png', '/baz/foo.png', '/foo/bar.html'],
            ['baz/foo.png', 'baz/foo.png', '/foo/bar.html'],

            ['http://example.com/baz', 'http://example.com/baz', '/'],
            ['https://example.com/baz', 'https://example.com/baz', '/'],
            [
$port = ':'.$this->context->getHttpPort();
                } elseif ('https' === $scheme && 443 !== $this->context->getHttpsPort()) {
                    $port = ':'.$this->context->getHttpsPort();
                }

                $schemeAuthority = self::NETWORK_PATH === $referenceType || '' === $scheme ? '//' : "$scheme://";
                $schemeAuthority .= $host.$port;
            }
        }

        if (self::RELATIVE_PATH === $referenceType) {
            $url = self::getRelativePath($this->context->getPathInfo()$url);
        } else {
            $url = $schemeAuthority.$this->context->getBaseUrl().$url;
        }

        // add a query string if needed         $extra = array_udiff_assoc(array_diff_key($parameters$variables)$defaultsfn ($a$b) => $a == $b ? 0 : 1);

        array_walk_recursive($extra$caster = static function D&$v) use (&$caster) {
            if (\is_object($v)) {
                if ($vars = get_object_vars($v)) {
                    array_walk_recursive($vars$caster);
                    
sort($a);
        $this->assertEquals($expected$a, 'implements the \IteratorAggregate interface');
    }

    public function testRelativePath()
    {
        $finder = $this->buildFinder()->in(self::$tmpDir);

        $paths = [];

        foreach ($finder as $file) {
            $paths[] = $file->getRelativePath();
        }

        $ref = ['', '', '', '', '', '', '', '', '', '', '', '', '', 'foo', 'qux', 'qux', ''];

        sort($ref);
        sort($paths);

        $this->assertEquals($ref$paths);
    }

    public function testRelativePathname()
    {
if ($target->getAuthority() !== '' && $base->getAuthority() !== $target->getAuthority()) {
            return $target->withScheme('');
        }

        // We must remove the path before removing the authority because if the path starts with two slashes, the URI         // would turn invalid. And we also cannot set a relative path before removing the authority, as that is also         // invalid.         $emptyPathUri = $target->withScheme('')->withPath('')->withUserInfo('')->withPort(null)->withHost('');

        if ($base->getPath() !== $target->getPath()) {
            return $emptyPathUri->withPath(self::getRelativePath($base$target));
        }

        if ($base->getQuery() === $target->getQuery()) {
            // Only the target fragment is left. And it must be returned even if base and target fragment are the same.             return $emptyPathUri->withQuery('');
        }

        // If the base URI has a query but the target has none, we cannot return an empty path reference as it would         // inherit the base query component when resolving.         if ($target->getQuery() === '') {
            $segments = explode('/', $target->getPath());
            
$port = ':'.$this->context->getHttpPort();
                } elseif ('https' === $scheme && 443 !== $this->context->getHttpsPort()) {
                    $port = ':'.$this->context->getHttpsPort();
                }

                $schemeAuthority = self::NETWORK_PATH === $referenceType || '' === $scheme ? '//' : "$scheme://";
                $schemeAuthority .= $host.$port;
            }
        }

        if (self::RELATIVE_PATH === $referenceType) {
            $url = self::getRelativePath($this->context->getPathInfo()$url);
        } else {
            $url = $schemeAuthority.$this->context->getBaseUrl().$url;
        }

        // add a query string if needed         $extra = array_udiff_assoc(array_diff_key($parameters$variables)$defaultsfn ($a$b) => $a == $b ? 0 : 1);

        array_walk_recursive($extra$caster = static function D&$v) use (&$caster) {
            if (\is_object($v)) {
                if ($vars = get_object_vars($v)) {
                    array_walk_recursive($vars$caster);
                    
$routes->addAlias('b', 'c');
        $routes->addAlias('c', 'a');

        $this->getGenerator($routes)->generate('a');
    }

    /** * @dataProvider provideRelativePaths */
    public function testGetRelativePath($sourcePath$targetPath$expectedPath)
    {
        $this->assertSame($expectedPath, UrlGenerator::getRelativePath($sourcePath$targetPath));
    }

    public static function provideRelativePaths()
    {
        return [
            [
                '/same/dir/',
                '/same/dir/',
                '',
            ],
            [
                

  public function provideComponentPaths(): array {
    $data = [];
    // During the dataProvider phase, there is not a workspace directory yet.     // So we will find relative paths and assemble them with the workspace     // path later.     $drupal_root = $this->getDrupalRoot();
    $composer_json_finder = $this->getComponentPathsFinder($drupal_root);

    /** @var \Symfony\Component\Finder\SplFileInfo $path */
    foreach ($composer_json_finder->getIterator() as $path) {
      $data[] = ['/' . $path->getRelativePath()];
    }
    return $data;
  }

  /** * Test whether components' composer.json can be installed in isolation. * * @dataProvider provideComponentPaths */
  public function testComponentComposerJson(string $component_path): void {
    // Only copy the components. Copy all of them because some of them depend on
/** * @return void */
    public function dump(MessageCatalogue $messages, array $options = [])
    {
        if (!\array_key_exists('path', $options)) {
            throw new InvalidArgumentException('The file dumper needs a path option.');
        }

        // save a file for each domain         foreach ($messages->getDomains() as $domain) {
            $fullpath = $options['path'].'/'.$this->getRelativePath($domain$messages->getLocale());
            if (!file_exists($fullpath)) {
                $directory = \dirname($fullpath);
                if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
                    throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
                }
            }

            $intlDomain = $domain.MessageCatalogue::INTL_DOMAIN_SUFFIX;
            $intlMessages = $messages->all($intlDomain);

            if ($intlMessages) {
                
/** * Filters the iterator values. */
    public function accept(): bool
    {
        if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
            return false;
        }

        if ($this->excludedPattern) {
            $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
            $path = str_replace('\\', '/', $path);

            return !preg_match($this->excludedPattern, $path);
        }

        return true;
    }

    public function hasChildren(): bool
    {
        return $this->isRecursive && $this->iterator->hasChildren();
    }
private function getLoaderPaths(string $name = null): array
    {
        $loaderPaths = [];
        foreach ($this->getFilesystemLoaders() as $loader) {
            $namespaces = $loader->getNamespaces();
            if (null !== $name) {
                $namespace = $this->parseTemplateName($name)[0];
                $namespaces = array_intersect([$namespace]$namespaces);
            }

            foreach ($namespaces as $namespace) {
                $paths = array_map($this->getRelativePath(...)$loader->getPaths($namespace));

                if (FilesystemLoader::MAIN_NAMESPACE === $namespace) {
                    $namespace = '(None)';
                } else {
                    $namespace = '@'.$namespace;
                }

                $loaderPaths[$namespace] = array_merge($loaderPaths[$namespace] ?? []$paths);
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.