php Webmozart-PathUtil-Path类(方法)实例源码

下面列出了php Webmozart-PathUtil-Path 类(方法)源码代码实例,从而了解它的用法。

作者:xabbu    项目:manage   
/**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     $options = array_replace(self::$defaultOptions, $options);
     Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::boolean($options['serialize-strings'], 'The "serialize-strings" option should be a boolean. Got: %s');
     Assert::boolean($options['serialize-arrays'], 'The "serialize-arrays" option should be a boolean. Got: %s');
     Assert::boolean($options['escape-slash'], 'The "escape-slash" option should be a boolean. Got: %s');
     Assert::boolean($options['pretty-print'], 'The "pretty-print" option should be a boolean. Got: %s');
     $path = Path::makeAbsolute($options['path'], $options['root-dir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $flags = array();
     if (!$options['serialize-strings']) {
         $flags[] = 'JsonFileStore::NO_SERIALIZE_STRINGS';
     }
     if (!$options['serialize-arrays']) {
         $flags[] = 'JsonFileStore::NO_SERIALIZE_ARRAYS';
     }
     if (!$options['serialize-arrays']) {
         $flags[] = 'JsonFileStore::NO_ESCAPE_SLASH';
     }
     if ($options['pretty-print']) {
         $flags[] = 'JsonFileStore::PRETTY_PRINT';
     }
     $targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
     $targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s%s%s);', $varName, $flags ? "\n    " : '', '__DIR__.' . var_export('/' . $relPath, true), $flags ? ",\n    " . implode("\n        | ", $flags) . "\n" : ''));
 }

作者:jibra    项目:drus   
/**
     * Assure that matching version-specific command files are loaded and others are ignored.
     */
    function testCommandVersionSpecific()
    {
        $path = Path::join(UNISH_SANDBOX, 'commandUnitCase');
        $major = $this->drush_major_version();
        $major_plus1 = $major + 1;
        // Write matched and unmatched files to the system search path.
        $files = array(Path::join($path, "{$major}.drush{$major}.inc"), Path::join($path, "drush{$major}/drush{$major}.drush.inc"), Path::join($path, "{$major_plus1}.drush{$major_plus1}.inc"), Path::join($path, "drush{$major_plus1}/drush{$major_plus1}.drush.inc"));
        $this->mkdir(Path::join($path, 'drush' . $major));
        $this->mkdir(Path::join($path, 'drush' . $major_plus1));
        foreach ($files as $file) {
            $contents = <<<EOD
<?php
// Written by Unish. This file is safe to delete.
\$GLOBALS['unish_foo'][] = '{$file}';
EOD;
            $return = file_put_contents($file, $contents);
        }
        drush_set_context('DRUSH_INCLUDE', array($path));
        drush_preflight();
        $loaded = drush_commandfile_list();
        $this->assertContains($files[0], $loaded);
        //Loaded a version-specific command file.
        $this->assertContains($files[1], $loaded);
        //Loaded a version-specific command directory.
        $this->assertNotContains($files[2], $loaded);
        //Did not load a mismatched version-specific command file.
        $this->assertNotContains($files[3], $loaded);
        //Did not load a a mismatched version-specific command directory.
    }

作者:niklongston    项目:manage   
/**
  * Creates the environment.
  *
  * @param string|null              $homeDir         The path to the home
  *                                                  directory or `null` if
  *                                                  none exists.
  * @param string                   $rootDir         The path to the project's
  *                                                  root directory.
  * @param Config                   $config          The configuration.
  * @param RootPackageFile          $rootPackageFile The root package file.
  * @param ConfigFile               $configFile      The configuration file or
  *                                                  `null` if none exists.
  * @param EventDispatcherInterface $dispatcher      The event dispatcher.
  */
 public function __construct($homeDir, $rootDir, Config $config, RootPackageFile $rootPackageFile, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null)
 {
     Assert::directory($rootDir, 'The root directory %s is not a directory.');
     parent::__construct($homeDir, $config, $configFile, $dispatcher);
     $this->rootDir = Path::canonicalize($rootDir);
     $this->rootPackageFile = $rootPackageFile;
 }

作者:nanband    项目:cor   
/**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \LogicException
  * @throws BadMethodCallException
  */
 public function load($resource, $type = null)
 {
     $path = $this->locator->locate($resource);
     $this->container->addResource(new FileResource($path));
     $file = new JsonFile($path);
     $content = $file->read();
     $extension = pathinfo($resource, PATHINFO_FILENAME);
     if (array_key_exists('parameters', $content)) {
         foreach ($content['parameters'] as $name => $parameter) {
             $this->container->setParameter($name, $parameter);
         }
         unset($content['parameters']);
     }
     if (array_key_exists('imports', $content)) {
         foreach ($content['imports'] as $import) {
             $importFilename = $import;
             if (!Path::isAbsolute($importFilename)) {
                 $importFilename = Path::join([dirname($path), $import]);
             }
             $this->import($importFilename, null, false, $file);
         }
         unset($content['imports']);
     }
     $this->container->loadFromExtension($extension, $content);
 }

