skar / laminas-doctrine-orm
简单的 Laminas/Mezzio Doctrine ORM 集成
0.2
2024-02-04 05:32 UTC
Requires
- php: ^8.1 || ^8.2 || ^8.3
- doctrine/migrations: ^3.3.0
- doctrine/orm: ^3.0.0
- laminas/laminas-cli: ^1.0.0
- laminas/laminas-servicemanager: ~3.3 || ~4.0
- psr/container: ^1.0 || ^2.0
- skar/php-cache: ^0.1
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.0 || ^10.0 || ^11.0
- squizlabs/php_codesniffer: ^3.5.0
Suggests
- doctrine/migrations: doctrine migrations if you want to keep your schema definitions versioned
This package is auto-updated.
Last update: 2024-09-11 19:46:12 UTC
README
简单的 Laminas/Mezzio Doctrine ORM 集成。
请随时报告错误和缺少的功能。
使用
配置
创建配置文件 config/autoload/doctrine.global.php
,包含最小配置
doctrine
- doctrine 配置的键
有关更多可能的配置,请参阅 Doctrine 文档
示例配置
<?php declare(strict_types=1); use Doctrine\DBAL\Driver\PDO\MySQL\Driver; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; return [ 'doctrine' => [ 'connection' => [ 'orm_default' => [ 'driver_class' => Driver::class, 'params' => [ 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'password' => 'root', 'dbname' => 'database', ], ], ], 'driver' => [ 'orm_default' => [ 'drivers' => [ 'App\Entity' => [ 'class' => AnnotationDriver::class, 'paths' => [ 'src/Entity', ], ], ], ], ], ], ];
迁移命令
命令使用 Laminas CLI 和 vendor/bin/laminas
入口
可能的命令
doctrine:migrations:diff [diff] Generate a migration by comparing your current database to your mapping information.
doctrine:migrations:dump-schema [dump-schema] Dump the schema for your database to a migration.
doctrine:migrations:execute [execute] Execute a single migration version up or down manually.
doctrine:migrations:generate [generate] Generate a blank migration class.
doctrine:migrations:latest [latest] Outputs the latest version number
doctrine:migrations:migrate [migrate] Execute a migration to a specified version or the latest available version.
doctrine:migrations:rollup [rollup] Rollup migrations by deleting all tracked versions and insert the one version that exists.
doctrine:migrations:status [status] View the status of a set of migrations.
doctrine:migrations:up-to-date [up-to-date] Tells you if your schema is up-to-date.
doctrine:migrations:version [version] Manually add and delete migration versions from the version table.
示例
$ vendor/bin/laminas doctrine:migrations:diff
$ vendor/bin/laminas doctrine:migrations:migrate
TODO
- 测试
- 将此库拆分为独立的 DBAL、ORM 和迁移库
- 添加库支持(认证、分页等)
WHY
因为 DoctrineORMModule 只适用于 Laminas(完整的 MVC),但我需要 Mezzio 的简单集成。