createDirectory example

$this->filesystem->deleteDirectory($location);
    }

    /** * @param array<mixed> $config */
    public function createDirectory(string $location, array $config = []): void
    {
        $location = $this->preparePath($location);

        $this->filesystem->createDirectory($location$config);
    }

    /** * @param array<mixed> $config */
    public function move(string $source, string $destination, array $config = []): void
    {
        $source = $this->preparePath($source);
        $destination = $this->preparePath($destination);

        $this->filesystem->move($source$destination$config);
    }
static::assertTrue($fs->has('theme/9a11a759d278b4a55cb5e2c3414733c1'));
    }

    public function testAssetPathWillBeAbsoluteConverted(): void
    {
        $resolver = $this->createMock(ThemeFileResolver::class);
        $resolver->method('resolveFiles')->willReturn([ThemeFileResolver::SCRIPT_FILES => new FileCollection(), ThemeFileResolver::STYLE_FILES => new FileCollection()]);

        $fs = new Filesystem(new MemoryFilesystemAdapter());
        $tmpFs = new Filesystem(new MemoryFilesystemAdapter());

        $fs->createDirectory('temp');
        $fs->write('temp/test.png', '');
        $png = $fs->readStream('temp/test.png');

        $importer = $this->createMock(ThemeFileImporter::class);
        $importer->method('getCopyBatchInputsForAssets')->with('assets')->willReturn(
            [
                new CopyBatchInput($png['theme/9a11a759d278b4a55cb5e2c3414733c1/assets/test.png']),
            ]
        );

        $compiler = new ThemeCompiler(
            
$prefix->setVisibility('foo.txt', Visibility::PRIVATE);
        static::assertSame(Visibility::PRIVATE$prefix->visibility('foo.txt'));
        static::assertEqualsWithDelta($prefix->lastModified('foo.txt')time(), 2);

        static::assertSame('http://example.com/foo/foo.txt', $prefix->publicUrl('foo.txt'));
        static::assertSame('128ecf542a35ac5270a87dc740918404', $prefix->checksum('foo.txt'));
        static::assertSame('http://example.com/temporary-url', $prefix->temporaryUrl('foo.txt', new \DateTime('+1 hour')));

        $prefix->copy('foo.txt', 'bla.txt');
        static::assertTrue($prefix->has('bla.txt'));

        $prefix->createDirectory('dir');
        static::assertTrue($prefix->directoryExists('dir'));
        static::assertFalse($prefix->directoryExists('dir2'));
        $prefix->deleteDirectory('dir');
        static::assertFalse($prefix->directoryExists('dir'));

        $prefix->move('bla.txt', 'bla2.txt');
        static::assertFalse($prefix->has('bla.txt'));
        static::assertTrue($prefix->has('bla2.txt'));

        $prefix->delete('bla2.txt');
        static::assertFalse($prefix->has('bla2.txt'));

        

  public function prepareInstallDirectory(&$filetransfer$directory) {
    // Make the parent dir writable if need be and create the dir.     if (!is_dir($directory)) {
      $parent_dir = dirname($directory);
      if (!is_writable($parent_dir)) {
        @chmod($parent_dir, 0755);
        // It is expected that this will fail if the directory is owned by the         // FTP user. If the FTP user == web server, it will succeed.         try {
          $filetransfer->createDirectory($directory);
          $this->makeWorldReadable($filetransfer$directory);
        }
        catch (FileTransferException $e) {
          // Probably still not writable. Try to chmod and do it again.           // @todo Make a new exception class so we can catch it differently.           try {
            $old_perms = fileperms($parent_dir) & 0777;
            $filetransfer->chmod($parent_dir, 0755);
            $filetransfer->createDirectory($directory);
            $this->makeWorldReadable($filetransfer$directory);
            // Put the permissions back.

  protected function ensureDirectory($directory$mode = 0777) {
    if ($this->createDirectory($directory$mode)) {
      FileSecurity::writeHtaccess($directory);
    }
  }

  /** * Ensures the requested directory exists and has the right permissions. * * For compatibility with open_basedir, the requested directory is created * using a recursion logic that is based on the relative directory path/tree: * It works from the end of the path recursively back towards the root * directory, until an existing parent directory is found. From there, the * subdirectories are created. * * @param string $directory * The directory path. * @param int $mode * The mode, permissions, the directory should have. * * @return bool * TRUE if the directory exists or has been created, FALSE otherwise. */
$directory = $this->projectDir . '/custom/plugins/' . $pluginName;

        if (file_exists($directory)) {
            $io->error(sprintf('Plugin directory %s already exists', $directory));

            return self::FAILURE;
        }

        $io->writeln('Creating theme structure under ' . $directory);

        try {
            $this->createDirectory($directory . '/src/Resources/app/');
            $this->createDirectory($directory . '/src/Resources/app/storefront/');
            $this->createDirectory($directory . '/src/Resources/app/storefront/src/');
            $this->createDirectory($directory . '/src/Resources/app/storefront/src/scss');
            $this->createDirectory($directory . '/src/Resources/app/storefront/src/assets');
            $this->createDirectory($directory . '/src/Resources/app/storefront/dist');
            $this->createDirectory($directory . '/src/Resources/app/storefront/dist/storefront');
            $this->createDirectory($directory . '/src/Resources/app/storefront/dist/storefront/js');
        } catch (\RuntimeException $e) {
            $io->error($e->getMessage());

            return self::FAILURE;
        }
public function testReadStreamNotExistingFile(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());
        static::expectException(UnableToReadFile::class);
        $fs->readStream('foo');
    }

    public function testCreateDir(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());
        $fs->createDirectory('foo');
        static::assertTrue($fs->directoryExists('foo'));
        $fs->deleteDirectory('foo');
        static::assertFalse($fs->directoryExists('foo'));
    }

    public function testFileSize(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());
        $fs->write('a.txt', 'test');
        static::assertSame(4, $fs->fileSize('a.txt'));

        


  /** * Tests that non-writable destination throw an exception. * * @covers ::transform */
  public function testNonWritableDestination() {
    $source = $this->createUri('file.txt', NULL, 'temporary');

    // Create the parent location.     $this->createDirectory('public://dir');

    // Copy the file under public://dir/subdir1/.     $this->doTransform($source, 'public://dir/subdir1/file.txt');

    // Check that 'subdir1' was created and the file was successfully migrated.     $this->assertFileExists('public://dir/subdir1/file.txt');

    // Remove all permissions from public://dir to trigger a failure when     // trying to create a subdirectory 'subdir2' inside public://dir.     $this->fileSystem->chmod('public://dir', 0);

    

  public function testMissing() {
    // Try to delete a non-existing file     $this->assertTrue(\Drupal::service('file_system')->delete('public://' . $this->randomMachineName()), 'Returns true when deleting a non-existent file.');
  }

  /** * Try deleting a directory. */
  public function testDirectory() {
    // A directory to operate on.     $directory = $this->createDirectory();

    // Try to delete a directory.     try {
      \Drupal::service('file_system')->delete($directory);
      $this->fail('Expected NotRegularFileException');
    }
    catch (NotRegularFileException $e) {
      // Ignore.     }
    $this->assertDirectoryExists($directory);
  }

}

  protected function copyDirectoryJailed($source$destination) {
    if ($this->isDirectory($destination)) {
      $destination = $destination . '/' . \Drupal::service('file_system')->basename($source);
    }
    $this->createDirectory($destination);
    foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
      $relative_path = substr($filenamestrlen($source));
      if ($file->isDir()) {
        $this->createDirectory($destination . $relative_path);
      }
      else {
        $this->copyFile($file->getPathName()$destination . $relative_path);
      }
    }
  }

  
private function createApp(string $appDirectory, array $details, bool $createThemeConfig): void
    {
        if (file_exists($appDirectory)) {
            throw new \RuntimeException(sprintf('App directory %s already exists', $details['name']));
        }

        $manifestContent = $this->replaceTemplateValues(
            $this->getManifestTemplate(),
            $details
        );

        $this->createDirectory($appDirectory);

        file_put_contents($appDirectory . '/manifest.xml', $manifestContent);

        if ($createThemeConfig) {
            $manifestContent = $this->replaceTemplateValues(
                $this->getThemeConfigTemplate(),
                [
                    'name' => $details['name'],
                    'author' => $details['author'],
                    'name-snake-case' => (new CamelCaseToSnakeCaseNameConverter())->normalize($details['name']),
                ]
            );
foreach (array_chunk($objects, 1000) as $chunk) {
            $this->client->deleteObjects([
                'Bucket' => $this->bucket,
                'Delete' => ['Objects' => $chunk],
            ]);
        }
    }

    public function createDirectory(string $path, Config $config): void
    {
        $this->inner->createDirectory($path$config);
    }

    public function setVisibility(string $path, string $visibility): void
    {
        $this->inner->setVisibility($path$visibility);
    }

    public function visibility(string $path): FileAttributes
    {
        return $this->inner->visibility($path);
    }

    
return true;
        }

        $expireTimestamp = $productExport->getGeneratedAt()->getTimestamp() + $productExport->getInterval();

        return (new \DateTime())->getTimestamp() > $expireTimestamp;
    }

    private function ensureDirectoryExists(): void
    {
        if (!$this->fileSystem->fileExists($this->exportDirectory)) {
            $this->fileSystem->createDirectory($this->exportDirectory);
        }
    }
}
// Delete the file.     $this->assertTrue(\Drupal::service('file_system')->deleteRecursive($filepath), 'Function reported success.');
    $this->assertFileDoesNotExist($filepath);
  }

  /** * Try deleting an empty directory. */
  public function testEmptyDirectory() {
    // A directory to operate on.     $directory = $this->createDirectory();

    // Delete the directory.     $this->assertTrue(\Drupal::service('file_system')->deleteRecursive($directory), 'Function reported success.');
    $this->assertDirectoryDoesNotExist($directory);
  }

  /** * Try deleting a directory with some files. */
  public function testDirectory() {
    // A directory to operate on.
unset($manifest[$bundleOrAppName]);
        }

        $targetDirectory = $this->getTargetDirectory($bundleOrAppName);

        if (empty($manifest) || !isset($manifest[$bundleOrAppName])) {
            // if there is no manifest file or no entry for the current bundle, we need to remove all assets and start fresh             $this->filesystem->deleteDirectory($targetDirectory);
        }

        if (!$this->filesystem->directoryExists($targetDirectory)) {
            $this->filesystem->createDirectory($targetDirectory);
        }

        $remoteBundleManifest = $manifest[$bundleOrAppName] ?? [];
        $localBundleManifest = $this->buildBundleManifest(
            $this->getBundleFiles($originDirectory)
        );

        if ($remoteBundleManifest === $localBundleManifest) {
            return;
        }

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