hopeter1018/sequential-counter-format-bundle

This bundle aims to generate value for doctrine entities.

1.0.9 2020-09-09 02:28 UTC

This package is auto-updated.

Last update: 2024-05-09 09:56:58 UTC


README

Introduction

This bundle aims to generate value for doctrine entities.

Installation

Require the package

composer require hopeter1018/sequential-counter-format-bundle

Add to kernel

Symfony 4+ or Symfony Flex

Add /config/bundles.php

return [
  ...,
  HoPeter1018\SequentialCounterFormatBundle\HoPeter1018SequentialCounterFormatBundle::class => ['all' => true],
];

Symfony 2+

Add /app/AppKernel.php

$bundles = [
  ...,
  new HoPeter1018\SequentialCounterFormatBundle\HoPeter1018SequentialCounterFormatBundle(),
];

Config

thru config.yml / config.yaml

ho_peter1018_sequential_counter_format:
  # managers: ['default'] # add / modify if you are not using 'default'
  rules:
    _rule_alias_:
        entity_class: 'Your\Bundle\Entity\EntityClass'
        property: 'yamlTargetPropertyName'
        format: '__SEE_FORMAT_SECTION__'

thru Doctrine Annotation

namespace Your\Bundle\Entity;

use HoPeter1018\SequentialCounterFormatBundle\Annotations as Scf;

/**
 * Class docblock
 *
 * @Scf\ClassRule(settings={
 *   "classAnnotationTargetPropertyName"={"format"="__SEE_FORMAT_SECTION__", "batchPrefix"="[site.id]"},
 * })
 */
class EntityClass {

  /**
   * @Scf\PropertyRule("__SEE_FORMAT_SECTION__")
   * @ORM\Column(type="string", length=255)
   */
  private $propertyAnnotationTargetPropertyName;

  /**
   * @ORM\Column(type="string", length=255)
   */
  private $classAnnotationTargetPropertyName;

  /**
   * declared in the above section: `thru config.yml / config.yaml`
   */
  private $yamlTargetPropertyName;

}

Usage

Format Placeholder

Type Format Description
Sequence %d same as sprintf
Only %d is supported right now.
Date {format_character} same as date
EACH Date format should wrap separately.
Currently supports: YyMmWdwNHi
if you want 19970101, you should do {Y}{m}{d}
Property [property_name] Powered by Symfony's PropertyAccess Component