rougin/combustor
Composer 安装命令:
composer require rougin/combustor
包简介
MVC code generator for Codeigniter 3.
README 文档
README
Combustor is a utility package for Codeigniter 3 that generates controllers, models, and views based on the provided database tables. It uses the Describe package for getting columns from a database table and as the basis for code generation.
Features
- Generates code based on the structure of the
Codeigniter 3framework; - Speeds up the code development for prototyping web applications;
- View templates can be based on Bootstrap and are upgradable; and
- Only worry on the database schema, and
Combustorwill do the rest.
Installation
Extract the contents of the latest Codeigniter 3 project first:
$ wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.13.zip $ unzip 3.1.13.zip -d ciacme
Then configure the project's database connectivity settings:
$ cd ciacme
$ nano application/config/database.php
// ciacme/application/config/database.php // ... $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysqli', // ... );
Next is to proceed in installing Combustor via Composer:
$ composer require rougin/combustor --dev
// ciacme/composer.json { // ... "require-dev": { "mikey179/vfsstream": "1.6.*", "phpunit/phpunit": "4.* || 5.* || 9.*", "rougin/combustor": "~1.0" } }
Lastly, install the ORM wrappers like Wildfire or Doctrine:
$ vendor/bin/combustor install:wildfire $ vendor/bin/combustor install:doctrine
Note
Using the install:wildfire command installs the Wildfire package while the install:doctrine installs the Credo package.
Reminders
Prior in executing any commands, kindly ensure that the database tables are defined properly (foreign keys, indexes, relationships, normalizations) in order to minimize the modifications after the code structure has been generated.
Also, please proceed first in generating models, views, or controllers to database tables that are having no relationship with other tables in the database.
Tip
Combustor will generate controllers, models, or views based on the specified database schema. If there's something wrong in the specified database schema, Combustor will generate a bad codebase.
Commands
create:layout
Create a new header and footer file.
Options
--bootstrap- adds styling based on Bootstrap--force- generates file/s even they already exists
Example
$ vendor/bin/combustor create-layout --bootstrap
create:controller
Create a new HTTP controller.
Arguments
table- name of the database table
Options
--doctrine- generates a Doctrine-based controller--wildfire- generates a Wildfire-based controller--empty- generates an empty HTTP controller--force- generates file/s even they already exists
Note
If either Wildfire or Doctrine is installed, no need to specify it as option for executing a specified command (e.g. --wildfire). However if both are installed, a command must have a --wildfire or --doctrine option added.
Example
$ vendor/bin/combustor create:controller users --wildfire
create:model
Create a new model.
Arguments
table- name of the database table
Options
--doctrine- generates a Doctrine-based model--wildfire- generates a Wildfire-based model--empty- generates an empty model--force- generates file/s even they already exists
Example
$ vendor/bin/combustor create:model users --wildfire
create:repository
Create a new entity repository.
Arguments
table- name of the database table
Options
--force- generates file/s even they already exists
Example
$ vendor/bin/combustor create:repository users
Note
This command is only applicable to a Doctrine implementation.
create:view
Create view templates.
Arguments
table- name of the database table
Options
--bootstrap- adds styling based on Bootstrap--doctrine- generates Doctrine-based views--wildfire- generates Wildfire-based views--force- generates file/s even they already exists
Example
$ vendor/bin/combustor create:view users --bootstrap
create:scaffold
Create a new HTTP controller, model, and view templates.
Arguments
table- name of the database table
Options
--bootstrap- adds styling based on Bootstrap--doctrine- generates a Doctrine-based controller, model, and views--wildfire- generates a Wildfire-based controller, model, and views--force- generates file/s even they already exists
Example
$ vendor/bin/combustor create:scaffold users --bootstrap --wildfire
Note
If --doctrine is selected, the command will also execute the create:repository command.
install:doctrine
Install the Doctrine package.
Example
$ vendor/bin/combustor install:doctrine
Note
- This command will be available if
Doctrineis not installed in the project. - It also adds a
Loader.phpin thecoredirectory. The said file is used for loading custom repositories extended toEntityRepository.
install:wildfire
Install the Wildfire package.
Example
$ vendor/bin/combustor install:wildfire
Note
This command will be available if Wildfire is not installed in the project.
remove:doctrine
Remove the Doctrine package.
Example
$ vendor/bin/combustor remove:doctrine
Note
This command will be available if Doctrine is installed in the project.
remove:wildfire
Remove the Wildfire package.
Example
$ vendor/bin/combustor remove:wildfire
Note
This command will be available if Wildfire is installed in the project.
Using combustor.yml
Combustor currently works out of the box after the configuration based on Installation. However, using a combustor.yml can be used for complex setups like specifying the new application path and excluding columns:
# combustor.yml app_path: %%CURRENT_DIRECTORY%%/Sample excluded_fields: - created_at - updated_at - deleted_at
To create a combustor.yml, simply run the initialize command:
$ vendor/bin/combustor initialize [PASS] "combustor.yml" added successfully!
app_path
This property specifies the application directory. It may updated to any directory (e.g., ciacme/application, ciacme/config, etc.) as long it can detect the config/config.php file from the defined directory:
# combustor.yml app_path: %%CURRENT_DIRECTORY%%/Sample # ...
Note
Combustor will try to check the path specified in app_path if it is a valid Codeigniter 3 project. Then it will perform another check if the application directory exists or if the config directory can be accessed directly from the directory defined in app_path.
excluded_fields
Specified fields in this property are excluded from generation to the following templates:
controllersmodelsviews(only forcreateandedittemplates)
# combustor.yml # ... excluded_fields: - created_at - updated_at - deleted_at
Note
The timestamps are added by default when creating a combustor.yml for the first time as they are usually populated automatically by installed ORMs such as Wildfire or Doctrine.
custom_fields
By default, all of the fields generated by Combustor to create and edit pages will use the form_input helper:
<div class="mb-3"> <?= form_label('Email', '', ['class' => 'form-label mb-0']) ?> <?= form_input('email', set_value('email'), 'class="form-control"') ?> <?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?> </div>
However, some fields like email and boolean types may need to use other form helpers:
<div class="mb-3"> <?= form_label('Email', '', ['class' => 'form-label mb-0']) ?> // Still using form_input, but the type is "email" instead <?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email'), 'class' => 'form-control']) ?> <?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?> </div>
<div class="mb-3"> <?= form_label('Admin', '', ['class' => 'form-label mb-0']) ?> // Use "form_checkbox" for boolean-based data types <div> <?= form_checkbox('admin', true, set_value('admin'), 'class="form-check-input"') ?> </div> <?= form_error('admin', '<div><span class="text-danger small">', '</span></div>') ?> </div>
To achieve this, Combustor provides a utility for handling specified field names or data types using custom_fields:
# combustor.yml # ... custom_fields: - Rougin\Combustor\Template\Fields\BooleanField
When adding a custom field, kindly create a class that extends to the Colfield class:
namespace Acme\Fields; use Rougin\Combustor\Colfield; class EmailField extends Colfield { protected $class = 'form-control'; /** * If $name is specified, it will check if the current field * name matches the in this $name field. */ protected $name = 'email'; public function getPlate() { $field = $this->accessor; $class = $this->getClass(); /** @var string */ $name = $this->getName(); $html = '<?= form_input([\'type\' => \'email\', \'name\' => \'' . $name . '\', \'value\' => set_value(\'' . $name . '\')]) ?>'; if ($this->edit) { $html = str_replace('set_value(\'' . $name . '\')', 'set_value(\'' . $name . '\', ' . $field . ')', $html); } $html = str_replace(')]) ?>', '), \'class\' => \'' . $class . '\']) ?>', $html); return array($html); } }
Then after creating the custom field, simply add the class name to the combustor.yml:
# combustor.yml # ... custom_fields: - Rougin\Combustor\Template\Fields\BooleanField - Acme\Fields\EmailField
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
rougin/combustor 适用场景与选型建议
rougin/combustor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.18k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2014 年 09 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「code-generator」 「crud-generator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rougin/combustor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rougin/combustor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rougin/combustor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Code generator for OpenAPI or Swagger specification files
A laravel package to generate CRUD by giving Model and database table column
Bootstrap 4 templates for the excellent code Generator from CrestApps
Base Skeleton for Laravel Application
User interface to help developpers with laravel-code-generator commands
CLI code generator for Nette Framework: scaffold modules, migrations, seeders, factories, authentication, API resources, form requests and more.
统计信息
- 总下载量: 4.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 6
其他信息
- 授权协议: MIT
- 更新时间: 2014-09-07