定制 angrybytes/filegen 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

angrybytes/filegen

最新稳定版本:0.5.1

Composer 安装命令:

composer require angrybytes/filegen

包简介

A PHP File and Directory Generating Tool

README 文档

README

PHP checks

Note: this is a fork of the original project as it appears to be abandoned.

A small tool to aid in the creation of (complicated) file and directory

layouts.

use Naneau\FileGen\Structure;
use Naneau\FileGen\Generator;

// Specify a structure to be generated
$structure = new Structure;
$structure
    ->directory('foo')
    ->file('bar/baz', 'these are the file contents');
    ->link('/some/file/somewhere', 'qux');

// Generate the structure
$generator = new Generator('/output/directory');
$generator->generate($structure);

will output:

- /output/directory/
    - foo/
    - bar/
        - baz
    - qux => /some/file/somewhere

Examples

Copy A File

Copying an existing file to a new file in the structure to be generated is easy.

use Naneau\FileGen\Structure;
use Naneau\FileGen\File\Contents\Copy;

$structure = new Structure;
$structure->file('foo', new Copy('/from/this/file'));

Use a Twig Template

Files can be given content using a Twig template.

use Naneau\FileGen\Structure;
use Naneau\FileGen\File\Contents\Twig;

// $twig = ...

// Load a template
$template = $twig->load('some_template.twig');

// Parameters for the template
$parameters = array('foo' => 'bar')

$structure = new Structure;
$structure->file('foo', new Twig($template, $parameters));

Set up A Parameter Specification Alongside A Structure

In some cases you'll want to specify parameters to be used by your structure beforehand. These parameters can then be queried for using the console helper (see below), and used in Twig templates.

use Naneau\FileGen\Generator;
use Naneau\FileGen\Structure;
use Naneau\FileGen\File\Contents\Twig;

// $twig = ...
$template = ;
$structure = new Structure;
$structure
    // A parameter "foo" is expected
    ->param('foo')

    // A bar parameter with a description
    ->param('bar', 'Please specify "bar"')

    // Can use {{ foo }} and {{ bar }}
    ->file('someFile', new Twig($twig->load('someFile.twig'));

    // Can also use {{ foo }} and {{ bar }}
    ->file('anotherFile', new Twig($twig->load('anotherFile.twig'));

// Set a default value for foo
$structure->getParameterDefinition()->get('foo')->setDefaultValue('Foo!');

// Pass values for the structure's parameters to the generator
$generator = new Generator('/output/directory', array(
    'foo' => 'foo!'
    'bar' => 12345
));

// Generate the structure
$generator->generate($structure);

Console Helper

FileGen ships with a a (Symfony Console Helper](http://symfony.com/doc/current/components/console/introduction.html#console-helpers) that will use the built-in question helper to ask for parameter values.

Simply add the helper to your console helper set:

use Naneau\FileGen\Console\Helper\ParameterHelper;

// $application = ...
$application->getHelperSet()->set(new ParameterHelper, 'filegenParameters');

And use it in your commands:

protected function execute(InputInterface $input, OutputInterface $output)
{
    // $structure = ...

    $helper = $this->getHelper('filegenParameters');

    // Ask for all parameters one by one
    $parameters = $helper->askParameters($structure, $input, $output);

    // Ask for a single parameter
    $fooParameter = $structure->getParameterDefinition()->get('foo');
    $fooValue = $helper->askParameter($fooParameter, $input, $output);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-04