当前位置: 首页>>代码示例>>PHP>>正文


PHP Filesystem::isAbsolutePath方法代码示例

本文整理汇总了PHP中Composer\Util\Filesystem::isAbsolutePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::isAbsolutePath方法的具体用法?PHP Filesystem::isAbsolutePath怎么用?PHP Filesystem::isAbsolutePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Composer\Util\Filesystem的用法示例。


在下文中一共展示了Filesystem::isAbsolutePath方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: normalize

 private function normalize(string $path) : string
 {
     if (!$this->filesystem->isAbsolutePath($path)) {
         $path = $this->basePath . '/' . $path;
     }
     return $this->filesystem->normalizePath($path);
 }
开发者ID:jderusse,项目名称:composer-warmup,代码行数:7,代码来源:DirectoryReader.php

示例2: __construct

 /**
  * Creates an instance of InstallationManager
  *
  * @param    string    $vendorDir    Relative path to the vendor directory
  * @throws   \InvalidArgumentException
  */
 public function __construct($vendorDir = 'vendor')
 {
     $fs = new Filesystem();
     if ($fs->isAbsolutePath($vendorDir)) {
         $basePath = getcwd();
         $relativePath = $fs->findShortestPath($basePath . '/file', $vendorDir);
         if ($fs->isAbsolutePath($relativePath)) {
             throw new \InvalidArgumentException("Vendor dir ({$vendorDir}) must be accessible from the directory ({$basePath}).");
         }
         $this->vendorPath = $relativePath;
     } else {
         $this->vendorPath = rtrim($vendorDir, '/');
     }
 }
开发者ID:nlegoff,项目名称:composer,代码行数:20,代码来源:InstallationManager.php

示例3: absolutePaths

 /**
  * Helper to convert relative paths to absolute ones.
  *
  * @param string[] $paths
  * @return string[]
  */
 protected function absolutePaths($paths)
 {
     $return = array();
     foreach ($paths as $path) {
         if (!$this->filesystem->isAbsolutePath($path)) {
             $path = getcwd() . '/' . $path;
         }
         $return[] = $path;
     }
     return $return;
 }
开发者ID:ruuds,项目名称:composer-remove-paths,代码行数:17,代码来源:PluginWrapper.php

示例4: generatePackagetAlias

 protected function generatePackagetAlias(PackageInterface $package)
 {
     $fs = new Filesystem();
     $autoload = $package->getAutoload();
     $baseDir = $this->baseDir;
     $aliases = [];
     if (!empty($autoload['psr-0'])) {
         foreach ($autoload['psr-0'] as $name => $path) {
             $name = str_replace('\\', '/', trim($name, '\\'));
             if (!$fs->isAbsolutePath($path)) {
                 $path = $baseDir . '/' . $path;
             }
             $path = $fs->normalizePath($path);
             if (strpos($path . '/', $baseDir . '/') === 0) {
                 $aliases["@{$name}"] = '<base-dir>' . substr($path, strlen($baseDir)) . '/' . $name;
             } else {
                 $aliases["@{$name}"] = $path . '/' . $name;
             }
         }
     }
     if (!empty($autoload['psr-4'])) {
         foreach ($autoload['psr-4'] as $name => $path) {
             $name = str_replace('\\', '/', trim($name, '\\'));
             if (!$fs->isAbsolutePath($path)) {
                 $path = $baseDir . '/' . $path;
             }
             $path = $fs->normalizePath($path);
             if (strpos($path . '/', $baseDir . '/') === 0) {
                 $aliases["@{$name}"] = '<base-dir>' . substr($path, strlen($baseDir));
             } else {
                 $aliases["@{$name}"] = $path;
             }
         }
     }
     return $aliases;
 }
开发者ID:deesoft,项目名称:yii2-composer,代码行数:36,代码来源:Installer.php

示例5: createMap

 /**
  * Iterate over all files in the given directory searching for classes
  *
  * @param \Iterator|string $path      The path to search in or an iterator
  * @param string           $blacklist Regex that matches against the file path that exclude from the classmap.
  * @param IOInterface      $io        IO object
  * @param string           $namespace Optional namespace prefix to filter by
  *
  * @throws \RuntimeException When the path is neither an existing file nor directory
  * @return array             A class map array
  */
 public static function createMap($path, $blacklist = null, IOInterface $io = null, $namespace = null)
 {
     if (is_string($path)) {
         if (is_file($path)) {
             $path = array(new \SplFileInfo($path));
         } elseif (is_dir($path)) {
             $path = Finder::create()->files()->followLinks()->name('/\\.(php|inc|hh)$/')->in($path);
         } else {
             throw new \RuntimeException('Could not scan for classes inside "' . $path . '" which does not appear to be a file nor a folder');
         }
     }
     $map = array();
     $filesystem = new Filesystem();
     $cwd = getcwd();
     foreach ($path as $file) {
         $filePath = $file->getPathname();
         if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc', 'hh'))) {
             continue;
         }
         if (!$filesystem->isAbsolutePath($filePath)) {
             $filePath = $cwd . '/' . $filePath;
             $filePath = $filesystem->normalizePath($filePath);
         } else {
             $filePath = preg_replace('{[\\\\/]{2,}}', '/', $filePath);
         }
         if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) {
             continue;
         }
         $classes = self::findClasses($filePath);
         foreach ($classes as $class) {
             // skip classes not within the given namespace prefix
             if (null !== $namespace && 0 !== strpos($class, $namespace)) {
                 continue;
             }
             if (!isset($map[$class])) {
                 $map[$class] = $filePath;
             } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) {
                 $io->writeError('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>');
             }
         }
     }
     return $map;
 }
