定制 paulhenri-l/generator 二次开发

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

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

paulhenri-l/generator

Composer 安装命令:

composer require paulhenri-l/generator

包简介

Generate files from their specification

README 文档

README

Tests License: MIT

Generate files from a specification. This tool is useful in scaffold commands.

Installation

You just need to require the package.

composer require paulhenri-l/generator

Usage

Generator use specifications to generate new files. A specification is a class that implements the PaulhenriL\Generator\GeneratorSpecification interface.

You then pass this specification to the generate method of the Generator

$generator = new \PaulhenriL\Generator\Generator();

$spec = new HelloWorld('Paul-Henri');

$generator->generate($spec);

Defining a specification

Here's a sample specification.

<?php

use PaulhenriL\Generator\GeneratorSpecification;

class HelloWorld implements GeneratorSpecification
{
    /**
     * The Name to greet.
     *
     * @var string
     */
    protected $name;

    /**
     * HelloWorld constructor.
     */
    public function __construct(string $name)
    {
        $this->name = $name;
    }

    /**
     * The template to use for generation.
     */
    public function getTemplate(): string
    {
        // You may also store the template in another file and return it here
        // return file_get_contents('path/to/template');

        return "<h1>{{ name }}</h1>";
    }

    /**
     * Return the target path for the generated file.
     */
    public function getTargetPath(): string
    {
        return getcwd() . '/welcome.html';
    }

    /**
     * Return the replacements
     */
    public function getReplacements(): array
    {
        return [
            'name' => $this->name
        ];
    }

    /**
     * Return template processors.
     */
    public function getProcessors(): array
    {
        return [
            // Processors are callable that can process the file right before it
            // gets written to disk. Invokable classes are a good fit for this.
            //
            // new MyCustomProcessor(),
        ];
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固