ensureDirectoryExists example



  /** * 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;
  }

}
/** * @internal */
    public function __construct(
        private readonly FilesystemOperator $fileSystem,
        private readonly string $exportDirectory
    ) {
    }

    public function getFilePath(ProductExportEntity $productExport, bool $partialGeneration = false): string
    {
        $this->ensureDirectoryExists();

        $filePath = sprintf(
            '%s/%s',
            $this->exportDirectory,
            $productExport->getFileName()
        );

        if ($partialGeneration) {
            $filePath .= '.partial';
        }

        
// Do nothing if overwrite is 'false' and a file already exists at the     // destination.     if ($this->overwrite === FALSE && file_exists($destination_path)) {
      $interpolator = $destination->getInterpolator();
      $io->write($interpolator->interpolate(" - Skip <info>[dest-rel-path]</info> because it already exists and overwrite is <comment>false</comment>."));
      return new ScaffoldResult($destination, FALSE);
    }

    // Get rid of the destination if it exists, and make sure that     // the directory where it's going to be placed exists.     $fs->remove($destination_path);
    $fs->ensureDirectoryExists(dirname($destination_path));
    if ($options->symlink()) {
      return $this->symlinkScaffold($destination$io);
    }
    return $this->copyScaffold($destination$io);
  }

  /** * Copies the scaffold file. * * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath $destination * Scaffold file to process. * @param \Composer\IO\IOInterface $io * IOInterface to writing to. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult * The scaffold result. */

  public function mkTmpDir($prefix) {
    $tmpDir = $this->tmpDir($prefix);
    $filesystem = new Filesystem();
    $filesystem->ensureDirectoryExists($tmpDir);
    return $tmpDir;
  }

  /** * Create an isolated cache directory for Composer. */
  public function createIsolatedComposerCacheDir() {
    $cacheDir = $this->mkTmpDir('composer-cache');
    putenv("COMPOSER_CACHE_DIR=$cacheDir");
  }

  
if (empty($_contents)) {
            return false;
        }
        $_error_reporting = error_reporting();
        error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
        if ($smarty->_file_perms !== null) {
            $old_umask = umask(0);
        }

        $_dirpath = dirname($_filepath);
        // if subdirs, create dir structure         if ($_dirpath !== '.' && !self::ensureDirectoryExists($_dirpath$smarty->_dir_perms)) {
            error_reporting($_error_reporting);
            throw new SmartyException("unable to create directory {$_dirpath}");
        }

        // write to tmp file, then move to overt file lock race condition         $_tmp_file = $_dirpath . DS . uniqid('wrt', true);
        if (file_put_contents($_tmp_file$_contents) === false) {
            error_reporting($_error_reporting);
            umask($old_umask);
            throw new SmartyException("unable to write file {$_tmp_file}");
        }

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