fsi/doctrine-extensions-bundle
Composer 安装命令:
composer require fsi/doctrine-extensions-bundle
包简介
FSi Doctrine extensions bundle.
README 文档
README
This bundle provides integration with the FSi DoctrineExtensions library.
Installation
This is the master branch, which is under development. For a stable release, please
use version 1.1.
Add the bundle to composer.json and run composer.phar update.
{
"require": {
"fsi/doctrine-extensions-bundle": "2.0@dev",
}
}
Register bundles in AppKernel.php
// app/AppKernel.php public function registerBundles() { return [ new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), new FSi\Bundle\DoctrineExtensionsBundle\FSiDoctrineExtensionsBundle(), ]; }
Configure listeners
Listeners are not registered by default and you need to enable them in the
app/config/config.yml file before using.
# app/config/config.yml fsi_doctrine_extensions: orm: default: translatable: true uploadable: true
Be sure to enable the translations in app/config/config.yml, even if you do not
wish to use the translatable component of the bundle.
framework: translator: { fallback: %locale% }
Example of an entity with an uploadable field
<?php namespace FSi\DemoBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FSi\Bundle\DoctrineExtensionsBundle\Validator\Constraints as FSiAssert; use FSi\DoctrineExtensions\Uploadable\Mapping\Annotation as FSi; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity() */ class Article { /** * @var integer * * @ORM\Column(type="integer") * @ORM\Id */ private $id; /** * It is important that this column is nullable, because the value is set * after the entity is persisted. * * @ORM\Column(nullable=true) * @FSi\Uploadable(targetField="photo") */ private $photoKey; /** * Currently there is no common interface for uploaded files. * * @var mixed * * @FSiAssert\Image( * maxWidth = 1000, * maxHeight = 460 * ) */ private $photo; public function getId(): int { return $this->id; } public function setPhoto($photo): void { $this->photo = $photo; } public function getPhoto() { return $this->photo; } public function setPhotoKey(?string $photoKey): void { $this->photoKey = $photoKey; } public function getPhotoKey(): ?string { return $this->photoKey; } }
Example of an entity with translatable fields and a translation entity
namespace Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use FSi\DoctrineExtensions\Translatable\Mapping\Annotation as Translatable; /** * The entity's repository needs to implement the * \FSi\DoctrineExtensions\Translatable\Model\TranslatableRepositoryInterface * * @ORM\Entity(repositoryClass="FSi\DoctrineExtensions\Translatable\Entity\Repository\TranslatableRepository") */ class Article { /** * @var integer * * @ORM\Column(type="integer") * @ORM\Id */ private $id; /** * @var string * * @Translatable\Locale */ private $locale; /** * @var string * * @Translatable\Translatable(mappedBy="translations") */ private $title; /** * @var string * * @Translatable\Translatable(mappedBy="translations") */ private $contents; /** * @var Collection|ArticleTranslation[] * * @ORM\OneToMany(targetEntity="ArticleTranslation", mappedBy="article", indexBy="locale") */ private $translations; public function __construct() { $this->translations = new ArrayCollection(); } public function getId(): int { return $this->id; } public function setTitle(?string $title): void { $this->title = $title; } public function getTitle(): ?string { return $this->title; } public function setContents(?string $contents): void { $this->contents = $contents; } public function getContents(): ?string { return $this->contents; } public function setLocale(?string $locale): void { $this->locale = $locale; } public function getLocale(): ?string { return $this->locale; } public function getTranslations(): Collection { return $this->translations; } }
namespace Entity; use Doctrine\ORM\Mapping as ORM; use FSi\DoctrineExtensions\Translatable\Mapping\Annotation as Translatable; /** * @ORM\Entity */ class ArticleTranslation { /** * @var integer * * @ORM\Column(type="integer") * @ORM\Id */ private $id; /** * @var string * * @Translatable\Locale * * @ORM\Column(length=2) */ private $locale; /** * @ORM\Column * @var string */ private $title; /** * @var string * * @ORM\Column */ private $contents; /** * @var Article * * @ORM\ManyToOne(targetEntity="Article", inversedBy="translations") */ private $article; public function setTitle(?string $title): void { $this->title = $title; } public function getTitle(): ?string { return $this->title; } public function setContents(?string $contents): void { $this->contents = $contents; } public function getContents(): ?string { return $this->contents; } public function setLocale(?string $locale): void { $this->locale = $locale; } public function getLocale(): ?string { return $this->locale; } public function setArticle(?Article $article): void { $this->article = $article; } public function getArticle(): ?Article { return $this->article; } }
Additional documentation
Extended validators
There are two validators that can be used with FSi uploadable file.
@FSiAssert\Image - extends Symfony's Image validator
@FSiAssert\File - extends Symfony's File validator
Both of these have exactly the same options as their parent classes.
Detailed documentation of FSi doctrine extensions
fsi/doctrine-extensions-bundle 适用场景与选型建议
fsi/doctrine-extensions-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.21k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2013 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bundle」 「extensions」 「doctrine」 「doctrine-extensions」 「fsi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fsi/doctrine-extensions-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fsi/doctrine-extensions-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fsi/doctrine-extensions-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Register more Twig filters for your OctoberCMS templates
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
统计信息
- 总下载量: 30.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 22
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-10-23