skar / laminas-doctrine-orm
Simple Laminas/Mezzio Doctrine ORM integration
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-12-08 19:33:35 UTC
README
Simple Laminas/Mezzio Doctrine ORM integration.
Please feel free to report bugs and missing features.
Using
Configuration
Create config file config/autoload/doctrine.global.php
with minimal config:
doctrine
- Key for doctrine configconnection
orm_default
driver_class
- The full name of\Doctrine\DBAL\Driver
implementationparams
- The connection driver parameters
driver
- Mapping driver configurationorm_default
drivers
- Key must be a namespace for entities (e.g.
App\Entity
)class
- The full name of the metadata driverpaths
- An array of directories containing your entities
- Key must be a namespace for entities (e.g.
See the Doctrine documentation for more possible configurations.
Example Configuration
<?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', ], ], ], ], ], ], ];
Migrations Commands
Commands uses Laminas CLI and vendor/bin/laminas
entry point for it
Possible commands
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.
Example
$ vendor/bin/laminas doctrine:migrations:diff
$ vendor/bin/laminas doctrine:migrations:migrate
TODO
- Tests
- Split this library into separate DBAL, ORM and Migrations libraries
- Add libraries support (auth, pagination etc)
WHY
Because DoctrineORMModule is only for Laminas (full MVC) but I need simple integration for Mezzio.