stargazer-team/yii-doctrine
Composer 安装命令:
composer require stargazer-team/yii-doctrine
包简介
Yii3 integration Doctrine extension
关键字:
README 文档
README
Yii3 Doctrine Extension
Installation
The preferred way to install this extension is through composer:
composer require stargazer-team/yii-doctrine
Basic Usage
Configuration params doctrine: dbal, orm, migrations example config path example.php
DBAL
Create database:
php yii doctrine:database:create
Drop database:
php yii doctrine:database:drop --if-exists --force
Dynamic create connection:
<?php declare(strict_types=1); use Yiisoft\Yii\Doctrine\Dbal\Enum\ConfigOptions; use Yiisoft\Yii\Doctrine\Dbal\Factory\DynamicConnectionFactory; use Yiisoft\Yii\Doctrine\DoctrineManager; final class ConnectionService { public function __construct( private readonly DynamicConnectionFactory $dynamicConnectionFactory, private readonly DoctrineManager $doctrineManager, ) { } public function create(): void { $connectionModel = $this->dynamicConnectionFactory->createConnection( [ ConfigOptions::PARAMS => [ 'driver' => 'pdo_pgsql', 'dbname' => 'dbname', 'host' => 'localhost', 'password' => 'secret', 'user' => 'postgres', ] ], 'postgres', ); } public function close(): void { $this->doctrineManager->closeConnection('postgres'); } }
Command:
- doctrine:dbal:run-sql
- doctrine:database:create
- doctrine:database:drop
ORM
If need default entity manager add on di.php
<?php declare(strict_types=1); use Yiisoft\Yii\Doctrine\DoctrineManager use Yiisoft\Yii\Doctrine\Orm\Enum\ConfigOptions; EntityManagerInterface::class => fn( DoctrineManager $doctrineManager ): EntityManagerInterface => $doctrineManager->getManager( $params['yiisoft/yii-doctrine'][ConfigOptions::ORM][ConfigOptions::DEFAULT_ENTITY_MANAGER] ?? DoctrineManager::DEFAULT_ENTITY_MANAGER, ),
Use default entity manager:
<?php declare(strict_types=1); use Doctrine\ORM\EntityManagerInterface; final class TestController { public function __construct( private readonly EntityManagerInterface $entityManager, ) { } }
If two or more entity manager use Yiisoft\Yii\Doctrine\Doctrine\DoctrineManager, find by name entity manager
<?php declare(strict_types=1); use Yiisoft\Yii\Doctrine\DoctrineManager; final class Test2Controller { public function __construct( private readonly DoctrineManager $doctrineManager, ) { } }
Dynamic create entity manager:
<?php declare(strict_types=1); use Yiisoft\Yii\Doctrine\DoctrineManager; use Yiisoft\Yii\Doctrine\Orm\Enum\ConfigOptions; use Yiisoft\Yii\Doctrine\Orm\Factory\DynamicEntityManagerFactory; final class EntityManagerService { public function __construct( private readonly DynamicEntityManagerFactory $dynamicEntityManagerFactory, private readonly DoctrineManager $doctrineManager, ) { } public function create(): void { $this->dynamicEntityManagerFactory->create( [ ConfigOptions::CONNECTION => 'mysql', ConfigOptions::MAPPINGS => [ 'Mysql' => [ ConfigOptions::MAPPING_DIR => '@common/Mysql', ConfigOptions::MAPPING_DRIVER => DriverMappingEnum::ATTRIBUTE_MAPPING, ConfigOptions::MAPPING_NAMESPACE => 'Common\Mysql', ], ], ], [ ConfigOptions::PROXY_NAMESPACE => 'Proxies', ConfigOptions::PROXY_PATH => '@runtime/cache/doctrine/proxy', ConfigOptions::PROXY_AUTO_GENERATE => true ], 'mysql', ); $entityManager = $this->doctrineManager->getManager('mysql'); } public function reset(): void { $this->doctrineManager->resetManager('mysql'); } public function close(): void { $this->doctrineManager->closeManager('mysql'); } }
Command:
- doctrine:orm:info
- doctrine:orm:generate-proxies
- doctrine:orm:mapping-describe
- doctrine:orm:run-dql
- doctrine:orm:validate-schema
- doctrine:orm:schema-tool:create
- doctrine:orm:schema-tool:drop
- doctrine:orm:schema-tool:update
Cache
Extension use psr6 cache implementation symfony cache. Default cache Symfony\Component\Cache\Adapter\NullAdapter.
Options add config on params.php
<?php declare(strict_types=1); use Yiisoft\Yii\Doctrine\Cache\CacheCollector; use Yiisoft\Yii\Doctrine\Cache\Enum\ConfigOptions; return [ 'yiisoft/yii-doctrine' => [ // Used symfony cache ConfigOptions::CACHE => [ ConfigOptions::DRIVER => CacheAdapterEnum::ARRAY_ADAPTER, // only redis or memcached ConfigOptions::SERVER => [ ConfigOptions::HOST => 'localhost', ConfigOptions::PORT => 6379 ], ConfigOptions::NAMESPACE => 'doctrine_', // only file cache driver ConfigOptions::PATH => '@runtime/cache/doctrine', ], ];
Add on di.php configuration psr-6 cache
<?php declare(strict_types=1); use Symfony\Component\Cache\Adapter\ArrayAdapter; use Yiisoft\Yii\Doctrine\Cache\CacheCollector return [ CacheCollector::DOCTRINE_HYDRATION_CACHE => fn(CacheFactory $cacheFactory): CacheItemPoolInterface => $cacheFactory->create( $params['yiisoft/yii-doctrine']['cache'] ?? [] ), // or add di.php customer implementation CacheCollector::DOCTRINE_HYDRATION_CACHE => ArrayAdapter(), CacheCollector::DOCTRINE_METADATA_CACHE => ArrayAdapter(), CacheCollector::DOCTRINE_QUERY_CACHE => ArrayAdapter(), CacheCollector::DOCTRINE_RESULT_CACHE => ArrayAdapter(), ];
Command:
- doctrine:orm:clear-cache:metadata
- doctrine:orm:clear-cache:query
- doctrine:orm:clear-cache:result
Migrations
Create migration:
php yii doctrine:migrations:diff
Multi configuration
php yii doctrine:migrations:diff --configuration=mysql
Migrate
php yii doctrine:migrations:migrate
Command:
- doctrine:migrations:current
- doctrine:migrations:diff
- doctrine:migrations:dump-schema
- doctrine:migrations:execute
- doctrine:migrations:generate
- doctrine:migrations:latest
- doctrine:migrations:list
- doctrine:migrations:migrate
- doctrine:migrations:rollup
- doctrine:migrations:status
- doctrine:migrations:sync-metadata-storage
- doctrine:migrations:up-to-date
- doctrine:migrations:version
Fixture
If need fixture, install package
composer require stargazer-team/yii-doctrine-fixture --dev
stargazer-team/yii-doctrine 适用场景与选型建议
stargazer-team/yii-doctrine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「migrations」 「doctrine」 「yii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stargazer-team/yii-doctrine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stargazer-team/yii-doctrine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stargazer-team/yii-doctrine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
Symfony ClickhouseMigrationsBundle
Very simple SQL-based database migrations tool - a heavily stripped down fork of robmorgan/phinx
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
Laravel table comments loader (part of Diplodocker project)
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
统计信息
- 总下载量: 99
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-05-06