Filesystem example


  protected function createTmpRepo($source$destParent$version) {
    $target = $destParent . '/' . basename($source);
    $filesystem = new Filesystem();
    $filesystem->copy($source$target);
    $this->mustExec("git init", $target);
    $this->mustExec('git config user.email "scaffoldtest@example.com"', $target);
    $this->mustExec('git config user.name "Scaffold Test"', $target);
    $this->mustExec("git add .", $target);
    $this->mustExec("git commit -m 'Initial commit'", $target);
    $this->mustExec("git tag $version", $target);
    return $target;
  }

}

  public static function generateAutoload(IOInterface $io$package_name$web_root$vendor) {
    $autoload_path = static::autoloadPath($package_name$web_root);
    // Calculate the relative path from the webroot (location of the project     // autoload.php) to the vendor directory.     $fs = new Filesystem();
    $relative_autoload_path = $fs->findShortestPath($autoload_path->fullPath(), "$vendor/autoload.php");
    file_put_contents($autoload_path->fullPath()static::autoLoadContents($relative_autoload_path));
    return new ScaffoldResult($autoload_path, TRUE);
  }

  /** * Determines whether or not the autoload file has been committed. * * @param \Composer\IO\IOInterface $io * IOInterface to write to. * @param string $package_name * The name of the package defining the autoload file (the root package). * @param string $web_root * The path to the web root. * * @return bool * True if autoload.php file exists and has been committed to the repository */

  public function getLocationReplacements() {
    return (new Interpolator())->setData($this->ensureLocations());
  }

  /** * Ensures that all of the locations defined in the scaffold files exist. * * Create them on the filesystem if they do not. */
  protected function ensureLocations() {
    $fs = new Filesystem();
    $locations = $this->getOptions()->locations() + ['web_root' => './'];
    $locations = array_map(function D$location) use ($fs) {
      $fs->ensureDirectoryExists($location);
      $location = realpath($location);
      return $location;
    }$locations);
    return $locations;
  }

}

    private $filesystem;

    public function __construct(
        OptimizerServiceInterface $optimizerService,
        MediaServiceInterface $mediaService,
        ?FilesystemInterface $filesystem = null
    ) {
        $this->optimizerService = $optimizerService;
        $this->mediaService = $mediaService;
        $this->filesystem = $filesystem ? $filesystem : new Filesystem(new Local(sys_get_temp_dir()));
    }

    /** * {@inheritdoc} */
    public function optimize($filepath)
    {
        // If the file is on the local filesystem we can optimize it directly         if ($this->mediaService->getAdapterType() === 'local') {
            $this->optimizerService->optimize($filepath);

            
/** * @param int $offset * * @throws RuntimeException * @throws Exception * * @return FinishResult|ValidResult */
    public function run($offset)
    {
        $fs = new Filesystem();
        $requestTime = time();

        try {
            $source = new Zip($this->source);
            $count = $source->count();
            $source->seek($offset);
        } catch (Exception $e) {
            @unlink($this->source);
            throw new Exception(sprintf('Could not open update package:<br>%s', $e->getMessage()), 0, $e);
        }

        
return $this->getLocalFilesystem();
    }

    /** * @return Filesystem */
    private function getLocalFilesystem()
    {
        $adapter = new LocalAdapter($this->baseDir);

        return new Filesystem($adapter);
    }

    /** * @return Filesystem */
    private function getRemoteFilesystem()
    {
        $adapter = new FtpAdapter(
            $this->remoteConfig['path'],
            $this->remoteConfig['server'],
            [
                
// Whatever happens here, this package counts as cleaned so that we don't     // process it more than once.     $package_name = strtolower($package->getName());
    $this->packagesAlreadyCleaned[$package_name] = TRUE;

    $package_dir = $this->getInstallPathForPackage($package);
    if (!is_dir($package_dir)) {
      return;
    }

    $this->io->writeError(sprintf('%sCleaning directories in <comment>%s</comment>', str_repeat(' ', 4)$package_name), TRUE, IOInterface::VERY_VERBOSE);
    $fs = new Filesystem();
    foreach ($paths_for_package as $cleanup_item) {
      $cleanup_path = $package_dir . '/' . $cleanup_item;
      if (!is_dir($cleanup_path)) {
        // If the package has changed or the --prefer-dist version does not         // include the directory. This is not an error.         $this->io->writeError(sprintf("%s<comment>Directory '%s' does not exist.</comment>", str_repeat(' ', 6)$cleanup_path), TRUE, IOInterface::VERY_VERBOSE);
        continue;
      }

      if (!$fs->removeDirectory($cleanup_path)) {
        // Always display a message if this fails as it means something
$this->container->set('kernel', $this);

        if ($oldContainer && $this->container::class !== $oldContainer->name) {
            // Because concurrent requests might still be using them,             // old container files are not removed immediately,             // but on a next dump of the container.             static $legacyContainers = [];
            $oldContainerDir = \dirname($oldContainer->getFileName());
            $legacyContainers[$oldContainerDir.'.legacy'] = true;
            foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy', \GLOB_NOSORT) as $legacyContainer) {
                if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
                    (new Filesystem())->remove(substr($legacyContainer, 0, -7));
                }
            }

            touch($oldContainerDir.'.legacy');
        }

        $preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir')) : [];

        if ($this->container->has('cache_warmer')) {
            $preload = array_merge($preload(array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
        }

        
if (in_array($oldPathstatic::$checkedDuplicates)) {
            return;
        }

        if ($oldPath !== $path && file_exists($oldPath) && $this->io->isInteractive()) {
            $this->io->writeError(' <error>Duplication of packages:</error>');
            $this->io->writeError(' <info>Package ' . $oldPath . ' will be called instead package ' . $path . '</info>');

            while (true) {
                switch ($this->io->ask(' <info>Delete ' . $oldPath . ' [y,n,?]?</info> ', '?')) {
                    case 'y':
                        $fs = new Filesystem();
                        $fs->removeDirectory($oldPath);
                        break 2;

                    case 'n':
                        break 2;

                    case '?':
                    default:
                        $this->io->writeError(array(
                            ' y - delete package ' . $oldPath . ' and to continue with the installation',
                            ' n - don\'t delete and to continue with the installation',
                        ));
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\PhpExecutableFinder;

/** * @group Build * @group TestSiteApplication */
class InstallTest extends BuildTestBase {

  public function testInstall() {
    $this->copyCodebase();
    $fs = new Filesystem();
    $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000);

    // Composer tells you stuff in error output.     $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-interaction');
    $this->assertErrorOutputContains('Generating autoload files');

    // We have to stand up the server first so we can know the port number to     // pass along to the install command.     $this->standUpServer();

    $php_finder = new PhpExecutableFinder();
    
$this->adapterFactories = $adapterFactoryArray;
    }

    /** * {@inheritdoc} */
    public function factory(array $config)
    {
        $config = $this->resolveFilesystemConfig($config);
        $factory = $this->findAdapterFactory($config['type']);

        return new Filesystem(
            $factory->create($config['config']),
            ['visibility' => $config['visibility']]
        );
    }

    /** * @param string $type * * @throws AdapterFactoryNotFoundException * * @return AdapterFactoryInterface */

    public function factory($backendName)
    {
        if (!isset($this->cdnConfig['adapters'][$backendName])) {
            throw new Exception(sprintf('Configuration "%s" not found', $backendName));
        }

        // Filesystem         $config = $this->cdnConfig['adapters'][$backendName];
        $adapter = $this->getAdapter($config);
        $filesystem = new Filesystem($adapter['visibility' => AdapterInterface::VISIBILITY_PUBLIC]);

        // Strategy         $strategyFactory = $this->container->get(\Shopware\Bundle\MediaBundle\Strategy\StrategyFactory::class);
        $strategyName = isset($config['strategy']) ? $config['strategy'] : $this->cdnConfig['strategy'];
        $strategy = $strategyFactory->factory($strategyName);

        return new MediaService($filesystem$strategy$this->container, $config);
    }

    /** * Collects third party adapters * * @param array $config * * @throws Enlight_Event_Exception * @throws Exception * * @return AdapterInterface */
    $dispatcher->dispatch(self::POST_DRUPAL_SCAFFOLD_CMD);
  }

  /** * Gets the path to the 'vendor' directory. * * @return string * The file path of the vendor directory. */
  protected function getVendorPath() {
    $vendor_dir = $this->composer->getConfig()->get('vendor-dir');
    $filesystem = new Filesystem();
    return $filesystem->normalizePath(realpath($vendor_dir));
  }

  /** * Gets a consolidated list of file mappings from all allowed packages. * * @param \Composer\Package\Package[] $allowed_packages * A multidimensional array of file mappings, as returned by * self::getAllowedPackages(). * * @return \Drupal\Composer\Plugin\Scaffold\Operations\OperationInterface[][] * An array of destination paths => scaffold operation objects. */
/** * The Fixtures object. * * @var \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures */
  protected $fixtures;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->projectRoot = $this->fixtures->projectRoot();
    // The directory used for creating composer projects to test can be     // configured using the SCAFFOLD_FIXTURE_DIR environment variable. Otherwise     // a directory will be created in the system's temporary directory.     $this->fixturesDir = getenv('SCAFFOLD_FIXTURE_DIR');
    if (!$this->fixturesDir) {
      $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    }
  }

  

  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. */
  
Home | Imprint | This part of the site doesn't use cookies.