makeAbsolute example


    public function dumpFile(string $filename$content)
    {
        if (\is_array($content)) {
            throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
        }

        $dir = \dirname($filename);

        if (is_link($filename) && $linkTarget = $this->readlink($filename)) {
            $this->dumpFile(Path::makeAbsolute($linkTarget$dir)$content);

            return;
        }

        if (!is_dir($dir)) {
            $this->mkdir($dir);
        }

        // Will create a temp file with 0600 access rights         // when the filesystem supports chmod.         $tmpFile = $this->tempnam($dirbasename($filename));

        
        yield ['/css/style.css', '/webmozart/symfony', '/css/style.css'];
        yield ['\\css\\style.css', '/webmozart/symfony', '/css/style.css'];
        yield ['C:/css/style.css', 'C:/webmozart/symfony', 'C:/css/style.css'];
        yield ['D:\\css\\style.css', 'D:/webmozart/symfony', 'D:/css/style.css'];
    }

    /** * @dataProvider provideMakeAbsoluteTests */
    public function testMakeAbsolute(string $relativePath, string $basePath, string $absolutePath)
    {
        $this->assertSame($absolutePath, Path::makeAbsolute($relativePath$basePath));
    }

    public function testMakeAbsoluteFailsIfBasePathNotAbsolute()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The base path "webmozart/symfony" is not an absolute path.');

        Path::makeAbsolute('css/style.css', 'webmozart/symfony');
    }

    public function testMakeAbsoluteFailsIfBasePathEmpty()
    {
Home | Imprint | This part of the site doesn't use cookies.