ovk13/doctrine2-exporter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ovk13/doctrine2-exporter

Composer 安装命令:

composer require ovk13/doctrine2-exporter

包简介

MySQL Workbench Schema Exporter for Doctrine 2

README 文档

README

This is an exporter to convert MySQL Workbench Models (*.mwb) to a Doctrine 2 Schema.

Prerequisites

  • PHP 5.4+
  • Composer to install the dependencies

Installation

php composer.phar require --dev mysql-workbench-schema-exporter/doctrine2-exporter

This will install the exporter and also require mysql-workbench-schema-exporter.

You then can invoke the CLI script using vendor/bin/mysql-workbench-schema-export.

Formatter Setup Options

Additionally to the common options of mysql-workbench-schema-exporter these options are supported:

Common Setup Options for Doctrine 2.0:

  • useAutomaticRepository

    Automatically generate entity repository class name.

  • bundleNamespace

    The global namespace prefix for entity class name.

  • entityNamespace

    The entity namespace.

    Default is Entity.

  • repositoryNamespace

    The namespace prefix for entity repository class name. For this configuration to apply, useAutomaticRepository must be set to true.

  • skipColumnWithRelation

    Don't generate columns definition (for YAML) or columns variable and columns getter and setter (for Annotation) which has relation to other table.

    Default is false.

  • relatedVarNameFormat

    The format for generated related column name.

    Default is %name%%related%.

  • nullableAttribute

    How nullable attribute of columns and joins is generated. Set to auto if you want to automatically include nullable attribute based on its value. Set to always to always include nullable attribute.

    Default is auto.

  • generatedValueStrategy

    The stragety for auto-generated values.

    Default is auto.

  • defaultCascade

    The default cascade option to define.

    Default is false.

Doctrine 2.0 YAML Schema

Setup Options

  • extendTableNameWithSchemaName

    Include schema name beside the table name.

    Default is false.

Doctrine 2.0 Annotation

Setup Options

  • useAnnotationPrefix

    Doctrine annotation prefix.

    Default is ORM\.

  • skipGetterAndSetter

    Don't generate columns getter and setter.

    Default is false.

  • generateEntitySerialization

    Generate method __sleep() to include only real columns when entity is serialized.

    Default is true.

  • generateExtendableEntity

    Generate two class for each tables in schema, one for base and one other for extend class. The extend class would not be generated if it already exist. So it is safe to place custom code inside the extend class.

    This option will generate entity using Single Table Inheritance.

    Default is false.

  • extendableEntityHasDiscriminator

    If enabled, DiscriminatorColumn and DiscriminatorMap annotations will be used.

    Default is true.

  • quoteIdentifierStrategy

    This option determine wheter identifier quoting is applied or not, depend on the strategy value.

    • auto, indentifier quoting enabled if identifier is a reserved word.
    • always, always quote identifier.
    • none, never quote identifier.

    Default is auto.

  • extendsClass

    This option allows you to define a base class from which all generated entities extend.

    Default is ''.

  • propertyTypehint

    This option allows you to specify whether type-hinting should be enabled for all non-scalar properties whose type is a class. E.g. \DateTime would be type-hinted but not object or string.

    Default is false.

  • useBehavioralExtensions

    use Doctrine2 behavioral extensions like create table with name '_img' then can be auto create plugin support.

    Default is false.

  • removeTablePrefix

    This prefix will be removed from model names.

    Default is false.

