join() public static method

The result is a canonical path.
Since: 2.0 Added method.
public static join ( string[] | string $paths ) : string
$paths string[] | string Path parts as parameters or array.
return string The joint path.
示例#1
0
 /**
  * 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']));
 }
示例#2
0
    /**
     * 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.
    }
示例#3
0
 /**
  * {@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);
 }
示例#4
0
 /**
  * {@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;
 }
示例#5
0
 /**
  * @param string $path
  * @param string|null $configFile
  * @param AbstractLogger $logger
  * @return Result
  */
 public function analyse($path, $configFile = null, AbstractLogger $logger = null)
 {
     $logger = $logger ?: new NullLogger();
     $path = Path::makeAbsolute($path, getcwd());
     if (!$configFile) {
         $configFile = Path::join([$path, '.simpspector.yml']);
     }
     $config = $this->loader->load($configFile);
     return $this->executor->run($path, $config, $logger);
 }
示例#6
0
 public function testParameters()
 {
     $path = Path::join([DATAFIXTURES_DIR, 'config', 'test-parameters.json']);
     $this->locator->locate('test-parameters.json')->willReturn($path);
     $this->container->addResource(Argument::that(function (FileResource $resource) use($path) {
         return $resource->getResource() === $path;
     }))->shouldBeCalled();
     $this->container->loadFromExtension('test-parameters', ['name' => 'test'])->shouldBeCalled();
     $this->container->setParameter('test', 'value')->shouldBeCalled();
     $this->loader->load('test-parameters.json');
 }
示例#7
0
 /**
  * {@inheritdoc}
  */
 public function getUris($sourceFile)
 {
     $uris = [];
     foreach (parent::getUris($sourceFile) as $uri) {
         foreach (array_keys($this->sizes) as $size) {
             $info = pathinfo($uri);
             $uris[] = Path::join($info['dirname'], $size . $info['basename']);
         }
     }
     return $uris;
 }
示例#8
0
 public function testRestore()
 {
     $path = Path::join([DATAFIXTURES_DIR, 'backups', '13-21-2016-05-29_success.zip']);
     $nanbando = $this->getNanbando(['uploads' => ['plugin' => 'directory', 'parameter' => ['directory' => 'uploads']]]);
     $filesystem = new Filesystem(new ZipArchiveAdapter($path));
     $this->storage->open('13-21-45-2016-05-29')->willReturn($filesystem);
     $this->eventDispatcher->dispatch(Events::PRE_RESTORE_EVENT, Argument::type(PreRestoreEvent::class))->shouldBeCalled();
     $this->eventDispatcher->dispatch(Events::RESTORE_EVENT, Argument::type(RestoreEvent::class))->shouldBeCalled();
     $this->eventDispatcher->dispatch(Events::POST_RESTORE_EVENT, Argument::type(Event::class))->shouldBeCalled();
     $nanbando->restore('13-21-45-2016-05-29');
 }
示例#9
0
 /**
  * @param string $path
  * @param Issue $issue
  * @param int $around
  * @param bool $attr
  * @return string
  */
 public static function createCodeSnippet($path, Issue $issue, $around = 5, $attr = false)
 {
     $snippet = SnippetHelper::createSnippetByFile(Path::join($path, $issue->getFile()), $issue->getLine(), $around);
     $extension = pathinfo($issue->getFile(), PATHINFO_EXTENSION);
     $offset = max($issue->getLine() - $around, 1);
     $options = [];
     if ($attr) {
         $options = ['file' => $issue->getFile(), 'line' => $issue->getLine(), 'offset' => $offset];
     }
     return (new MarkdownBuilder())->code($snippet, $extension, $options)->getMarkdown();
 }