开发者ID:neon64,项目名称:composer,代码行数:54,代码来源:ClassMapGenerator.php

示例6: getPathCode

 protected function getPathCode(Filesystem $filesystem, $basePath, $vendorPath, $path)
 {
     if (!$filesystem->isAbsolutePath($path)) {
         $path = $basePath . '/' . $path;
     }
     $path = $filesystem->normalizePath($path);
     $baseDir = '';
     if (strpos($path . '/', $vendorPath . '/') === 0) {
         $path = substr($path, strlen($vendorPath));
         $baseDir = '$vendorDir';
         if ($path !== false) {
             $baseDir .= " . ";
         }
     } else {
         $path = $filesystem->normalizePath($filesystem->findShortestPath($basePath, $path, true));
         if (!$filesystem->isAbsolutePath($path)) {
             $baseDir = '$baseDir . ';
             $path = '/' . $path;
         }
     }
     if (preg_match('/\\.phar$/', $path)) {
         $baseDir = "'phar://' . " . $baseDir;
     }
     return $baseDir . ($path !== false ? var_export($path, true) : "");
 }
开发者ID:aminembarki,项目名称:composer,代码行数:25,代码来源:AutoloadGenerator.php

示例7: getPath

 protected function getPath(Filesystem $filesystem, $relVendorPath, $vendorPath, $path)
 {
     $path = strtr($path, '\\', '/');
     if (!$filesystem->isAbsolutePath($path)) {
         if (strpos($path, $relVendorPath) === 0) {
             // path starts with vendor dir
             return $vendorPath . substr($path, strlen($relVendorPath));
         }
         return strtr(getcwd(), '\\', '/') . '/' . $path;
     }
     return $path;
 }
开发者ID:rufinus,项目名称:composer,代码行数:12,代码来源:AutoloadGenerator.php

示例8: normalizeUrl

 /**
  * An absolute path (leading '/') is converted to a file:// url.
  *
  * @param string $url
  *
  * @return string
  */
 protected static function normalizeUrl($url)
 {
     $fs = new Filesystem();
     if ($fs->isAbsolutePath($url)) {
         return 'file://' . strtr($url, '\\', '/');
     }
     return $url;
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:15,代码来源:SvnDriver.php

示例9: dump

    public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
    {
        $autoloadFile = <<<'EOF'
<?php

// autoload.php generated by Composer
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
    require __DIR__.'/ClassLoader.php';
}

$__composer_autoload_init = function() {
    $loader = new \Composer\Autoload\ClassLoader();

    $map = require __DIR__.'/autoload_namespaces.php';

    foreach ($map as $namespace => $path) {
        $loader->add($namespace, $path);
    }

    $loader->register();

    return $loader;
};

return $__composer_autoload_init();
EOF;
        $filesystem = new Filesystem();
        $vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
        $relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath);
        $vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
        $namespacesFile = <<<EOF
<?php

// autoload_namespace.php generated by Composer

\$vendorDir = {$vendorDirCode};

return array(

EOF;
        $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
        $autoloads = $this->parseAutoloads($packageMap);
        $appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
        $appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
        if (isset($autoloads['psr-0'])) {
            foreach ($autoloads['psr-0'] as $namespace => $paths) {
                $exportedPaths = array();
                foreach ($paths as $path) {
                    $path = strtr($path, '\\', '/');
                    $baseDir = '';
                    if (!$filesystem->isAbsolutePath($path)) {
                        // vendor dir == working dir
                        if (preg_match('{^(\\./?)?$}', $relVendorPath)) {
                            $path = '/' . $path;
                            $baseDir = '$vendorDir . ';
                        } elseif (strpos($path, $relVendorPath) === 0) {
                            // path starts with vendor dir
                            $path = substr($path, strlen($relVendorPath));
                            $baseDir = '$vendorDir . ';
                        } else {
                            $path = '/' . $path;
                            $baseDir = $appBaseDir . ' . ';
                        }
                    } elseif (strpos($path, $vendorPath) === 0) {
                        $path = substr($path, strlen($vendorPath));
                        $baseDir = '$vendorDir . ';
                    }
                    $exportedPaths[] = $baseDir . var_export($path, true);
                }
                $exportedPrefix = var_export($namespace, true);
                $namespacesFile .= "    {$exportedPrefix} => ";
                if (count($exportedPaths) > 1) {
                    $namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n";
                } else {
                    $namespacesFile .= $exportedPaths[0] . ",\n";
                }
            }
        }
        $namespacesFile .= ");\n";
        file_put_contents($targetDir . '/autoload.php', $autoloadFile);
        file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile);
        copy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php');
    }
