hamichen / laminas-doctrine-orm
简单的Laminas/Mezzio Doctrine ORM集成
1.0.1
2022-08-23 08:34 UTC
Requires
- php: ^8.1 || ^8.0 || ^7.4
- doctrine/migrations: ^3.5
- doctrine/orm: ^2.10.0
- hamichen/php-cache: ^1.0.0
- laminas/laminas-cli: ^1.0.0
- laminas/laminas-servicemanager: ~3.3 || ~4.0
- psr/container: ^1.0
Requires (Dev)
- phpunit/phpunit: ~8.5.0 || ~9.3.0
- squizlabs/php_codesniffer: ~3.5.0
Suggests
- doctrine/migrations: doctrine migrations if you want to keep your schema definitions versioned
This package is not auto-updated.
Last update: 2024-09-18 14:07:58 UTC
README
简单的Laminas/Mezzio Doctrine ORM集成。
请随意报告错误和缺失的功能。
使用
配置
创建配置文件 config/autoload/doctrine.global.php
,其中包含最小配置
doctrine
- Doctrine配置的键连接
orm_default
driver_class
-\Doctrine\DBAL\Driver
实现的全名params
- 驱动程序参数
driver
- 映射驱动程序配置orm_default
drivers
- 键必须是实体(例如
App\Entity
)的命名空间class
-MappingDriver
的全名paths
- 包含实体的目录数组
- 键必须是实体(例如
有关更多可能的配置,请参阅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
待办事项
- 测试
- 将此库拆分为单独的DBAL、ORM和迁移库
- 添加库支持(认证、分页等)
原因
因为DoctrineORMModule仅适用于Laminas(完整MVC),但我需要Mezzio的简单集成。