l0wskilled/api-platform-traits

简化常用属性的使用的包

0.1.8 2020-04-21 10:26 UTC

This package is auto-updated.

Last update: 2024-09-29 05:28:57 UTC


README

简化api平台包所需常用属性的使用的包。

你可能想看看: https://github.com/epubli/api-platform-test

本包内容

  • OrmIdentificatorTrait
  • OrmTimestampableTrait
  • OrmSoftDeletableTrait
  • OdmIdentificatorTrait
  • OdmTimestampableTrait
  • OdmSoftDeletableTrait

ORM 时间戳和软删除的使用

添加stof doctrine扩展

composer require stof/doctrine-extensions-bundle

编辑配置文件 config/packages/stof_doctrine_extensions.yaml

它应该看起来像这样

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            softdeleteable: true
            timestampable: true

以下是一个实现这些特性的示例类

use Epubli\ApiPlatform\TraitBundle\OrmSoftDeletableTrait;
use Epubli\ApiPlatform\TraitBundle\OrmTimestampableTrait;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
 */
class Example
{
    use OrmTimestampableTrait;
    use OrmSoftDeletableTrait;
}