task/filesystem 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

task/filesystem

Composer 安装命令:

composer require task/filesystem

包简介

Filesystem plugin for Task

README 文档

README

Build Status Coverage Status

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

统计信息

  • 总下载量: 2.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固