l0wskilled/api-platform-traits

Package to ease the use of common properties

0.1.8 2020-04-21 10:26 UTC

This package is auto-updated.

Last update: 2024-04-29 03:57:49 UTC


README

Package to ease the use of common properties needed for the api platform package.

You may want to have a look at: https://github.com/epubli/api-platform-test

Content of this package

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

Usage of ORM Timestampable and SoftDeletable

Add the stof doctrine extension:

composer require stof/doctrine-extensions-bundle

Edit the config file config/packages/stof_doctrine_extensions.yaml

It should look like this:

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

Here is an example class which implements these traits:

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;
}