vespula / spot-tools
一个用于从现有数据库表中生成SpotORM实体的库。
Requires
- php: >=5.4
- doctrine/dbal: ^2.5
- league/climate: ^3.2
Requires (Dev)
- ext-sqlite3: *
- phpmd/phpmd: @stable
- phpunit/phpunit: 4.8.*
This package is auto-updated.
Last update: 2024-09-14 10:53:37 UTC
README
说明
此脚本及其相关库用于从现有数据库表中生成SpotORM实体文件。主要用途是创建映射表列的fields
数组。手动创建这个数组可能会有些繁琐。
脚本创建两个文件。一个是实体类,必须扩展\Spot\Entity(可以通过扩展\Spot\Entity的基类,或者直接扩展\Spot\Entity。第二个文件是字段元数据数组。由于这两个文件是分开的,所以它使得重新生成元数据变得容易,而不会影响实体类。
此脚本不创建关系定义,但在创建实体后提供了一个占位符方法来定义它们。
安装
这是一个PHP脚本,因此您必须安装PHP CLI才能使其工作。
composer require vespula/spot-tools
。如果您不知道composer是什么,请查看composer的文档以获取更多信息。
- 您需要一个名为
spot-config.php
的配置文件。源文件夹中有一个示例。您的配置文件应如下所示
<?php
return [
'db_url'=>'mysql://user:passwd@localhost/dbname',
'entity_folder'=>'/path/to/entities'
];
如果您将配置文件放在与运行脚本相同的文件夹中,它将被自动加载。例如,与您的composer.json文件在同一个位置。
您可以使用
-f
开关指定配置文件。
$ ./vendor/bin/spot-entity -t mytable -f src/Vendor/spot-config.php
用法
要获取命令行选项的帮助,请输入
./vendor/bin/spot-entity -h
尝试预览,请输入:
./vendor/bin/spot-entity -t mytable -p
这将输出字段元数据和实体类到屏幕,而不会写入任何文件。这可能很有用,以便查看将生成什么。
要使用默认选项生成文件,请使用
./vendor/bin/spot-entity -t mytable
这将创建配置输出文件夹中的两个文件。第一个是实体类,命名为Mytable.php
。第二个将保存在metadata
子文件夹中,也将命名为Mytable.php
。
如果您打开生成的实体类,您将看到一个名为fields()
的方法,它将通过include语句引用元数据文件。这很有用,因为您可以在不替换或干扰实体文件的情况下重新运行./vendor/bin/spot-tools
脚本并选择覆盖元数据字段定义。
命令选项
Usage: ./bin/spot-entity [-c classname, --classname classname] [-e extends, --extends extends (default: \Spot\Entity)] [-f file, --file file (default: spot-config.php)] [-h help, --help help] [-n namespace, --namespace namespace] [-o, --overwrite] [-p, --preview] [-t table, --table table]
Required Arguments:
-t table, --table table
The table you want to reverse
Optional Arguments:
-f file, --file file (default: spot-config.php)
The config file you want to use. Defaults to `spot-config.php`.
-e extends, --extends extends (default: \Spot\Entity)
The class this entity should extend
-n namespace, --namespace namespace
The namespace for this class
-p, --preview
Write out the class to screen to preview
-c classname, --classname classname
The name of the entity if you don't want to use the defaults.
-o, --overwrite
Overwrite existing metadata field file
-h help, --help help
Show help