task / filesystem
Filesystem plugin for Task
Installs: 2 787
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- symfony/filesystem: ~2.4
- task/plugin: ~1.0
Requires (Dev)
- bossa/phpspec2-expect: ~1.0
- henrikbjorn/phpspec-code-coverage: 1.0.*@dev
- mikey179/vfsstream: ~1.2
- satooshi/php-coveralls: ~0.6
- symfony/finder: ~2.4
- task/phpspec: ~0.1
- task/task: ~0.1
This package is not auto-updated.
Last update: 2024-12-21 16:25:50 UTC
README
Example
use Task\Plugin\FilesystemPlugin; use Symfony\Component\Finder\Finder; $project->inject(function ($container) { $container['fs'] = new FilesystemPlugin; }); $project->addTask('write', ['fs', function ($fs) { $fs->open('/tmp/foo')->write('wow'); }]); $project->addTask('read', ['fs', function ($fs) { $fs->read('/tmp/foo')->pipe($this->getOutput()); }]); $project->addTask('copy', ['fs', function ($fs) { $fs->copy('/tmp/foo', '/tmp/bar'); # OR $fs->read('/tmp/foo')->pipe($fs->touch('/tmp/bar')); }]); $project->addTask('copyTree', ['fs', function ($fs) { $finder = new Finder; $finder->name('foo')->in('/tmp/source'); $fs->copyTree('/tmp'source', '/tmp/target', $finder); }]);
Installation
Add to composer.json
:
... "require-dev": { "task/filesystem": "~0.2" } ...
Usage
Task\Plugin\FilesystemPlugin
extends Symfony's Filesystem
component object, overring some methods and providing some new ones. Many of these methods return streams which can be piped to other plugins.
open
open($filename, $mode = 'r+')
Returns Task\Plugin\Filesystem\File
, opened with the specified mode.
touch
FilesystemPlugin::touch($filename, $time = null, $atime = null)
See Symfony's Filesystem::touch
documentation for argument description. Returns Task\Plugin\Filesystem\File
, opened with r+
.
ls
ls($dir)
Returns Task\Plugin\Filesystem\FilesystemIterator
.
copy
copy($source, $target, $override = false)
Supports multiple operations, e.g.
Given:
use Task\Plugin\FilesystemPlugin; $fs = new FilesystemPlugin;
File to file:
/
foo
# @return File('bar') $fs->copy('foo', 'bar')
/
foo
bar
File to directory:
/
foo
bar/
# @return File('bar/foo') $fs->copy('foo', 'bar')
/
foo
bar/
foo
Link to link:
/
foo
bar -> foo
# @return File('wow') $fs->copy('foo', 'wow')
/
foo
bar -> foo
wow -> foo
Directory to directory:
/
foo/
bar
# @return FilesystemIterator('wow') $fs->copy('foo', 'wow')
/
foo/
bar
wow/
bar
mirror
mirror($originDir, $targetDir, Traversable $iterator = null, $options = [])
Mirror a directory, optionally providing a Traversable
instance to select or exclude files. Symfony's Finder
component is really good for this:
/
foo/
.git/
objects/
bar
baz
use Task\Plugin\FilesystemPlugin; use Symfony\Component\Finder\Finder; $finder = new Finder; $finder->ignoreVcs()->in('foo'); $fs = new FilesystemPlugin; # @return FilesystemIterator('wow') $fs->mirror('foo', 'wow', $finder);
/
foo/
.git/
objects/
bar
baz
wow/
bar
baz