示例#10
0
 public function testDrushFinder()
 {
     // We don't really need a real Drupal site; we could
     // create a fake site, as long as we had the right signature
     // files to allow us to bootstrap to the DRUPAL_ROOT phase.
     $this->setUpDrupal(1, TRUE);
     $globalDrushDotPhp = Path::join(UNISH_DRUSH, '../drush.php');
     // Control: test `drush --root ` ... with no site-local Drush
     $drush_location = $this->getDrushLocation();
     $this->assertEquals($globalDrushDotPhp, $drush_location);
     // We will try copying a site-local Drush to
     // all of the various locations the 'drush finder'
     // might expect to find it.
     $drush_locations = array("vendor", "../vendor", "sites/all/vendor", "sites/all");
     foreach ($drush_locations as $drush_base) {
         $drush_root = $this->create_site_local_drush($drush_base);
         // Test `drush --root ` ... with a site-local Drush
         $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
         $this->assertEquals(realpath($drush_root . '/drush.php'), realpath($drush_location));
         // Ensure that --local was NOT added
         $result = $this->drush('ev', array('return drush_get_option("local");'), array('root' => $this->webroot()));
         $output = $this->getOutput();
         $this->assertEquals("", $output);
         // Run the `drush --root` test again, this time with
         // a drush.wrapper script in place.
         $this->createDrushWrapper($drush_base);
         $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
         $this->assertEquals(realpath($drush_root . '/drush.php'), realpath($drush_location));
         // Test to see if --local was added
         $result = $this->drush('ev', array('return drush_get_option("local");'), array('root' => $this->webroot()));
         $output = $this->getOutput();
         $this->assertEquals("TRUE", $output);
         // Get rid of the symlink and site-local Drush we created
         $this->remove_site_local_drush($drush_base);
     }
     // Next, try again with a site-local Drush in a location
     // that Drush does not search.
     $mysterious_location = "path/drush/does/not/search";
     $drush_root = $this->create_site_local_drush($mysterious_location);
     // We should not find the site-local Drush without a Drush wrapper.
     $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
     $this->assertEquals($globalDrushDotPhp, $drush_location);
     $this->createDrushWrapper($mysterious_location);
     // Now that there is a Drush wrapper, we should be able to find the site-local Drush.
     $drush_location = $this->getDrushLocation(array('root' => $this->webroot()));
     $this->assertEquals(realpath($drush_root . '/drush.php'), $drush_location);
 }
示例#11
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The paths must be strings. Got: array
  */
 public function testJoinFailsIfInvalidPath()
 {
     Path::join('/path', array());
 }
示例#12
0
文件: Kernel.php 项目: nanbando/core
 /**
  * {@inheritdoc}
  */
 public function getLogDir()
 {
     $logDir = Path::join([getcwd(), NANBANDO_DIR, 'app', 'log']);
     $filesystem = new Filesystem();
     $filesystem->mkdir($logDir);
     return $logDir;
 }
示例#13
0
 /**
  * @param string $collection
  * @return string
  */
 protected function getCollectionDirectory($collection)
 {
     return Path::join($this->directory, strtolower($collection));
 }
示例#14
0
 public function testPushExistsRemote()
 {
     $zipPath = Path::join([DATAFIXTURES_DIR, 'backups', '13-21-2016-05-29_success.zip']);
     $file = '123-123-123';
     $path = sprintf('%s/%s.zip', $this->name, $file);
     $this->localFilesystem->readStream($path)->willReturn(file_get_contents($zipPath));
     $this->remoteFilesystem->has($path)->willReturn(true);
     $this->remoteFilesystem->putStream($path, Argument::any())->shouldNotBeCalled();
     $this->storage->push($file);
 }
