Filesystem Tasks

CleanDir

Deletes all files from specified dir, ignoring git files.

<?php
$this->taskCleanDir(['tmp','logs'])->run();
// as shortcut
$this->_cleanDir('app/cache');
?>

CopyDir

Copies one dir into another

<?php
$this->taskCopyDir(['dist/config' => 'config'])->run();
// as shortcut
$this->_copyDir('dist/config', 'config');
?>

DeleteDir

Deletes dir

<?php
$this->taskDeleteDir('tmp')->run();
// as shortcut
$this->_deleteDir(['tmp', 'log']);
?>

FilesystemStack

Wrapper for Symfony Filesystem Component. Comands are executed in stack and can be stopped on first fail with stopOnFail option.

<?php
$this->taskFilesystemStack()
     ->mkdir('logs')
     ->touch('logs/.gitignore')
     ->chgrp('www', 'www-data')
     ->symlink('/var/log/nginx/error.log', 'logs/error.log')
     ->run();

// one line
$this->_touch('.gitignore');
$this->_mkdir('logs');

?>

FlattenDir

Searches for files in a nested directory structure and copies them to a target directory with or without the parent directories. The task was inspired by gulp-flatten.

Example directory structure:

└── assets
    ├── asset-library1
    │   ├── README.md
    │   └── asset-library1.min.js
    └── asset-library2
        ├── README.md
        └── asset-library2.min.js

The following code will search the *.min.js files and copy them inside a new dist folder:

<?php
$this->taskFlattenDir(['assets/*.min.js' => 'dist'])->run();
// or use shortcut
$this->_flattenDir('assets/*.min.js', 'dist');
?>

You can also define the target directory with an additional method, instead of key/value pairs. More similar to the gulp-flatten syntax:

<?php
$this->taskFlattenDir(['assets/*.min.js'])
  ->to('dist')
  ->run();
?>

You can also append parts of the parent directories to the target path. If you give the value 1 to the includeParents() method, then the top parent will be appended to the target directory resulting in a path such as dist/assets/asset-library1.min.js.

If you give a negative number, such as -1 (the same as specifying array(0, 1) then the bottom parent will be appended, resulting in a path such as dist/asset-library1/asset-library1.min.js.

The top parent directory will always be starting from the relative path to the current directory. You can override that with the parentDir() method. If in the above example you would specify assets, then the top parent directory would be asset-library1.

<?php
$this->taskFlattenDir(['assets/*.min.js' => 'dist'])
  ->parentDir('assets')
  ->includeParents(1)
  ->run();
?>

MirrorDir

Mirrors a directory to another

<?php
$this->taskMirrorDir(['dist/config/' => 'config/'])->run();
// or use shortcut
$this->_mirrorDir('dist/config/', 'config/');

?>

TmpDir

Create a temporary directory that is automatically cleaned up once the task collection is is part of completes.

Use WorkDir if you do not want the directory to be deleted.

<?php
// Delete on rollback or on successful completion.
// Note that in this example, everything is deleted at
// the end of $collection->run().
$collection = $this->collectionBuilder();
$tmpPath = $collection->tmpDir()->getPath();
$collection->taskFilesystemStack()
          ->mkdir("$tmpPath/log")
          ->touch("$tmpPath/log/error.txt");
$collection->run();
// as shortcut (deleted when program exits)
$tmpPath = $this->_tmpDir();
?>

WorkDir

Create a temporary working directory that is automatically renamed to its final desired location if all of the tasks in the collection succeed. If there is a rollback, then the working directory is deleted.

<?php
$collection = $this->collectionBuilder();
$workingPath = $collection->workDir("build")->getPath();
$collection->taskFilesystemStack()
          ->mkdir("$workingPath/log")
          ->touch("$workingPath/log/error.txt");
$collection->run();
?>