isAbsolutePath example

if ($frameworkType === false) {
            throw new \InvalidArgumentException(
                'Sorry the package type of this package is not yet supported.'
            );
        }

        $class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
        $installer = new $class($package$this->composer, $this->getIO());

        $path = $installer->getInstallPath($package$frameworkType);
        if (!$this->filesystem->isAbsolutePath($path)) {
            $path = getcwd() . '/' . $path;
        }

        return $path;
    }

    public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        $installPath = $this->getPackageBasePath($package);
        $io = $this->io;
        $outputStatus = function D) use ($io$installPath) {
            
return realpath($path);
        }

        return readlink($path);
    }

    /** * Given an existing path, convert it to a path relative to a given starting path. */
    public function makePathRelative(string $endPath, string $startPath): string
    {
        if (!$this->isAbsolutePath($startPath)) {
            throw new InvalidArgumentException(sprintf('The start path "%s" is not absolute.', $startPath));
        }

        if (!$this->isAbsolutePath($endPath)) {
            throw new InvalidArgumentException(sprintf('The end path "%s" is not absolute.', $endPath));
        }

        // Normalize separators on Windows         if ('\\' === \DIRECTORY_SEPARATOR) {
            $endPath = str_replace('\\', '/', $endPath);
            $startPath = str_replace('\\', '/', $startPath);
        }

    public function __construct(string|array $templatePathPatterns)
    {
        $this->templatePathPatterns = (array) $templatePathPatterns;
    }

    public function load(TemplateReferenceInterface $template): Storage|false
    {
        $file = $template->get('name');

        if (self::isAbsolutePath($file) && is_file($file)) {
            return new FileStorage($file);
        }

        $replacements = [];
        foreach ($template->all() as $key => $value) {
            $replacements['%'.$key.'%'] = $value;
        }

        $fileFailures = [];
        foreach ($this->templatePathPatterns as $templatePathPattern) {
            if (is_file($file = strtr($templatePathPattern$replacements)) && is_readable($file)) {
                

  public function __construct($path_type$package_name$rel_path$full_path) {
    $this->type = $path_type;
    $this->packageName = $package_name;
    $this->relativePath = $rel_path;
    $this->fullPath = $full_path;

    // Ensure that the full path really is a full path. We do not use     // 'realpath' here because the file specified by the full path might     // not exist yet.     $fs = new Filesystem();
    if (!$fs->isAbsolutePath($this->fullPath)) {
      $this->fullPath = getcwd() . '/' . $this->fullPath;
    }
  }

  /** * Gets the name of the package this source file was pulled from. * * @return string * Name of package. */
  public function packageName() {
    
use Symfony\Component\Templating\Loader\FilesystemLoader;

class ProjectTemplateFilesystemLoader extends FilesystemLoader
{
    public function getTemplatePathPatterns()
    {
        return $this->templatePathPatterns;
    }

    public static function isAbsolutePath($path): bool
    {
        return parent::isAbsolutePath($path);
    }
}
public function testConstructor()
    {
        $pathPattern = self::$fixturesPath.'/templates/%name%.%engine%';
        $loader = new ProjectTemplateFilesystemLoader($pathPattern);
        $this->assertEquals([$pathPattern]$loader->getTemplatePathPatterns(), '__construct() takes a path as its second argument');
        $loader = new ProjectTemplateFilesystemLoader([$pathPattern]);
        $this->assertEquals([$pathPattern]$loader->getTemplatePathPatterns(), '__construct() takes an array of paths as its second argument');
    }

    public function testIsAbsolutePath()
    {
        $this->assertTrue(ProjectTemplateFilesystemLoader::isAbsolutePath('/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
        $this->assertTrue(ProjectTemplateFilesystemLoader::isAbsolutePath('c:\\\\foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
        $this->assertTrue(ProjectTemplateFilesystemLoader::isAbsolutePath('c:/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
        $this->assertTrue(ProjectTemplateFilesystemLoader::isAbsolutePath('\\server\\foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
        $this->assertTrue(ProjectTemplateFilesystemLoader::isAbsolutePath('https://server/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
        $this->assertTrue(ProjectTemplateFilesystemLoader::isAbsolutePath('phar://server/foo.xml'), '->isAbsolutePath() returns true if the path is an absolute path');
    }

    public function testLoad()
    {
        $pathPattern = self::$fixturesPath.'/templates/%name%';
        $path = self::$fixturesPath.'/templates';
        


    /** * @return string|array */
    public function locate(string $name, string $currentPath = null, bool $first = true)
    {
        if ('' === $name) {
            throw new \InvalidArgumentException('An empty file name is not valid to be located.');
        }

        if ($this->isAbsolutePath($name)) {
            if (!file_exists($name)) {
                throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist.', $name), 0, null, [$name]);
            }

            return $name;
        }

        $paths = $this->paths;

        if (null !== $currentPath) {
            array_unshift($paths$currentPath);
        }

    }

    /** * @throws LoaderError */
    public function addPath(string $path, string $namespace = self::MAIN_NAMESPACE): void
    {
        // invalidate the cache         $this->cache = $this->errorCache = [];

        $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
        if (!is_dir($checkPath)) {
            throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path$checkPath));
        }

        $this->paths[$namespace][] = rtrim($path, '/\\');
    }

    /** * @throws LoaderError */
    public function prependPath(string $path, string $namespace = self::MAIN_NAMESPACE): void
    {

                    $file->next();
                } while ($file->valid());
            }
        } else {
            $alternatives = [];

            if ($paths) {
                $shortnames = [];
                $dirs = [];
                foreach (current($paths) as $path) {
                    $dirs[] = $this->isAbsolutePath($path) ? $path : $this->projectDir.'/'.$path;
                }
                foreach (Finder::create()->files()->followLinks()->in($dirs) as $file) {
                    $shortnames[] = str_replace('\\', '/', $file->getRelativePathname());
                }

                [$namespace$shortname] = $this->parseTemplateName($name);
                $alternatives = $this->findAlternatives($shortname$shortnames);
                if (FilesystemLoader::MAIN_NAMESPACE !== $namespace) {
                    $alternatives = array_map(fn ($shortname) => '@'.$namespace.'/'.$shortname$alternatives);
                }
            }

            


    private function getDirectories(): array
    {
        $filesystem = new Filesystem();
        if (null !== $this->absolutePaths) {
            return $this->absolutePaths;
        }

        $this->absolutePaths = [];
        foreach ($this->paths as $path => $namespace) {
            if ($filesystem->isAbsolutePath($path)) {
                if (!file_exists($path)) {
                    throw new \InvalidArgumentException(sprintf('The asset mapper directory "%s" does not exist.', $path));
                }
                $this->absolutePaths[realpath($path)] = $namespace;

                continue;
            }

            if (file_exists($this->projectRootDir.'/'.$path)) {
                $this->absolutePaths[realpath($this->projectRootDir.'/'.$path)] = $namespace;

                
$this->filesystem->mirror($sourcePath$targetPath);

        $this->assertFileEquals($file1$targetPath.'file1');
    }

    /** * @dataProvider providePathsForIsAbsolutePath */
    public function testIsAbsolutePath($path$expectedResult)
    {
        $result = $this->filesystem->isAbsolutePath($path);

        $this->assertEquals($expectedResult$result);
    }

    public static function providePathsForIsAbsolutePath()
    {
        return [
            ['/var/lib', true],
            ['c:\\\\var\\lib', true],
            ['\\var\\lib', true],
            ['var/lib', false],
            [
private string $rootConfig;

    public function __construct($varDir$testCase$rootConfig$environment$debug)
    {
        if (!is_dir(__DIR__.'/'.$testCase)) {
            throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
        }
        $this->varDir = $varDir;
        $this->testCase = $testCase;

        $fs = new Filesystem();
        if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
            throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
        }
        $this->rootConfig = $rootConfig;

        parent::__construct($environment$debug);
    }

    public function registerBundles(): iterable
    {
        if (!file_exists($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) {
            throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
        }
public function __construct($varDir$testCase$rootConfig$environment$debug)
    {
        if (!is_dir(__DIR__.'/'.$testCase)) {
            throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
        }
        $this->varDir = $varDir;
        $this->testCase = $testCase;

        $fs = new Filesystem();
        foreach ((array) $rootConfig as $config) {
            if (!$fs->isAbsolutePath($config) && !is_file($config = __DIR__.'/'.$testCase.'/'.$config)) {
                throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $config));
            }

            $this->rootConfig[] = $config;
        }

        parent::__construct($environment$debug);
    }

    public function getContainerClass(): string
    {
        
|| false === $extra = $this->composer->getPackage()->getExtra()['runtime'] ?? []
        ) {
            return;
        }

        $fs = new Filesystem();
        $projectDir = \dirname(realpath(Factory::getComposerFile()));

        if (null === $autoloadTemplate = $extra['autoload_template'] ?? null) {
            $autoloadTemplate = __DIR__.'/autoload_runtime.template';
        } else {
            if (!$fs->isAbsolutePath($autoloadTemplate)) {
                $autoloadTemplate = $projectDir.'/'.$autoloadTemplate;
            }

            if (!is_file($autoloadTemplate)) {
                throw new \InvalidArgumentException(sprintf('File "%s" defined under "extra.runtime.autoload_template" in your composer.json file not found.', $this->composer->getPackage()->getExtra()['runtime']['autoload_template']));
            }
        }

        $projectDir = $fs->makePathRelative($projectDir$vendorDir);
        $nestingLevel = 0;

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