zenbox/doctrine
Composer 安装命令:
composer require zenbox/doctrine
包简介
Doctrine extensions
关键字:
README 文档
README
Installation
Using Composer:
composer require zenbox/doctrine
What is contained in the package?
Doctrine components
QueryBuilderCollection
Lazy load query builder collection
$qb = $this->createQueryBuilder('a'); $qb->orderBy('a.date','DESC'); $collection = new QueryBuilderCollection($qb); $collection->count(); // returns the total number of records $collection->slice(0, 10); // request limited 10 records from the database
DataProvider
Can be used for pagination. 20 records per page by default
use Doctrine\Common\Collections\ArrayCollection; $dataProvider = new DataProvider(new ArrayCollection([...])); // iterable foreach ($dataProvider as $object) { // do something } $array = $dataProvider->toArray(); // returns 20 records
Extract data from objects
use ZenBox\Doctrine\Extractor\ExtractorInterface; // implement extractor class UserExtractor implements ExtractorInterface { public function extract(object $object) : array { // TODO: Implement extract() method. } } // fetch collection from repository $collection = $repository->findAll(); $dataProvider = new DataProvider($collection, new UserExtractor()); // iterable foreach ($dataProvider as $row) { // do something } $array = $dataProvider->extract(); // returns 20 rows
Console commands
You need to create a file ./bin/doctrine in your project for use console commands
#!/usr/bin/env php <?php require __DIR__ . ' /../vendor/autoload.php'; use Doctrine\ORM\EntityManagerInterface; use Psr\Container\ContainerInterface; use ZenBox\Doctrine\Console\DoctrineConsoleRunner; /** @var ContainerInterface $container */ $container = require __DIR__ . '/../config/container.php'; $entityManager = $container->get(EntityManagerInterface::class); $config = [ 'migrations' => [ 'table_storage' => [ 'table_name' => 'doctrine_migration_versions', 'version_column_name' => 'version', 'version_column_length' => 1024, 'executed_at_column_name' => 'executed_at', 'execution_time_column_name' => 'execution_time', ], 'migrations_paths' => [ 'MyProject\Migrations' => __DIR__ . '/../data/migrations/MyProject/Migrations', 'MyProject\Component\Migrations' => __DIR__ . '/../data/migrations/Component/MyProject/Migrations', ], 'all_or_nothing' => true, 'check_database_platform' => true, ], 'fixtures_path' => __DIR__ . '/../data/fixtures', ]; DoctrineConsoleRunner::run($entityManager, $config);
Container configuration
<?php declare(strict_types=1); use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Tools\Setup; use ZenBox\Doctrine\DefinitionFactory; use ZenBox\Doctrine\Iterator\DirectoryPathIterator; use App\Identity\Domain\Model\User; use App\Identity\Domain\Repository\UserRepositoryInterface; return [ 'dependencies' => [ 'factories' => [ EntityManagerInterface::class => function() { return EntityManager::create( [ 'dbname' => getenv('MYSQL_DATABASE'), 'user' => getenv('MYSQL_USER'), 'password' => getenv('MYSQL_PASSWORD'), 'host' => getenv('MYSQL_HOST'), 'driver' => 'pdo_mysql', ], Setup::createYAMLMetadataConfiguration( // iterate through all folders to find metadata configuration (new DirectoryPathIterator(realpath(__DIR__) . '/../config/doctrine'))->toArray(), getenv('APP_DEV_MODE') ) ); }, // you can use definition factory UserRepositoryInterface::class => DefinitionFactory::create(User::class), // instead UserRepositoryInterface::class => function (ContainerInterface $container) { return $container->get(EntityManagerInterface::class)->getRepository(User::class); } ], ], ];
zenbox/doctrine 适用场景与选型建议
zenbox/doctrine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.97k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extensions」 「doctrine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zenbox/doctrine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zenbox/doctrine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zenbox/doctrine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
Register more Twig filters for your OctoberCMS templates
Make pimcore migration simple
Bundle for Doctrine enumerations extension for Postgres
Doctrine extension to manage enumerations in PostgreSQL
PhpPlaisio: Phing Extensions
统计信息
- 总下载量: 1.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-26