作者:niklongston    项目:manage   
/**
     * {@inheritdoc}
     */
    public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
    {
        Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
        $options = array_replace(self::$defaultOptions, $options);
        if (!isset($options['path'])) {
            $options['path'] = $targetMethod->getClass()->getDirectory() . '/repository';
        }
        Assert::string($options['path'], 'The "path" option should be a string. Got: %s');
        Assert::string($options['rootDir'], 'The "rootDir" option should be a string. Got: %s');
        Assert::boolean($options['symlink'], 'The "symlink" option should be a boolean. Got: %s');
        $path = Path::makeAbsolute($options['path'], $options['rootDir']);
        $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
        $escPath = $relPath ? '__DIR__.' . var_export('/' . $relPath, true) : '__DIR__';
        if ($relPath) {
            $targetMethod->addBody(<<<EOF
if (!file_exists({$escPath})) {
    mkdir({$escPath}, 0777, true);
}

EOF
);
        }
        $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\FilesystemRepository'));
        $targetMethod->addBody(sprintf('$%s = new FilesystemRepository(%s, %s);', $varName, $escPath, var_export($options['symlink'], true)));
    }

作者:nanband    项目:cor   
/**
  * {@inheritdoc}
  */
 public function getConfigTreeBuilder()
 {
     $treeBuilder = new TreeBuilder();
     $rootNode = $treeBuilder->root('nanando');
     $rootNode->children()->scalarNode('name')->defaultValue('nanbando')->end()->arrayNode('application')->addDefaultsIfNotSet()->children()->scalarNode('name')->defaultNull()->end()->scalarNode('version')->defaultNull()->end()->arrayNode('options')->prototype('scalar')->end()->end()->end()->end()->scalarNode('temp')->defaultValue(sys_get_temp_dir())->end()->arrayNode('backup')->useAttributeAsKey('name')->prototype('array')->children()->scalarNode('plugin')->end()->arrayNode('parameter')->prototype('variable')->end()->end()->end()->end()->end()->arrayNode('storage')->addDefaultsIfNotSet()->children()->scalarNode('local_directory')->defaultValue(Path::join([Path::getHomeDirectory(), 'nanbando']))->end()->scalarNode('remote_service')->end()->end()->end()->arrayNode('require')->prototype('variable')->end()->end()->arrayNode('presets')->prototype('array')->children()->scalarNode('application')->end()->scalarNode('version')->end()->arrayNode('options')->prototype('scalar')->end()->end()->arrayNode('backup')->prototype('array')->children()->scalarNode('plugin')->end()->arrayNode('parameter')->prototype('variable')->end()->end()->end()->end()->end()->end()->end()->end()->end();
     return $treeBuilder;
 }

作者:nanband    项目:cor   
/**
  * Rebuild the puli dependencies for symfony container.
  */
 protected function rebuild(InputInterface $input, OutputInterface $output)
 {
     $puli = new Puli(Path::join([getcwd(), NANBANDO_DIR]));
     $puli->start();
     /** @var EmbeddedComposerInterface $embeddedComposer */
     $embeddedComposer = $this->getApplication()->getEmbeddedComposer();
     $packageManager = $puli->getPackageManager();
     $io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet());
     $composer = $embeddedComposer->createComposer($io);
     $installationManager = $composer->getInstallationManager();
     $rootPackage = $composer->getPackage();
     $repository = $composer->getRepositoryManager()->getLocalRepository();
     $packages = [];
     foreach ($repository->getPackages() as $package) {
         $packages[$package->getName()] = $package;
     }
     foreach ($rootPackage->getRequires() as $require) {
         if (!array_key_exists($require->getTarget(), $packages)) {
             continue;
         }
         $packageManager->installPackage(Path::normalize($installationManager->getInstallPath($packages[$require->getTarget()])), $require->getTarget(), 'nanbando');
     }
     $filesystem = new Filesystem();
     $filesystem->remove(Path::join([getcwd(), NANBANDO_DIR, '.puli']));
     $discoveryManager = $puli->getDiscoveryManager();
     if (!$discoveryManager->hasRootTypeDescriptor('nanbando/bundle')) {
         $discoveryManager->addRootTypeDescriptor(new BindingTypeDescriptor(new BindingType('nanbando/bundle')), 0);
     }
     $discoveryManager->clearDiscovery();
     $discoveryManager->buildDiscovery();
     $filesystem = new Filesystem();
     $filesystem->remove(Path::join([getcwd(), NANBANDO_DIR, 'app', 'cache']));
 }

