ecommit/doctrine-orm-refetch
Composer 安装命令:
composer require ecommit/doctrine-orm-refetch
包简介
Refetch ORM Doctrine objects. Or detach all entities attached since a snapshot
README 文档
README
This library allows to
- re-fetch Doctrine ORM objects after clear the object manager
- detach all entities attached since a snapshot
Installation
To install doctrine-orm-refetch with Composer just run :
$ composer require ecommit/doctrine-orm-refetch
Usage
Create the utility ($entityManager is the Doctrine ORM entity manager):
use Ecommit\DoctrineOrmRefetch\RefetchManager; $refetchManager = RefetchManager::create($entityManager);
Refetch an object
$myObject = $refetchManager->getFetchedObject($myObject); //or $refetchManager->refreshObject($myObject);
Example:
use Ecommit\DoctrineOrmRefetch\RefetchManager; $refetchManager = RefetchManager::create($entityManager); $author = $entityManager->getRepository(Author::class)->find(1); $queryBuilder = $entityManager->getRepository(Book::class)->createQueryBuilder('b'); $queryBuilder->select('b') ->andWhere('b.bookId != :bookId') ->setParameter('bookId', 7); $iterableResult = $queryBuilder->getQuery()->iterate(); $i = 0; foreach ($iterableResult as $row) { ++$i; $book = current($row); if (!$book->getAuthors()->contains($author)) { $book->addAuthor($author); } if (0 === $i % 20) { //$author is managed $entityManager->flush(); $entityManager->clear(); //$author is not managed $author = $refetchManager->getObject($author); //$author is managed } } $entityManager->flush(); $entityManager->clear();
Get collection by critera
$collection = $refetchManager->getCollectionFromCriteria($criteria, 'MyClass');
Example:
use Doctrine\Common\Collections\Criteria; use Ecommit\DoctrineOrmRefetch\RefetchManager; $refetchManager = RefetchManager::create($entityManager); $ctiteria = Criteria::create() ->andWhere(Criteria::expr()->gt('authorId', 2)); $authors = $refetchManager->getCollectionFromCriteria($ctiteria, Author::class); $queryBuilder = $entityManager->getRepository(Book::class)->createQueryBuilder('b'); $queryBuilder->select('b') ->andWhere('b.bookId != :bookId') ->setParameter('bookId', 9); $iterableResult = $queryBuilder->getQuery()->iterate(); $i = 0; foreach ($iterableResult as $row) { ++$i; $book = current($row); foreach ($authors as $author) { if (!$book->getAuthors()->contains($author)) { $book->addAuthor($author); } } if (0 === $i % 20) { $entityManager->flush(); $entityManager->clear(); $authors = $refetchManager->getCollectionFromCriteria($ctiteria, Author::class); } } $entityManager->flush(); $entityManager->clear();
Snapshot
Detach all entities attached since a snapshot (entities attached before the snapshot are kept)
use Ecommit\DoctrineOrmRefetch\SnapshotManager; $snapshotManager = SnapshotManager::create($entityManager); $author = $entityManager->getRepository(Author::class)->find(1); $snapshotManager->snapshot(); $queryBuilder = $entityManager->getRepository(Book::class)->createQueryBuilder('b'); $queryBuilder->select('b') ->andWhere('b.bookId != :bookId') ->setParameter('bookId', 7); $iterableResult = $queryBuilder->getQuery()->iterate(); $i = 0; foreach ($iterableResult as $row) { ++$i; /** @var Book $book */ $book = current($row); if (!$book->getAuthors()->contains($author)) { $book->addAuthor($author); } if (0 === $i % 2) { // $author and $book are managed $entityManager->flush(); $snapshotManager->clear(); // Detach all entities attached since the snapshot // Only $author is managed } } $entityManager->flush(); $snapshotManager->clear();
License
This librairy is under the MIT license. See the complete license in LICENSE file.
ecommit/doctrine-orm-refetch 适用场景与选型建议
ecommit/doctrine-orm-refetch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.52k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「snapshot」 「doctrine」 「refetch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ecommit/doctrine-orm-refetch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ecommit/doctrine-orm-refetch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ecommit/doctrine-orm-refetch 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PDF or Image generation from a Url or HTML page
Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter.
Guzzle Snapshots Middleware
A PHP package that takes a snapshot of your application and allows you to retrieve it later to help with debugging.
Snapshot your database with mysqldump and store it to a an asset volume (S3). Also restore it from that same location. Great for local dev snapshots and nightly backups.
Make pimcore migration simple
统计信息
- 总下载量: 3.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-11