kyoushu / common-bundle
此包已被 弃用 且不再维护。未建议替代包。
1.0.0
2016-03-16 16:55 UTC
Requires
- php: >=5.5.0
- doctrine/doctrine-bundle: ~1.5
- doctrine/orm: ~2.5
- stof/doctrine-extensions-bundle: ^1.2
- symfony/form: >=2.3
- symfony/framework-bundle: >=2.3
- symfony/twig-bundle: >=2.3
- symfony/validator: >=2.3
Requires (Dev)
- phpunit/phpunit: ~4.5
- symfony/browser-kit: ~2.3
- symfony/css-selector: >=2.3
- symfony/dom-crawler: ~2.6
This package is auto-updated.
Last update: 2022-02-01 12:53:11 UTC
README
此文件已自动生成。需要编辑以反映此包提供的功能描述。
安装
安装 stof/doctrine-extensions-bundle
将以下行添加到 composer.json
"require": { "kyoushu/common-bundle": "dev-master" }
将以下行添加到 app/AppKernel.php
$bundles = array( // ... new Kyoushu\CommonBundle\KyoushuCommonBundle(), // ... );
待办事项
- 动态路由的文档
- 视频及视频元数据的文档
上传处理器
此包提供上传处理器,在更新/持久化时将上传文件复制到目标目录。
您只需要在实体中实现 Kyoushu\CommonBundle\Upload\UploadInterface。
namespace AppBundle\Entity; use Kyoushu\CommonBundle\Upload\UploadInterface; use Symfony\Component\HttpFoundation\File\File; class MyUploadEntity implements UploadInterface { /** * @var File|null */ protected $file; /** * @var string|null */ protected $relPath; /** * @return File|null */ public function getFile() { return $this->file; } /** * @param File|null $file * @return $this */ public function setFile(File $file = null) { $this->file = $file; return $this; } /** * @return string|null */ public function getRelPath() { return $this->relPath; } /** * @param string|null $relPath * @return $this */ public function setRelPath($relPath) { $this->relPath = $relPath; return $this; } /** * @return string */ public function getRelDir() { return 'sub/dir/where/upload/should/go'; } }
实体特质
此包提供一系列特质以加速实体创建。
namespace AppBundle\Entity; use Kyoushu\CommonBundle\Entity\Traits as EntityTraits; class MyEntity { // Provides the property $id (auto-incrementing primary key) and related getter use EntityTraits\IdTrait; // Provides the properties $title and $slug and related getters/setters // - $slug is generated from the value of $title on persist/update use EntityTraits\TitleSlugTrait; // Provides the $summary property and related getters/setters // - Intended to be used with textarea form fields use EntityTraits\SummaryTrait; // Provides $created and $updated timestamp properties and related getters/setters // - $created is set to \DateTime('now') on persist // - $updated is set to \DateTime('now') on persist/update use EntityTraits\TimestampTrait; }
实体查找器
您可以通过扩展 \Kyoushu\CommonBundle\EntityFinder\AbstractEntityFinder 类来创建实体查找器。
namespace AppBundle\EntityFinder; use Kyoushu\CommonBundle\EntityFinder\AbstractEntityFinder; class MyEntityFinder extends AbstractEntityFinder { public function getEntityClass() { return 'AppBundle\Entity\MyEntity'; } }
可以通过覆盖 configureQueryBuilder() 和 getRouteParameterKeys() 方法使用自定义参数。
namespace AppBundle\EntityFinder; use Kyoushu\CommonBundle\EntityFinder\AbstractEntityFinder; class MyEntityFinder extends AbstractEntityFinder { protected $title; public function getEntityClass() { return 'AppBundle\Entity\MyEntity'; } public function getTitle() { return $this->title; } public function setTitle($title) { $this->title = $title; return $this; } public function getRouteParameterKeys() { return array('page', 'perPage', 'title'); } public function configureQueryBuilder(QueryBuilder $queryBuilder) { $title = $this->getTitle(); if($title !== null){ $queryBuilder->andWhere('entity.title like :like_title'); $queryBuilder->setParameter('like_title', '%' . $title . '%'); } } }