madflow/cheesecake

从模板创建项目或目录结构

3.1 2024-02-21 09:45 UTC

This package is not auto-updated.

Last update: 2024-09-11 15:21:52 UTC


README

Cheesecake 是一个用于 PHP 的项目/目录骨架生成工具。它受到 https://github.com/audreyr/cookiecutter 的启发。

安装

    $ composer require madflow/cheesecake
    $ ./vendor/bin/cheesecake

在不使用命令行的情况下使用它

    $template = __DIR__ .'/mytemplate';
    $output = __DIR__ .'/myoutput';
    $params = ['project_name' => 'Yeah!'];
    $options = [
        Generator::OPT_OUTPUT => $output,
        Generator::OPT_NO_INTERACTION => true,
    ];
    $o = new Generator($template, $params, $options);
    $o->run();

开发

# Clone the repo
git clone https://github.com/madflow/cheesecake.git

# Install dependencies
cd cheesecake
composer install

示例

创建一个 Silex 入门项目
# Create output directory
mkdir /tmp/silex

# Mmmh  - Cheesecake
./bin/cheesecake -o /tmp/silex examples/silex-starter

钩子

将钩子放在 hooks 目录中,并命名为 pre_gen.phppost_gen.php

技巧

  • 在处理 Twig 模板时,Mustache 引擎会尝试解释如 {{ okay | upper }} 这样的表达式,并将失败并抛出 Mustache_Exception_UnknownFilterException: Unknown filter: upper
  • 为了绕过这个问题,你可以在你的 cheesecake.json 文件中定义一个魔法 filters_ignore 参数。
    {
        "app_name": "twig",
        "filters_ignore": ["upper"]
    }
  • filters_ignore 接受一个字符串数组,这些字符串将被转换为虚拟过滤器。