Skip to content

Latest commit

 

History

History
271 lines (191 loc) · 6.45 KB

Filesystem.md

File metadata and controls

271 lines (191 loc) · 6.45 KB

Filesystem Tasks

CleanDir

Deletes all files from specified dir, ignoring git files.

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

  • param \Symfony\Component\Console\Output\OutputInterface $output

CopyDir

Copies one dir into another

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

  • link https://en.wikipedia.org/wiki/Chmod

  • exclude($exclude = null)

  • param string[] $exclude

  • overwrite($overwrite)

  • param bool $overwrite

  • setOutput($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output

DeleteDir

Deletes dir

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

  • param \Symfony\Component\Console\Output\OutputInterface $output

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');

?>
  • $this mkdir(string|array|\Traversable $dir, int $mode = 0777)

  • $this touch(string|array|\Traversable $file, int $time = null, int $atime = null)

  • $this copy(string $from, string $to, bool $force = false)

  • $this chmod(string|array|\Traversable $file, int $permissions, int $umask = 0000, bool $recursive = false)

  • $this chgrp(string|array|\Traversable $file, string $group, bool $recursive = false)

  • $this chown(string|array|\Traversable $file, string $user, bool $recursive = false)

  • $this remove(string|array|\Traversable $file)

  • $this rename(string $from, string $to, bool $force = false)

  • $this symlink(string $from, string $to, bool $copyOnWindows = false)

  • $this mirror(string $from, string $to, \Traversable $iterator = null, array $options = [])

  • stopOnFail($stop = null)

  • param bool $stop

  • setOutput($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output

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();
?>
  • dirPermissions($permission)

  • link https://en.wikipedia.org/wiki/Chmod

  • includeParents($parents)

  • param int|int[] $parents

  • parentDir($dir)

  • param string $dir

  • to($target)

  • param string $target

  • setOutput($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output

MirrorDir

Mirrors a directory to another

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

?>
  • setOutput($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output

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();
?>
  • cwd($shouldChangeWorkingDirectory = null)

  • param bool $shouldChangeWorkingDirectory

  • complete()

Delete this directory when our collection completes.

  • getPath()

  • return string

  • setOutput($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output

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();
?>
  • complete()

Move our working directory into its final destination once the

  • rollback()

Delete our working directory

  • getPath()

  • return string

  • cwd($shouldChangeWorkingDirectory = null)

  • param bool $shouldChangeWorkingDirectory

  • setOutput($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output