Model Comment Behavior

  • {d:bundleNamespace}AcmeBundle{/d:bundleNamespace} (applied to Table)

    Override bundleNamespace option.

  • {d:m2m}false{/d:m2m} (applied to Table)

    MySQL Workbench Schema Exporter tries to automatically guess which tables are many-to-many mapping tables and will not generate entity classes for these tables.

    A table is considered a mapping table, if it contains exactly two foreign keys to different tables and those tables are not many-to-many mapping tables.

    Sometimes this guessing is incorrect for you. But you can add a hint in the comment of the table, to show that it is no mapping table. Just use {d:m2m}false{/d:m2m} anywhere in the comment of the table.

  • {d:unidirectional}true{/d:unidirectional} (applied to ForeignKey)

    All foreign keys will result in a bidirectional relation by default. If you only want a unidirectional relation, add a flag to the comment of the foreign key.

  • {d:owningSide}true{/d:owningSide} (applied to ForeignKey)

    In a bi-directional many-to-many mapping table the owning side of the relation is randomly selected. If you add this hint to one foreign key of the m2m-table, you can define the owning side for Doctrine.

  • {d:cascade}persist, merge, remove, detach, all{/d:cascade} (applied to ForeignKey)

    You can specify Doctrine cascade options as a comment on a foreign key. They will be generated into the Annotation. (Reference)

  • {d:fetch}EAGER{/d:fetch} (applied to ForeignKey)

    You can specify the fetch type for relations in the comment of a foreign key. (EAGER or LAZY, doctrine default is LAZY)

  • {d:orphanRemoval}true{/d:orphanRemoval} (applied to ForeignKey)

    Another option you can set in the comments of foreign key. (Reference)

  • {d:order}column{/d:order} (applied to ForeignKey)

    Apply OrderBy annotation to One To Many and Many To Many relation. OrderBy annotation can be written in the following format:

    column[,(asc|desc)]
    

    Multiple columns are supported, separated by line break. Example usage:

    {d:order}
      column1
      column1,desc
    {/d:order}
    
  • {d:cache}READ_ONLY, NONSTRICT_READ_WRITE, READ_WRITE{/d:cache} (applied to Table and/or ForeignKey)

    You can specify Doctrine second level caching strategy as a comment on a table or foreign key. They will be generated into the Annotation or YAML. (Reference)

  • {d:relatedNames}RelationTable:NewName{/d:relatedNames} (applied to Table)

    Overrides relatedVarNameFormat.

    Rename generated related column names when the table names and the relatedVarNameFormat pattern are not good enough. The format should be CamelCase singular and should map with the class name that is generated for the related entity. Can be written in the following format:

    RelationTableName:CustomRelationName
    

    Multiple relations are supported, separated by line break. Example usage: - on a "store_products" table with "store_product_categories" and "store_product_images" related tables:

    {d:relatedNames}
    StoreProductCategory:Category
    StoreProductImage:Image
    {/d:relatedNames}
    

    It can be used in both parent / child tables. For example, on a "store_product_images" table:

    {d:relatedNames}
    StoreProduct:Product
    {/d:relatedNames}
    

    The generated StoreProduct class will have "category" and "image" properties instead of "storeProductCategory" and "storeProductImage", while the "StoreProductImage" class will have a "product" property instead of "storeProduct".

Doctrine 2.0 Annotation with ZF2 Input Filter Classes

Doctrine 2.0 Annotation with ZF2 Input Filter Classes formatter directly extend Doctrine 2.0 Annotation. The setup options and model comment behavior exactly the same as Doctrine 2.0 Annotation with the following addons.

Add Some Zend\Validator\StringLength,Zend\Filter\StringTrim,Zend\Filter\StripTags as string type column Add Some Filters like column name with 'phone' or '_tel' auto create filter with Zend\I18n\Validator\PhoneNumber and column name with 'email' auto create filter with Zend\Validator\EmailAddress

Setup Options

  • generateEntityPopulate

    Generate populate() method for entity class.

    Default is true.

  • generateEntityGetArrayCopy

    Generate getArrayCopy() method for entity class.

    Default is true.

Command Line Interface (CLI)

See documentation for mysql-workbench-schema-exporter

Links

ovk13/doctrine2-exporter 适用场景与选型建议

ovk13/doctrine2-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.31k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ovk13/doctrine2-exporter 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-06