承接 adrenalinkin/enum-property-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adrenalinkin/enum-property-bundle

Composer 安装命令:

composer require adrenalinkin/enum-property-bundle

包简介

Provides integration EnumMapper component with Symfony

README 文档

README

Introduction

Bundle integrate EnumMapper component with Symfony ecosystem. Provides filters and functions for Twig and validator.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

    composer require adrenalinkin/enum-property-bundle

This command requires you to have Composer install globally.

Step 2: Enable the Bundle

After enable the bundle by adding into list of the registered bundles into app/AppKernel.php of your project:

<?php
// app/AppKernel.php

class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = [
            // ...

            new Linkin\Bundle\EnumPropertyBundle\LinkinEnumPropertyBundle(),
        ];

        return $bundles;
    }

    // ...
}

Usage

Documentation for the EnumMapper component. As example we will use this class:

<?php

use Linkin\Component\EnumMapper\Mapper\AbstractEnumMapper;

class GenderMapper extends AbstractEnumMapper
{
    const DB_UNDEFINED = 0;
    const DB_MALE      = 10;
    const DB_FEMALE    = 20;

    const HUMAN_UNDEFINED = 'Undefined';
    const HUMAN_MALE      = 'Male';
    const HUMAN_FEMALE    = 'Female';
}

Twig Extension

Twig extension allow to use EnumMapper component functionality from the templates.

enum_to_human

Get humanized value by received database value:

    {% set status = 20 %}
    {% set class = '\\Acme\\Bundle\\AcmeBundle\\Entity\\Mapper\\GenderMapper' %}
    {{ status|enum_to_human(class) }} {# Female #}

enum_to_db

Get database value by received humanized value:

    {% set status = 'Male' %}
    {% set class = '\\Acme\\Bundle\\AcmeBundle\\Entity\\Mapper\\GenderMapper' %}
    {{ status|enum_to_db(class) }} {# 10 #}

enum_map

Get full list of the available pairs of the database and humanized values:

    {% for key, value in enum_map('\\Acme\\Bundle\\AcmeBundle\\Entity\\Mapper\\GenderMapper') %}
        {{ key }}: {{ value|trans }} <br>
    {% endfor %}
    {# 
        0: Undefined
        10: Male
        20: Female 
    #}

enum_allowed_db and enum_allowed_human

Get list of the all available value for the database values or for the humanized values:

    {% set class = '\\Acme\\Bundle\\AcmeBundle\\Entity\\Mapper\\GenderMapper' %}

    {{ enum_allowed_db(class)|join(', ') }} {# 0, 10, 20 #}
    {{ enum_allowed_human(class)|join(', ') }} {# Undefined, Male, Female #}

    {# Exclude values from result #}
    {{ enum_allowed_db(class, [0])|join(', ') }} {# 10, 20 #}
    {{ enum_allowed_human(class, ['Undefined'])|join(', ') }} {# Male, Female #}

enum_random_db and enum_random_human

Get random database or humanized value:

    {% set class = '\\Acme\\Bundle\\AcmeBundle\\Entity\\Mapper\\GenderMapper' %}

    {{ enum_random_db(class) }} {# 0 || 10 || 20 #}
    {{ enum_random_human(class) }} {# Undefined || Male || Female #}

    {# Exclude values from result #}
    {{ enum_random_db(class, [0]) }} {# 10 || 20 #}
    {{ enum_random_human(class, ['Undefined']) }} {# Male || Female #}

Enum Validator

For validate entity fields, which use EnumMapper component, bundle contain EnumValidator. Validator extends ChoiceValidator from the standard Symfony package. Changed standard error message and choice array. Array choice can not be changed and will be contain allowed database values of the received class-mapper. Also has been added several additional options. Required option:

  • mapperName - contains full name of the class-mapper.

Optional variable:

  • exclude - List of the database values which should be excluded from the allowed values.

Validator usage example

Acme\Bundle\AcmeBundle\Entity\User:
    properties:
        gender:
            - Linkin\Bundle\EnumPropertyBundle\Validator\Constraints\Enum:
                mapperName: 'Acme\Bundle\AcmeBundle\Entity\Mapper\GenderMapper'
                exclude:    [0]

License

license

adrenalinkin/enum-property-bundle 适用场景与选型建议

adrenalinkin/enum-property-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「enum」 「symfony-bundle」 「human-readable」 「enum-mapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adrenalinkin/enum-property-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adrenalinkin/enum-property-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 adrenalinkin/enum-property-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-16