dtforce/nette-doctrine

Nette 框架的轻量级 Doctrine 集成扩展。

v1.0.0 2016-12-05 14:34 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:16:22 UTC


README

Scrutinizer Code Quality

nette-doctrine

Nette 框架的轻量级 Doctrine 集成扩展。此扩展是 Kdyby\Doctrine 的替代品,适用于希望使用原生 Doctrine 类且不想在 Nette 服务容器中自行注册实体管理器的用户。它与 Kdyby\Console 兼容。

配置

将扩展添加到 Nette 项目中,如下所示

extensions:
	doctrine: DTForce\DoctrineExtension\DI\DoctrineExtension

配置 Doctrine 访问和其他参数,如下所示

doctrine:
	connection:
		driver: pdo_pgsql
		host: localhost
		port: 5432
		user: username
		password: password
		dbname: database

	debug: true
	prefix: doctrine.default
	proxyDir: %tempDir%/cache/proxies
	sourceDir: %appDir%/Entity

	dbal:
		types:
			dateinterval: App\Doctrine\Postgresql\Types\DateIntervalType
		type_overrides:
			date: VasekPurchart\Doctrine\Type\DateTimeImmutable\DateTimeImmutableType
			datetime: VasekPurchart\Doctrine\Type\DateTimeImmutable\DateTimeImmutableType
			datetimetz: VasekPurchart\Doctrine\Type\DateTimeImmutable\DateTimeTzImmutableType
		schema_filter: "~^(?!nd_)~" # tables and sequences that start with nd_ are ingored by Doctrine

	functions:
		CAST: App\Doctrine\Postgresql\Functions\Cast

调整

映射类

要创建用于注解的类和实际实例化类之间的映射,创建一个实现 IClassMappingProvider 的 Nette 扩展。期望 getClassnameToClassnameMapping 方法返回使用用于注解的类作为键,实际实例化的类作为关联值的映射。

添加实体源目录

要为不同的扩展注册不同的源目录,让您的扩展实现 IEntitySourceProvider。期望 getEntityFolderMappings 方法返回包含 Doctrine 实体可找到的文件夹的列表。返回数组的键被忽略。