示例#15
0
文件: SqlBase.php 项目: jibran/drush
 public function dumpFile($file)
 {
     $database = $this->db_spec['database'];
     // $file is passed in to us usually via --result-file.  If the user
     // has set $options['result-file'] = TRUE, then we
     // will generate an SQL dump file in the same backup
     // directory that pm-updatecode uses.
     if ($file) {
         if ($file === TRUE) {
             // User did not pass a specific value for --result-file. Make one.
             $backup = drush_include_engine('version_control', 'backup');
             $backup_dir = $backup->prepare_backup_dir($database);
             if (empty($backup_dir)) {
                 $backup_dir = drush_find_tmp();
             }
             $file = Path::join($backup_dir, '@DATABASE_@DATE.sql');
         }
         $file = str_replace(array('@DATABASE', '@DATE'), array($database, gmdate('Ymd_His')), $file);
     }
     return $file;
 }
示例#16
0
 /**
  * Returns the uris associated with a source file.
  *
  * @param string $sourceFile
  *
  * @return array
  */
 public function getUris($sourceFile)
 {
     $relativePath = substr($sourceFile, strlen(Glob::getBasePath($this->pattern)));
     return [Path::join(Glob::getBasePath($this->uriPattern), $relativePath)];
 }
示例#17
0
<?php

use Webmozart\PathUtil\Path;
$file = __DIR__ . '/../vendor/autoload.php';
if (!file_exists($file)) {
    throw new RuntimeException('Install dependencies to run test suite.');
}
$loader = (require $file);
define('RESOURCE_DIR', Path::join([__DIR__, 'Resources']));
define('DATAFIXTURES_DIR', Path::join([__DIR__, 'DataFixtures']));
return $loader;
示例#18
0
<?php

set_time_limit(0);
define('NANBANDO_DIR', getenv('NANBANDO_DIR') ?: '.nanbando');
use Dflydev\EmbeddedComposer\Core\EmbeddedComposerBuilder;
use Nanbando\Application\Application;
use Nanbando\Application\Kernel;
use Puli\Discovery\JsonDiscovery;
use Symfony\Component\Console\Input\ArgvInput;
use Webmozart\PathUtil\Path;
$input = new ArgvInput();
if ($projectDir = $input->getParameterOption('--root-dir')) {
    if (false !== strpos($projectDir, '~') && function_exists('posix_getuid')) {
        $info = posix_getpwuid(posix_getuid());
        $projectDir = str_replace('~', $info['dir'], $projectDir);
    }
    if (!is_dir($projectDir)) {
        throw new \InvalidArgumentException(sprintf('Specified project directory %s does not exist', $projectDir));
    }
    chdir($projectDir);
}
$discovery = new JsonDiscovery(Path::join([getcwd(), NANBANDO_DIR, '.puli', 'bindings.json']));
$embeddedComposerBuilder = new EmbeddedComposerBuilder($classLoader);
$embeddedComposer = $embeddedComposerBuilder->setComposerFilename('nanbando.json')->setVendorDirectory(NANBANDO_DIR)->build();
$embeddedComposer->processAdditionalAutoloads();
$kernel = new Kernel('prod', true, Path::getHomeDirectory(), $discovery);
$kernel->boot();
$input = $kernel->getContainer()->get('input');
$output = $kernel->getContainer()->get('output');
$application = new Application($kernel, $embeddedComposer);
$application->run($input, $output);
示例#19
0
 /**
  * @param string $path
  * @param AbstractLogger $logger
  * @return Result
  */
 private function getResult($path, AbstractLogger $logger)
 {
     if (is_file($path)) {
         $logger->writeln(sprintf('import file "%s"', $path));
         return $this->importer->import($path);
     }
     $file = Path::join($path, '.simpspector.yml');
     $logger->writeln(sprintf('load config "%s"', $file));
     $config = $this->loader->load($file);
     $logger->writeln('execute gadgets');
     return $this->executor->run($path, $config, $logger);
 }
示例#20
0
 private function actionsForReplaceRule($rootDirectory, ReplaceRule $rule)
 {
     $fullGlobPattern = Path::join([$rootDirectory, $rule->getPattern()]);
     return $this->actionForGlob("replace", $rootDirectory, $fullGlobPattern);
 }