开发者ID:natxet,项目名称:composer,代码行数:83,代码来源:AutoloadGenerator.php

示例10: setup

 function setup()
 {
     $allModulesDir = $this->parameters->getAllModulesDirs();
     $allPluginsDir = $this->parameters->getAllPluginsDirs();
     $allModules = $this->parameters->getAllSingleModuleDirs();
     if (!count($allModulesDir) && !count($allModules) && !count($allPluginsDir)) {
         // nothing to setup
         return;
     }
     $appDir = $this->parameters->getAppDir();
     if (!$appDir) {
         throw new \Exception("No application directory is set in JelixParameters");
     }
     $configDir = $this->parameters->getVarConfigDir();
     $vendorDir = $this->parameters->getVendorDir();
     $fs = new Filesystem();
     // open the localconfig.ini.php file
     $localinifile = $configDir . 'localconfig.ini.php';
     if (!file_exists($localinifile)) {
         if (!file_exists($configDir)) {
             throw new \Exception('Configuration directory "' . $configDir . '" for the app does not exist');
         }
         file_put_contents($localinifile, "<" . "?php\n;die(''); ?" . ">\n\n");
     }
     $ini = new IniModifier($localinifile);
     if (count($allModulesDir)) {
         $modulesPath = '';
         foreach ($allModulesDir as $path) {
             $path = $fs->findShortestPath($appDir, $vendorDir . $path, true);
             if ($fs->isAbsolutePath($path)) {
                 $modulesPath .= ',' . $path;
             } else {
                 $modulesPath .= ',app:' . $path;
             }
         }
         $modulesPath = trim($modulesPath, ',');
         $ini->setValue('modulesPath', $modulesPath);
     }
     if (count($allPluginsDir)) {
         $pluginsPath = '';
         foreach ($allPluginsDir as $path) {
             $path = $fs->findShortestPath($appDir, $vendorDir . $path, true);
             if ($fs->isAbsolutePath($path)) {
                 $pluginsPath .= ',' . $path;
             } else {
                 $pluginsPath .= ',app:' . $path;
             }
         }
         $pluginsPath = trim($pluginsPath, ',');
         $ini->setValue('pluginsPath', $pluginsPath);
     }
     if (count($allModules)) {
         // erase first all "<module>.path" keys
         foreach ($ini->getValues('modules') as $key => $val) {
             if (preg_match("/\\.path\$/", $key)) {
                 $ini->removeValue($key, "modules");
             }
         }
         foreach ($allModules as $path) {
             $path = $fs->normalizePath($path);
             $moduleName = basename($path);
             $path = $fs->findShortestPath($appDir, $vendorDir . $path, true);
             if (!$fs->isAbsolutePath($path)) {
                 $path = 'app:' . $path;
             }
             $ini->setValue($moduleName . '.path', $path, 'modules');
         }
     }
     $ini->save();
 }
开发者ID:jelix,项目名称:composer-module-setup,代码行数:70,代码来源:SetupJelix16.php

示例11: getPathCode

 protected function getPathCode(Filesystem $filesystem, $relVendorPath, $vendorPath, $path)
 {
     $path = strtr($path, '\\', '/');
     $baseDir = '';
     if (!$filesystem->isAbsolutePath($path)) {
         if (strpos($path, $relVendorPath) === 0) {
             // path starts with vendor dir
             $path = substr($path, strlen($relVendorPath));
             $baseDir = '$vendorDir . ';
         } else {
             $path = '/' . $path;
             $baseDir = '$baseDir . ';
         }
     } elseif (strpos($path, $vendorPath) === 0) {
         $path = substr($path, strlen($vendorPath));
         $baseDir = '$vendorDir . ';
     }
     return $baseDir . var_export($path, true);
 }
开发者ID:nicodmf,项目名称:composer,代码行数:19,代码来源:AutoloadGenerator.php