作者:pul    项目:asset-plugi   
/**
  * {@inheritdoc}
  */
 public function installResource(Resource $resource, InstallationParams $params)
 {
     $targetPath = Path::makeAbsolute($params->getTargetLocation(), $params->getRootDirectory());
     if (!file_exists($targetPath)) {
         mkdir($targetPath, 0777, true);
     }
     $repoPath = $params->getWebPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($targetPath, $this->symlinks, $relative);
     if ('/' === $repoPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($repoPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($repoPath);
     }
     $filesystemRepo->add($repoPath, $resource);
 }

作者:xabbu    项目:manage   
/**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     $options = array_replace_recursive(self::$defaultOptions, $options);
     if (!isset($options['path'])) {
         $options['path'] = $targetMethod->getClass()->getDirectory() . '/path-mappings.json';
     }
     Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::boolean($options['optimize'], 'The "optimize" option should be a boolean. Got: %s');
     Assert::isArray($options['change-stream'], 'The "change-stream" option should be an array. Got: %s');
     $path = Path::makeAbsolute($options['path'], $options['root-dir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $relBaseDir = Path::makeRelative($options['root-dir'], $targetMethod->getClass()->getDirectory());
     $escPath = '__DIR__.' . var_export('/' . $relPath, true);
     $escBaseDir = $relBaseDir ? '__DIR__.' . var_export('/' . $relBaseDir, true) : '__DIR__';
     if ($options['optimize']) {
         $streamGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::CHANGE_STREAM, $options['change-stream']['type']);
         $streamOptions = $options['change-stream'];
         $streamOptions['root-dir'] = $options['root-dir'];
         $streamGenerator->generateNewInstance('stream', $targetMethod, $generatorRegistry, $streamOptions);
         $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\OptimizedJsonRepository'));
         $targetMethod->addBody(sprintf('$%s = new OptimizedJsonRepository(%s, %s, false, $stream);', $varName, $escPath, $escBaseDir));
     } else {
         $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\JsonRepository'));
         $targetMethod->addBody(sprintf('$%s = new JsonRepository(%s, %s, true);', $varName, $escPath, $escBaseDir));
     }
 }

作者:kormi    项目:composer-plugi   
/**
  * Creates a new runner.
  *
  * @param string|null $binDir The path to Composer's "bin-dir".
  */
 public function __construct($binDir = null)
 {
     $phpFinder = new PhpExecutableFinder();
     if (!($php = $phpFinder->find())) {
         throw new RuntimeException('The "php" command could not be found.');
     }
     $puliFinder = new ExecutableFinder();
     // Search:
     // 1. in the current working directory
     // 2. in Composer's "bin-dir"
     // 3. in the system path
     $searchPath = array_merge(array(getcwd()), (array) $binDir);
     // Search "puli.phar" in the PATH and the current directory
     if (!($puli = $puliFinder->find('puli.phar', null, $searchPath))) {
         // Search "puli" in the PATH and Composer's "bin-dir"
         if (!($puli = $puliFinder->find('puli', null, $searchPath))) {
             throw new RuntimeException('The "puli"/"puli.phar" command could not be found.');
         }
     }
     if (Path::hasExtension($puli, '.bat', true)) {
         $this->puli = $puli;
     } else {
         $this->puli = $php . ' ' . $puli;
     }
 }

作者:xabbu    项目:manage   
/**
  * {@inheritdoc}
  */
 public function installResource(PuliResource $resource, InstallationParams $params)
 {
     $documentRoot = Path::makeAbsolute($params->getDocumentRoot(), $params->getRootDirectory());
     if (!file_exists($documentRoot)) {
         mkdir($documentRoot, 0777, true);
     }
     $serverPath = $params->getServerPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($documentRoot, $this->symlinks, $relative);
     if ('/' === $serverPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($serverPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($serverPath);
     }
     // Don't attach the original resource to the repository we just created
     $filesystemRepo->add($serverPath, clone $resource);
 }

作者:inetproces    项目:sugarcl   
/**
  * Concat two path member only if the second is not absolute
  * and make the result relative to the last parameter.
  */
 public static function makeConfigPathRelative($config_path, $option_path, $current_path = null)
 {
     $current_path = $current_path === null ? getcwd() : $current_path;
     $config_path = Path::makeAbsolute($config_path, $current_path);
     $absolute_path = Path::makeAbsolute($option_path, $config_path);
     $relative_path = Path::makeRelative($absolute_path, $current_path);
     return $relative_path === '' ? '.' : $relative_path;
 }

作者:kormi    项目:manage   
/**
  * Creates the context.
  *
  * @param string|null              $homeDir    The path to the home directory
  *                                             or `null` if none exists.
  * @param Config                   $config     The configuration.
  * @param ConfigFile               $configFile The configuration file or
  *                                             `null` if none exists.
  * @param EventDispatcherInterface $dispatcher The event dispatcher.
  */
 public function __construct($homeDir, Config $config, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null)
 {
     Assert::nullOrDirectory($homeDir, 'The home directory %s is not a directory.');
     $this->homeDir = $homeDir ? Path::canonicalize($homeDir) : null;
     $this->config = $config;
     $this->dispatcher = $dispatcher ?: new EventDispatcher();
     $this->configFile = $configFile;
 }

作者:phram    项目:staticfile   
/**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     $ext = Path::getExtension($path, true);
     if ('' == trim($ext)) {
         return null;
     }
     return isset($this->mimes[$ext]) ? $this->mimes[$ext] : null;
 }

作者:rejink    项目:cl   
/**
  * Handles the "package --add" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleAdd(Args $args)
 {
     $packageName = $args->getArgument('name');
     $installPath = Path::makeAbsolute($args->getArgument('path'), getcwd());
     $installer = $args->getOption('installer');
     $this->packageManager->installPackage($installPath, $packageName, $installer);
     return 0;
 }

作者:sensorari    项目:manage   
/**
  * Creates the context.
  *
  * @param string|null                   $homeDir        The path to the
  *                                                      home directory or
  *                                                      `null` if none
  *                                                      exists.
  * @param string                        $rootDir        The path to the
  *                                                      project's root
  *                                                      directory.
  * @param Config                        $config         The configuration.
  * @param RootModuleFile                $rootModuleFile The root module
  *                                                      file.
  * @param ConfigFile|null               $configFile     The configuration
  *                                                      file or `null` if
  *                                                      none exists.
  * @param EventDispatcherInterface|null $dispatcher     The event
  *                                                      dispatcher.
  * @param string                        $env            The environment
  *                                                      that Puli is
  *                                                      running in.
  */
 public function __construct($homeDir, $rootDir, Config $config, RootModuleFile $rootModuleFile, ConfigFile $configFile = null, EventDispatcherInterface $dispatcher = null, $env = Environment::DEV)
 {
     Assert::directory($rootDir, 'The root directory %s is not a directory.');
     Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s');
     parent::__construct($homeDir, $config, $configFile, $dispatcher);
     $this->rootDir = Path::canonicalize($rootDir);
     $this->rootModuleFile = $rootModuleFile;
     $this->env = $env;
 }

作者:webmozar    项目:cl   
/**
  * Handles the "package --install" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleInstall(Args $args)
 {
     $packageName = $args->getArgument('name');
     $installPath = Path::makeAbsolute($args->getArgument('path'), getcwd());
     $installer = $args->getOption('installer');
     $env = $args->isOptionSet('dev') ? Environment::DEV : Environment::PROD;
     $this->packageManager->installPackage($installPath, $packageName, $installer, $env);
     return 0;
 }

作者:fabschur    项目:phoundr   
/**
  * {@inheritDoc}
  */
 public function collect() : AssetCollection
 {
     $templates = [];
     $this->finder->files()->ignoreDotFiles(false)->in((string) $this->srcDir)->name('/\\.twig$/')->sortByType();
     foreach ($this->finder as $template) {
         $templates[] = new TwigTemplateFile(Path::makeRelative($template->getPathname(), (string) $this->srcDir), $this->twigData, $this->twig, $this->filesystem);
     }
     return new AssetCollection($templates);
 }

作者:fabschur    项目:phoundr   
/**
  * {@inheritDoc}
  */
 public function collect() : AssetCollection
 {
     $files = [];
     $this->finder->files()->ignoreDotFiles(false)->in((string) $this->srcDir)->name('/\\.txt$/')->sortByType();
     foreach ($this->finder as $file) {
         $files[] = new TextFile(new File($file->getPathname()), $this->filesystem, dirname(Path::makeRelative($file->getPathname(), (string) $this->srcDir)));
     }
     return new AssetCollection($files);
 }

作者:niklongston    项目:manage   
/**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
     $options = array_replace(self::$defaultOptions, $options);
     $path = Path::makeAbsolute($options['path'], $options['rootDir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
     $targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s, %s);', $varName, '__DIR__.' . var_export('/' . $relPath, true), $options['cache'] ? 'true' : 'false'));
 }


问题


面经


文章

微信
公众号

扫码关注公众号