示例12: generateDefaultAlias

 protected function generateDefaultAlias(PackageInterface $package)
 {
     $fs = new Filesystem();
     $vendorDir = $fs->normalizePath($this->vendorDir);
     $autoload = $package->getAutoload();
     $aliases = [];
     if (!empty($autoload['psr-0'])) {
         foreach ($autoload['psr-0'] as $name => $path) {
             $name = str_replace('\\', '/', trim($name, '\\'));
             if (!$fs->isAbsolutePath($path)) {
                 $path = $this->vendorDir . '/' . $package->getPrettyName() . '/' . $path;
             }
             $path = $fs->normalizePath($path);
             if (strpos($path . '/', $vendorDir . '/') === 0) {
                 $aliases["@{$name}"] = '<vendor-dir>' . substr($path, strlen($vendorDir)) . '/' . $name;
             } else {
                 $aliases["@{$name}"] = $path . '/' . $name;
             }
         }
     }
     if (!empty($autoload['psr-4'])) {
         foreach ($autoload['psr-4'] as $name => $path) {
             if (is_array($path)) {
                 // ignore psr-4 autoload specifications with multiple search paths
                 // we can not convert them into aliases as they are ambiguous
                 continue;
             }
             $name = str_replace('\\', '/', trim($name, '\\'));
             if (!$fs->isAbsolutePath($path)) {
                 $path = $this->vendorDir . '/' . $package->getPrettyName() . '/' . $path;
             }
             $path = $fs->normalizePath($path);
             if (strpos($path . '/', $vendorDir . '/') === 0) {
                 $aliases["@{$name}"] = '<vendor-dir>' . substr($path, strlen($vendorDir));
             } else {
                 $aliases["@{$name}"] = $path;
             }
         }
     }
     return $aliases;
 }
开发者ID:dieos2,项目名称:bolaoyyi2,代码行数:41,代码来源:Installer.php

示例13: dump

    public function dump(RepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir)
    {
        $filesystem = new Filesystem();
        $filesystem->ensureDirectoryExists($installationManager->getVendorPath());
        $filesystem->ensureDirectoryExists($targetDir);
        $vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
        $relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
        $vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
        $appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
        $appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
        $namespacesFile = <<<EOF
<?php

// autoload_namespace.php generated by Composer

\$vendorDir = {$vendorDirCode};
\$baseDir = {$appBaseDir};

return array(

EOF;
        $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
        $autoloads = $this->parseAutoloads($packageMap);
        foreach ($autoloads['psr-0'] as $namespace => $paths) {
            $exportedPaths = array();
            foreach ($paths as $path) {
                $path = strtr($path, '\\', '/');
                $baseDir = '';
                if (!$filesystem->isAbsolutePath($path)) {
                    if (strpos($path, $relVendorPath) === 0) {
                        // path starts with vendor dir
                        $path = substr($path, strlen($relVendorPath));
                        $baseDir = '$vendorDir . ';
                    } else {
                        $path = '/' . $path;
                        $baseDir = '$baseDir . ';
                    }
                } elseif (strpos($path, $vendorPath) === 0) {
                    $path = substr($path, strlen($vendorPath));
                    $baseDir = '$vendorDir . ';
                }
                $exportedPaths[] = $baseDir . var_export($path, true);
            }
            $exportedPrefix = var_export($namespace, true);
            $namespacesFile .= "    {$exportedPrefix} => ";
            if (count($exportedPaths) > 1) {
                $namespacesFile .= "array(" . implode(', ', $exportedPaths) . "),\n";
            } else {
                $namespacesFile .= $exportedPaths[0] . ",\n";
            }
        }
        $namespacesFile .= ");\n";
        $classmapFile = <<<EOF
<?php

// autoload_classmap.php generated by Composer

\$vendorDir = {$vendorDirCode};
\$baseDir = {$appBaseDir};

return array(

EOF;
        // flatten array
        $autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
        foreach ($autoloads['classmap'] as $dir) {
            foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
                $path = '/' . $filesystem->findShortestPath(getcwd(), $path, true);
                $classmapFile .= '    ' . var_export($class, true) . ' => $baseDir . ' . var_export($path, true) . ",\n";
            }
        }
        $classmapFile .= ");\n";
        file_put_contents($targetDir . '/autoload_namespaces.php', $namespacesFile);
        file_put_contents($targetDir . '/autoload_classmap.php', $classmapFile);
        if ($includePathFile = $this->getIncludePathsFile($packageMap)) {
            file_put_contents($targetDir . '/include_paths.php', $includePathFile);
        }
        file_put_contents($targetDir . '/autoload.php', $this->getAutoloadFile(true, true, (bool) $includePathFile));
        copy(__DIR__ . '/ClassLoader.php', $targetDir . '/ClassLoader.php');
    }
开发者ID:nlegoff,项目名称:composer,代码行数:80,代码来源:AutoloadGenerator.php


注:本文中的Composer\Util\Filesystem::isAbsolutePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。