├── .github └── workflows │ └── continuous-integration.yml ├── LICENSE ├── README.md ├── composer.json ├── docs ├── doctrine2-annotation.md ├── doctrine2-yaml.md └── doctrine2-zf2inputfilterannotation.md ├── export1.json ├── export2.json ├── export3.json └── lib ├── Annotation ├── Configuration │ ├── AnnotationPrefix.php │ ├── BehavioralExtension.php │ ├── ClassExtend.php │ ├── EntityExtend.php │ ├── EntityExtendDiscriminator.php │ ├── EntitySerialize.php │ ├── GetterSetterSkip.php │ ├── IdentifierQuotingStrategy.php │ ├── Typehint.php │ ├── TypehintArgument.php │ ├── TypehintReturnValue.php │ └── TypehintSkip.php ├── DatatypeConverter.php ├── Formatter.php └── Model │ ├── Column.php │ └── Table.php ├── Configuration ├── AutomaticRepository.php ├── BundleNamespace.php ├── Cascade.php ├── ColumnWithRelationSkip.php ├── EntityNamespace.php ├── GeneratedValueStrategy.php ├── NullableAttribute.php ├── RelatedVarName.php ├── RepositoryNamespace.php └── TableNamePrefix.php ├── DatatypeConverter.php ├── Formatter.php ├── Model ├── Column.php └── Table.php ├── Yaml ├── Configuration │ └── TableNameExtend.php ├── DatatypeConverter.php ├── Formatter.php └── Model │ ├── Column.php │ └── Table.php └── ZF2InputFilterAnnotation ├── Configuration ├── EntityArrayCopy.php └── EntityPopulate.php ├── DatatypeConverter.php ├── Formatter.php └── Model └── Table.php /.github/workflows/continuous-integration.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | test: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | php-version: 20 | - "7.2" 21 | - "7.3" 22 | - "7.4" 23 | - "8.0" 24 | - "8.1" 25 | - "8.2" 26 | - "8.3" 27 | - "8.4" 28 | 29 | steps: 30 | - uses: actions/checkout@v4 31 | 32 | - name: Install PHP 33 | uses: shivammathur/setup-php@v2 34 | with: 35 | php-version: ${{ matrix.php-version }} 36 | ini-values: error_reporting=E_ALL 37 | 38 | - name: Validate composer.json and composer.lock 39 | run: composer validate --strict 40 | 41 | - name: Cache Composer packages 42 | id: composer-cache 43 | uses: actions/cache@v4 44 | with: 45 | path: vendor 46 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 47 | restore-keys: | 48 | ${{ runner.os }}-php- 49 | 50 | - name: Install dependencies 51 | run: composer install --prefer-dist --no-progress 52 | 53 | - name: Build model 54 | run: | 55 | vendor/bin/mysql-workbench-schema-export --config=export1.json vendor/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter/example/data/sakila.mwb 56 | vendor/bin/mysql-workbench-schema-export --config=export2.json vendor/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter/example/data/sakila.mwb 57 | vendor/bin/mysql-workbench-schema-export --config=export3.json vendor/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter/example/data/sakila.mwb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010 Johannes Mueller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Build Status](https://github.com/mysql-workbench-schema-exporter/doctrine2-exporter/actions/workflows/continuous-integration.yml/badge.svg) 2 | [![Latest Stable Version](https://poser.pugx.org/mysql-workbench-schema-exporter/doctrine2-exporter/v/stable.svg)](https://packagist.org/packages/mysql-workbench-schema-exporter/doctrine2-exporter) 3 | [![Total Downloads](https://poser.pugx.org/mysql-workbench-schema-exporter/doctrine2-exporter/downloads.svg)](https://packagist.org/packages/mysql-workbench-schema-exporter/doctrine2-exporter) 4 | [![License](https://poser.pugx.org/mysql-workbench-schema-exporter/doctrine2-exporter/license.svg)](https://packagist.org/packages/mysql-workbench-schema-exporter/doctrine2-exporter) 5 | 6 | # README 7 | 8 | This is an exporter to convert [MySQL Workbench](http://www.mysql.com/products/workbench/) Models (\*.mwb) to a Doctrine 2 Schema. 9 | 10 | ## Prerequisites 11 | 12 | * PHP 7.2+ 13 | * Composer to install the dependencies 14 | 15 | ## Installation 16 | 17 | ``` 18 | composer require --dev mysql-workbench-schema-exporter/doctrine2-exporter 19 | ``` 20 | 21 | This will install the exporter and also require [mysql-workbench-schema-exporter](https://github.com/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter). 22 | 23 | You then can invoke the CLI script using `vendor/bin/mysql-workbench-schema-export`. 24 | 25 | ## Configuration 26 | 27 | * [Doctrine 2.0 YAML Schema](/docs/doctrine2-yaml.md) 28 | * [Doctrine 2.0 Annotation](/docs/doctrine2-annotation.md) 29 | * [Doctrine 2.0 Annotation with ZF2 Input Filter Classes](/docs/doctrine2-zf2inputfilterannotation.md) 30 | 31 | ## Model Comment Behavior 32 | 33 | * `{d:bundleNamespace}AcmeBundle{/d:bundleNamespace}` (applied to Table) 34 | 35 | Override `bundleNamespace` option. 36 | 37 | * `{d:m2m}false{/d:m2m}` (applied to Table) 38 | 39 | MySQL Workbench Schema Exporter tries to automatically guess which tables are many-to-many 40 | mapping tables and will not generate entity classes for these tables. 41 | 42 | A table is considered a mapping table, if it contains exactly two foreign keys to different 43 | tables and those tables are not many-to-many mapping tables. 44 | 45 | Sometimes this guessing is incorrect for you. But you can add a hint in the comment of the 46 | table, to show that it is no mapping table. Just use `{d:m2m}false{/d:m2m}` anywhere in the 47 | comment of the table. 48 | 49 | * `{d:unidirectional}true{/d:unidirectional}` (applied to ForeignKey) 50 | 51 | All foreign keys will result in a bidirectional relation by default. If you only want a 52 | unidirectional relation, add a flag to the comment of the foreign key. 53 | 54 | * `{d:owningSide}true{/d:owningSide}` (applied to ForeignKey) 55 | 56 | In a bi-directional many-to-many mapping table the owning side of the relation is randomly 57 | selected. If you add this hint to one foreign key of the m2m-table, you can define the owning 58 | side for Doctrine. 59 | 60 | * `{d:cascade}persist, merge, remove, detach, all{/d:cascade}` (applied to ForeignKey) 61 | 62 | You can specify Doctrine cascade options as a comment on a foreign key. They will be generated 63 | into the Annotation. 64 | ([Reference](http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations)) 65 | 66 | * `{d:fetch}EAGER{/d:fetch}` (applied to ForeignKey) 67 | 68 | You can specify the fetch type for relations in the comment of a foreign key. (EAGER or LAZY, 69 | doctrine default is LAZY) 70 | 71 | * `{d:orphanRemoval}true{/d:orphanRemoval}` (applied to ForeignKey) 72 | 73 | Another option you can set in the comments of foreign key. 74 | ([Reference](http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html#orphan-removal)) 75 | 76 | * `{d:order}column{/d:order}` (applied to ForeignKey) 77 | 78 | Apply OrderBy annotation to One To Many and Many To Many relation. OrderBy annotation can be 79 | written in the following format: 80 | 81 | column[,(asc|desc)] 82 | 83 | Multiple columns are supported, separated by line break. Example usage: 84 | 85 | {d:order} 86 | column1 87 | column1,desc 88 | {/d:order} 89 | 90 | * `{d:cache}READ_ONLY, NONSTRICT_READ_WRITE, READ_WRITE{/d:cache}` (applied to Table and/or ForeignKey) 91 | 92 | 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. 93 | ([Reference](http://doctrine-orm.readthedocs.io/en/latest/reference/second-level-cache.html)) 94 | 95 | 96 | * `{d:relatedNames}RelationTable:NewName{/d:relatedNames}` (applied to Table) 97 | 98 | Overrides `relatedVarNameFormat`. 99 | 100 | 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. 101 | Can be written in the following format: 102 | 103 | RelationTableName:CustomRelationName 104 | 105 | Multiple relations are supported, separated by line break. Example usage: 106 | - on a "store_products" table with "store_product_categories" and "store_product_images" related tables: 107 | 108 | {d:relatedNames} 109 | StoreProductCategory:Category 110 | StoreProductImage:Image 111 | {/d:relatedNames} 112 | 113 | It can be used in both parent / child tables. For example, on a "store_product_images" table: 114 | 115 | {d:relatedNames} 116 | StoreProduct:Product 117 | {/d:relatedNames} 118 | 119 | 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". 120 | 121 | ## Command Line Interface (CLI) 122 | 123 | See documentation for [mysql-workbench-schema-exporter](https://github.com/mysql-workbench-schema-exporter/mysql-workbench-schema-exporter#command-line-interface-cli) 124 | 125 | ## Links 126 | 127 | * [MySQL Workbench](http://wb.mysql.com/) 128 | * [Doctrine Project](http://www.doctrine-project.org/) 129 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "mysql-workbench-schema-exporter/doctrine2-exporter", 3 | "type" : "library", 4 | "description" : "MySQL Workbench Schema Exporter for Doctrine 2", 5 | "keywords" : [ 6 | "mysql", 7 | "mysql workbench", 8 | "database", 9 | "cli", 10 | "doctrine" 11 | ], 12 | "homepage" : "https://github.com/mysql-workbench-schema-exporter/doctrine2-exporter", 13 | "license" : "MIT", 14 | "authors" : [{ 15 | "name" : "Johannes Mueller", 16 | "email" : "circus2@web.de", 17 | "role" : "Developer" 18 | }, { 19 | "name" : "Toha", 20 | "email" : "tohenk@yahoo.com", 21 | "role" : "Developer" 22 | }, { 23 | "name" : "Robert Vock", 24 | "email" : "robertvock82@gmail.com", 25 | "role" : "Developer" 26 | } 27 | ], 28 | "require" : { 29 | "php" : ">=7.2", 30 | "mysql-workbench-schema-exporter/mysql-workbench-schema-exporter": "dev-master", 31 | "ntlab/php-obj": "^1.0" 32 | }, 33 | "autoload" : { 34 | "psr-4" : { 35 | "MwbExporter\\Formatter\\Doctrine2\\" : "lib/" 36 | } 37 | }, 38 | "extra": { 39 | "mysql-workbench-schema-exporter" : { 40 | "formatters" : { 41 | "doctrine2-annotation" : "MwbExporter\\Formatter\\Doctrine2\\Annotation\\Formatter", 42 | "doctrine2-yaml" : "MwbExporter\\Formatter\\Doctrine2\\Yaml\\Formatter", 43 | "doctrine2-zf2inputfilterannotation" : "MwbExporter\\Formatter\\Doctrine2\\ZF2InputFilterAnnotation\\Formatter" 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /docs/doctrine2-annotation.md: -------------------------------------------------------------------------------- 1 | # Doctrine 2.0 Annotation Classes Configuration 2 | 3 | Auto generated at 2023-04-28T09:14:39+0700. 4 | 5 | ## Global Configuration 6 | 7 | * `language` 8 | 9 | Language detemines which language used to transform singular and plural words 10 | used in certains other schema like Doctrine. 11 | 12 | Valid values: `none`, `english`, `french`, `norwegian-bokmal`, `portuguese`, `spanish`, 13 | `turkish` 14 | 15 | Default value: `none` 16 | 17 | * `useTab` (alias: `useTabs`) 18 | 19 | Use tab as blank instead of space in generated files. 20 | 21 | Default value: `false` 22 | 23 | * `indentation` 24 | 25 | Number of spaces used as blank in generated files. 26 | 27 | Default value: `4` 28 | 29 | * `eolDelimiter` (alias: `eolDelimeter`) 30 | 31 | End of line (EOL) delimiter detemines the end of line in generated files. 32 | 33 | Valid values: `win`, `unix` 34 | 35 | Default value: `win` 36 | 37 | * `filename` 38 | 39 | The output filename format, use the following tag `%schema%`, `%table%`, `%entity%`, and 40 | `%extension%` to allow the filename to be replaced with contextual data. 41 | 42 | Default value: `%entity%.%extension%` 43 | 44 | * `backupExistingFile` 45 | 46 | Perform backup existing file before writing generated file. 47 | 48 | Backup file will have an extension of *.bak. 49 | 50 | Default value: `true` 51 | 52 | * `headerFile` 53 | 54 | Include file as header in the generated files. It will be wrapped as a 55 | comment by choosen formatter. This configuration useful as for example 56 | to include notice to generated files such as license file. 57 | 58 | Default value: `blank` 59 | 60 | * `addGeneratorInfoAsComment` 61 | 62 | Include generated information as a comment in generated files. 63 | 64 | Default value: `true` 65 | 66 | * `namingStrategy` 67 | 68 | Naming strategy detemines how objects, variables, and methods name will be generated. 69 | 70 | Valid values: `as-is`, `camel-case`, `pascal-case` 71 | 72 | Default value: `as-is` 73 | 74 | * `identifierStrategy` 75 | 76 | Determines how identifier like table name will be treated for generated 77 | entity/model name. Supported identifier strategies are `fix-underscore` 78 | which will fix for double underscore to single underscore, and `none` which 79 | will do nothing. 80 | 81 | Valid values: `none`, `fix-underscore` 82 | 83 | Default value: `none` 84 | 85 | * `cleanUserDatatypePrefix` (alias: `asIsUserDatatypePrefix`) 86 | 87 | Clean user datatype matched the prefix specified. 88 | 89 | Default value: `blank` 90 | 91 | * `enhanceManyToManyDetection` 92 | 93 | Allows generate additional model for many to many relations. 94 | 95 | Default value: `true` 96 | 97 | * `sortTableAndView` (alias: `sortTablesAndViews`) 98 | 99 | Perform table name and view name sorting before generating files. 100 | 101 | Default value: `true` 102 | 103 | * `skipManyToManyTables` 104 | 105 | Skip many to many table generation. 106 | 107 | Default value: `true` 108 | 109 | * `skipPluralNameChecking` 110 | 111 | Skip checking the plural name of model and leave as is, useful for non English 112 | table names. 113 | 114 | Default value: `false` 115 | 116 | * `exportOnlyInCategory` (alias: `exportOnlyTableCategorized`) 117 | 118 | Some models may have category defined in comment, process only if it is matched. 119 | 120 | Default value: `blank` 121 | 122 | * `logToConsole` 123 | 124 | Activate logging to console. 125 | 126 | Default value: `false` 127 | 128 | * `logFile` 129 | 130 | Activate logging to filename. 131 | 132 | Default value: `blank` 133 | 134 | * `useLoggedStorage` 135 | 136 | Useful to use the generated files content for further processing. 137 | 138 | Default value: `false` 139 | 140 | ## Doctrine 2.0 Global Configuration 141 | 142 | * `useAutomaticRepository` 143 | 144 | Automatically generate entity repository class name. 145 | 146 | Default value: `true` 147 | 148 | * `repositoryNamespace` 149 | 150 | The namespace prefix for entity repository class name. For this configuration to apply, 151 | `useAutomaticRepository` must be set to `true`. 152 | 153 | Default value: `blank` 154 | 155 | * `bundleNamespace` 156 | 157 | The global namespace prefix for entity class name. 158 | 159 | Default value: `blank` 160 | 161 | * `entityNamespace` 162 | 163 | The entity namespace. 164 | 165 | Default value: `blank` 166 | 167 | * `tablenamePrefix` (alias: `prefixTablename`) 168 | 169 | Add prefix to table name. 170 | 171 | Default value: `blank` 172 | 173 | * `relatedVarNameFormat` 174 | 175 | The format for generated related column name. 176 | 177 | Default value: `%name%_%related%` 178 | 179 | * `skipColumnWithRelation` 180 | 181 | Don't generate columns definition (for YAML) or columns variable, columns getter and setter 182 | (for Annotation) which has relation to other table. 183 | 184 | Default value: `false` 185 | 186 | * `generatedValueStrategy` 187 | 188 | The stragety for auto-generated values. 189 | 190 | Valid values: `auto`, `identity`, `sequence`, `table`, `none` 191 | 192 | Default value: `auto` 193 | 194 | * `nullableAttribute` 195 | 196 | How nullable attribute of columns and joins is generated. Set to `auto` if you want to 197 | automatically include nullable attribute based on its value. Set to `always` to always 198 | include nullable attribute. 199 | 200 | Valid values: `auto`, `always` 201 | 202 | Default value: `auto` 203 | 204 | * `defaultCascade` 205 | 206 | The default cascade option to define. 207 | 208 | Valid values: ``, `persist`, `remove`, `merge`, `detach`, `all`, `refresh` 209 | 210 | Default value: `false` 211 | 212 | ## Doctrine 2.0 Annotation Configuration 213 | 214 | * `annotationPrefix` (alias: `useAnnotationPrefix`) 215 | 216 | Doctrine annotation prefix. 217 | 218 | Default value: `ORM\` 219 | 220 | * `extendsClass` 221 | 222 | Allows to define a base class from which all generated entities extend. 223 | 224 | Default value: `blank` 225 | 226 | * `skipGetterAndSetter` 227 | 228 | Don't generate columns getter and setter. 229 | 230 | Default value: `false` 231 | 232 | * `quoteIdentifierStrategy` 233 | 234 | This option determine wheter identifier quoting is applied or not, depend on 235 | the strategy value. 236 | 237 | `auto`, indentifier quoting enabled if identifier is a reserved word 238 | `always`, always quote identifier 239 | `none`, never quote identifier 240 | 241 | Valid values: `auto`, `always`, `none` 242 | 243 | Default value: `auto` 244 | 245 | * `generateEntitySerialization` 246 | 247 | Generate method `__sleep()` to include only real columns when entity is serialized. 248 | 249 | Default value: `true` 250 | 251 | * `generateExtendableEntity` 252 | 253 | Generate two class for each tables in schema, one for base and one other for extend class. 254 | The extend class would not be generated if it already exist. So it is safe to place custom code 255 | inside the extend class. 256 | 257 | This option will generate entity using Single Table Inheritance. 258 | 259 | Default value: `false` 260 | 261 | * `extendableEntityHasDiscriminator` 262 | 263 | Allows `DiscriminatorColumn` and `DiscriminatorMap` annotations. 264 | 265 | Default value: `true` 266 | 267 | * `useBehavioralExtensions` 268 | 269 | Use Doctrine2 behavioral extension like create table with name '_img' then can be 270 | auto create plugin support. 271 | 272 | Default value: `false` 273 | 274 | * `enableTypehint` (alias: `php7Typehints`) 275 | 276 | Enable typehint on generated models such as on argument or return value. 277 | 278 | Default value: `false` 279 | 280 | * `argumentTypehint` (alias: `php7ArgTypehints`) 281 | 282 | Enable typehint on method arguments. 283 | 284 | Default value: `true` 285 | 286 | * `returnValueTypehint` (alias: `php7ReturnTypehints`) 287 | 288 | Enable typehint on function return value. 289 | 290 | Default value: `true` 291 | 292 | * `ignoreTypehintColumns` (alias: `php7SkippedColumnsTypehints`) 293 | 294 | Allow blacklist the columns to be typehinted. 295 | 296 | Default value: `[]` 297 | 298 | -------------------------------------------------------------------------------- /docs/doctrine2-yaml.md: -------------------------------------------------------------------------------- 1 | # Doctrine 2.0 YAML Configuration 2 | 3 | Auto generated at 2023-04-28T09:14:39+0700. 4 | 5 | ## Global Configuration 6 | 7 | * `language` 8 | 9 | Language detemines which language used to transform singular and plural words 10 | used in certains other schema like Doctrine. 11 | 12 | Valid values: `none`, `english`, `french`, `norwegian-bokmal`, `portuguese`, `spanish`, 13 | `turkish` 14 | 15 | Default value: `none` 16 | 17 | * `useTab` (alias: `useTabs`) 18 | 19 | Use tab as blank instead of space in generated files. 20 | 21 | Default value: `false` 22 | 23 | * `indentation` 24 | 25 | Number of spaces used as blank in generated files. 26 | 27 | Default value: `4` 28 | 29 | * `eolDelimiter` (alias: `eolDelimeter`) 30 | 31 | End of line (EOL) delimiter detemines the end of line in generated files. 32 | 33 | Valid values: `win`, `unix` 34 | 35 | Default value: `win` 36 | 37 | * `filename` 38 | 39 | The output filename format, use the following tag `%schema%`, `%table%`, `%entity%`, and 40 | `%extension%` to allow the filename to be replaced with contextual data. 41 | 42 | Default value: `%entity%.dcm.%extension%` 43 | 44 | * `backupExistingFile` 45 | 46 | Perform backup existing file before writing generated file. 47 | 48 | Backup file will have an extension of *.bak. 49 | 50 | Default value: `true` 51 | 52 | * `headerFile` 53 | 54 | Include file as header in the generated files. It will be wrapped as a 55 | comment by choosen formatter. This configuration useful as for example 56 | to include notice to generated files such as license file. 57 | 58 | Default value: `blank` 59 | 60 | * `addGeneratorInfoAsComment` 61 | 62 | Include generated information as a comment in generated files. 63 | 64 | Default value: `true` 65 | 66 | * `namingStrategy` 67 | 68 | Naming strategy detemines how objects, variables, and methods name will be generated. 69 | 70 | Valid values: `as-is`, `camel-case`, `pascal-case` 71 | 72 | Default value: `as-is` 73 | 74 | * `identifierStrategy` 75 | 76 | Determines how identifier like table name will be treated for generated 77 | entity/model name. Supported identifier strategies are `fix-underscore` 78 | which will fix for double underscore to single underscore, and `none` which 79 | will do nothing. 80 | 81 | Valid values: `none`, `fix-underscore` 82 | 83 | Default value: `none` 84 | 85 | * `cleanUserDatatypePrefix` (alias: `asIsUserDatatypePrefix`) 86 | 87 | Clean user datatype matched the prefix specified. 88 | 89 | Default value: `blank` 90 | 91 | * `enhanceManyToManyDetection` 92 | 93 | Allows generate additional model for many to many relations. 94 | 95 | Default value: `true` 96 | 97 | * `sortTableAndView` (alias: `sortTablesAndViews`) 98 | 99 | Perform table name and view name sorting before generating files. 100 | 101 | Default value: `true` 102 | 103 | * `skipManyToManyTables` 104 | 105 | Skip many to many table generation. 106 | 107 | Default value: `true` 108 | 109 | * `skipPluralNameChecking` 110 | 111 | Skip checking the plural name of model and leave as is, useful for non English 112 | table names. 113 | 114 | Default value: `false` 115 | 116 | * `exportOnlyInCategory` (alias: `exportOnlyTableCategorized`) 117 | 118 | Some models may have category defined in comment, process only if it is matched. 119 | 120 | Default value: `blank` 121 | 122 | * `logToConsole` 123 | 124 | Activate logging to console. 125 | 126 | Default value: `false` 127 | 128 | * `logFile` 129 | 130 | Activate logging to filename. 131 | 132 | Default value: `blank` 133 | 134 | * `useLoggedStorage` 135 | 136 | Useful to use the generated files content for further processing. 137 | 138 | Default value: `false` 139 | 140 | ## Doctrine 2.0 Global Configuration 141 | 142 | * `useAutomaticRepository` 143 | 144 | Automatically generate entity repository class name. 145 | 146 | Default value: `true` 147 | 148 | * `repositoryNamespace` 149 | 150 | The namespace prefix for entity repository class name. For this configuration to apply, 151 | `useAutomaticRepository` must be set to `true`. 152 | 153 | Default value: `blank` 154 | 155 | * `bundleNamespace` 156 | 157 | The global namespace prefix for entity class name. 158 | 159 | Default value: `blank` 160 | 161 | * `entityNamespace` 162 | 163 | The entity namespace. 164 | 165 | Default value: `blank` 166 | 167 | * `tablenamePrefix` (alias: `prefixTablename`) 168 | 169 | Add prefix to table name. 170 | 171 | Default value: `blank` 172 | 173 | * `relatedVarNameFormat` 174 | 175 | The format for generated related column name. 176 | 177 | Default value: `%name%_%related%` 178 | 179 | * `skipColumnWithRelation` 180 | 181 | Don't generate columns definition (for YAML) or columns variable, columns getter and setter 182 | (for Annotation) which has relation to other table. 183 | 184 | Default value: `false` 185 | 186 | * `generatedValueStrategy` 187 | 188 | The stragety for auto-generated values. 189 | 190 | Valid values: `auto`, `identity`, `sequence`, `table`, `none` 191 | 192 | Default value: `auto` 193 | 194 | * `nullableAttribute` 195 | 196 | How nullable attribute of columns and joins is generated. Set to `auto` if you want to 197 | automatically include nullable attribute based on its value. Set to `always` to always 198 | include nullable attribute. 199 | 200 | Valid values: `auto`, `always` 201 | 202 | Default value: `auto` 203 | 204 | * `defaultCascade` 205 | 206 | The default cascade option to define. 207 | 208 | Valid values: ``, `persist`, `remove`, `merge`, `detach`, `all`, `refresh` 209 | 210 | Default value: `false` 211 | 212 | ## Doctrine 2.0 Yaml Configuration 213 | 214 | * `extendTableNameWithSchemaName` 215 | 216 | Include schema name in table name. 217 | 218 | Default value: `false` 219 | 220 | -------------------------------------------------------------------------------- /docs/doctrine2-zf2inputfilterannotation.md: -------------------------------------------------------------------------------- 1 | # Doctrine 2.0 Annotation with ZF2 input filter Classes Configuration 2 | 3 | Auto generated at 2023-04-28T09:14:39+0700. 4 | 5 | ## Global Configuration 6 | 7 | * `language` 8 | 9 | Language detemines which language used to transform singular and plural words 10 | used in certains other schema like Doctrine. 11 | 12 | Valid values: `none`, `english`, `french`, `norwegian-bokmal`, `portuguese`, `spanish`, 13 | `turkish` 14 | 15 | Default value: `none` 16 | 17 | * `useTab` (alias: `useTabs`) 18 | 19 | Use tab as blank instead of space in generated files. 20 | 21 | Default value: `false` 22 | 23 | * `indentation` 24 | 25 | Number of spaces used as blank in generated files. 26 | 27 | Default value: `4` 28 | 29 | * `eolDelimiter` (alias: `eolDelimeter`) 30 | 31 | End of line (EOL) delimiter detemines the end of line in generated files. 32 | 33 | Valid values: `win`, `unix` 34 | 35 | Default value: `win` 36 | 37 | * `filename` 38 | 39 | The output filename format, use the following tag `%schema%`, `%table%`, `%entity%`, and 40 | `%extension%` to allow the filename to be replaced with contextual data. 41 | 42 | Default value: `Entity/%entity%.%extension%` 43 | 44 | * `backupExistingFile` 45 | 46 | Perform backup existing file before writing generated file. 47 | 48 | Backup file will have an extension of *.bak. 49 | 50 | Default value: `true` 51 | 52 | * `headerFile` 53 | 54 | Include file as header in the generated files. It will be wrapped as a 55 | comment by choosen formatter. This configuration useful as for example 56 | to include notice to generated files such as license file. 57 | 58 | Default value: `blank` 59 | 60 | * `addGeneratorInfoAsComment` 61 | 62 | Include generated information as a comment in generated files. 63 | 64 | Default value: `true` 65 | 66 | * `namingStrategy` 67 | 68 | Naming strategy detemines how objects, variables, and methods name will be generated. 69 | 70 | Valid values: `as-is`, `camel-case`, `pascal-case` 71 | 72 | Default value: `as-is` 73 | 74 | * `identifierStrategy` 75 | 76 | Determines how identifier like table name will be treated for generated 77 | entity/model name. Supported identifier strategies are `fix-underscore` 78 | which will fix for double underscore to single underscore, and `none` which 79 | will do nothing. 80 | 81 | Valid values: `none`, `fix-underscore` 82 | 83 | Default value: `none` 84 | 85 | * `cleanUserDatatypePrefix` (alias: `asIsUserDatatypePrefix`) 86 | 87 | Clean user datatype matched the prefix specified. 88 | 89 | Default value: `blank` 90 | 91 | * `enhanceManyToManyDetection` 92 | 93 | Allows generate additional model for many to many relations. 94 | 95 | Default value: `true` 96 | 97 | * `sortTableAndView` (alias: `sortTablesAndViews`) 98 | 99 | Perform table name and view name sorting before generating files. 100 | 101 | Default value: `true` 102 | 103 | * `skipManyToManyTables` 104 | 105 | Skip many to many table generation. 106 | 107 | Default value: `true` 108 | 109 | * `skipPluralNameChecking` 110 | 111 | Skip checking the plural name of model and leave as is, useful for non English 112 | table names. 113 | 114 | Default value: `false` 115 | 116 | * `exportOnlyInCategory` (alias: `exportOnlyTableCategorized`) 117 | 118 | Some models may have category defined in comment, process only if it is matched. 119 | 120 | Default value: `blank` 121 | 122 | * `logToConsole` 123 | 124 | Activate logging to console. 125 | 126 | Default value: `false` 127 | 128 | * `logFile` 129 | 130 | Activate logging to filename. 131 | 132 | Default value: `blank` 133 | 134 | * `useLoggedStorage` 135 | 136 | Useful to use the generated files content for further processing. 137 | 138 | Default value: `false` 139 | 140 | ## Doctrine 2.0 Global Configuration 141 | 142 | * `useAutomaticRepository` 143 | 144 | Automatically generate entity repository class name. 145 | 146 | Default value: `true` 147 | 148 | * `repositoryNamespace` 149 | 150 | The namespace prefix for entity repository class name. For this configuration to apply, 151 | `useAutomaticRepository` must be set to `true`. 152 | 153 | Default value: `blank` 154 | 155 | * `bundleNamespace` 156 | 157 | The global namespace prefix for entity class name. 158 | 159 | Default value: `blank` 160 | 161 | * `entityNamespace` 162 | 163 | The entity namespace. 164 | 165 | Default value: `blank` 166 | 167 | * `tablenamePrefix` (alias: `prefixTablename`) 168 | 169 | Add prefix to table name. 170 | 171 | Default value: `blank` 172 | 173 | * `relatedVarNameFormat` 174 | 175 | The format for generated related column name. 176 | 177 | Default value: `%name%_%related%` 178 | 179 | * `skipColumnWithRelation` 180 | 181 | Don't generate columns definition (for YAML) or columns variable, columns getter and setter 182 | (for Annotation) which has relation to other table. 183 | 184 | Default value: `false` 185 | 186 | * `generatedValueStrategy` 187 | 188 | The stragety for auto-generated values. 189 | 190 | Valid values: `auto`, `identity`, `sequence`, `table`, `none` 191 | 192 | Default value: `auto` 193 | 194 | * `nullableAttribute` 195 | 196 | How nullable attribute of columns and joins is generated. Set to `auto` if you want to 197 | automatically include nullable attribute based on its value. Set to `always` to always 198 | include nullable attribute. 199 | 200 | Valid values: `auto`, `always` 201 | 202 | Default value: `auto` 203 | 204 | * `defaultCascade` 205 | 206 | The default cascade option to define. 207 | 208 | Valid values: ``, `persist`, `remove`, `merge`, `detach`, `all`, `refresh` 209 | 210 | Default value: `false` 211 | 212 | ## Doctrine 2.0 Annotation Configuration 213 | 214 | * `annotationPrefix` (alias: `useAnnotationPrefix`) 215 | 216 | Doctrine annotation prefix. 217 | 218 | Default value: `ORM\` 219 | 220 | * `extendsClass` 221 | 222 | Allows to define a base class from which all generated entities extend. 223 | 224 | Default value: `blank` 225 | 226 | * `skipGetterAndSetter` 227 | 228 | Don't generate columns getter and setter. 229 | 230 | Default value: `false` 231 | 232 | * `quoteIdentifierStrategy` 233 | 234 | This option determine wheter identifier quoting is applied or not, depend on 235 | the strategy value. 236 | 237 | `auto`, indentifier quoting enabled if identifier is a reserved word 238 | `always`, always quote identifier 239 | `none`, never quote identifier 240 | 241 | Valid values: `auto`, `always`, `none` 242 | 243 | Default value: `auto` 244 | 245 | * `generateEntitySerialization` 246 | 247 | Generate method `__sleep()` to include only real columns when entity is serialized. 248 | 249 | Default value: `true` 250 | 251 | * `generateExtendableEntity` 252 | 253 | Generate two class for each tables in schema, one for base and one other for extend class. 254 | The extend class would not be generated if it already exist. So it is safe to place custom code 255 | inside the extend class. 256 | 257 | This option will generate entity using Single Table Inheritance. 258 | 259 | Default value: `false` 260 | 261 | * `extendableEntityHasDiscriminator` 262 | 263 | Allows `DiscriminatorColumn` and `DiscriminatorMap` annotations. 264 | 265 | Default value: `true` 266 | 267 | * `useBehavioralExtensions` 268 | 269 | Use Doctrine2 behavioral extension like create table with name '_img' then can be 270 | auto create plugin support. 271 | 272 | Default value: `false` 273 | 274 | * `enableTypehint` (alias: `php7Typehints`) 275 | 276 | Enable typehint on generated models such as on argument or return value. 277 | 278 | Default value: `false` 279 | 280 | * `argumentTypehint` (alias: `php7ArgTypehints`) 281 | 282 | Enable typehint on method arguments. 283 | 284 | Default value: `true` 285 | 286 | * `returnValueTypehint` (alias: `php7ReturnTypehints`) 287 | 288 | Enable typehint on function return value. 289 | 290 | Default value: `true` 291 | 292 | * `ignoreTypehintColumns` (alias: `php7SkippedColumnsTypehints`) 293 | 294 | Allow blacklist the columns to be typehinted. 295 | 296 | Default value: `[]` 297 | 298 | ## Doctrine 2.0 Annotation ZF2 Input Filter Configuration 299 | 300 | * `generateEntityPopulate` 301 | 302 | Generate `populate()` method for entity class. 303 | 304 | Default value: `true` 305 | 306 | * `generateEntityGetArrayCopy` 307 | 308 | Generate `getArrayCopy()` method for entity class. 309 | 310 | Default value: `true` 311 | 312 | -------------------------------------------------------------------------------- /export1.json: -------------------------------------------------------------------------------- 1 | { 2 | "export": "doctrine2-annotation", 3 | "zip": false, 4 | "dir": "build", 5 | "params": { 6 | "language": "english", 7 | "useTab": false, 8 | "indentation": 4, 9 | "eolDelimiter": "win", 10 | "filename": "%entity%.%extension%", 11 | "backupExistingFile": true, 12 | "addGeneratorInfoAsComment": true, 13 | "namingStrategy": "as-is", 14 | "identifierStrategy": "none", 15 | "cleanUserDatatypePrefix": "", 16 | "enhanceManyToManyDetection": true, 17 | "sortTableAndView": true, 18 | "skipManyToManyTables": true, 19 | "skipPluralNameChecking": false, 20 | "exportOnlyInCategory": "", 21 | "logToConsole": false, 22 | "logFile": "", 23 | "useLoggedStorage": false, 24 | "useAutomaticRepository": true, 25 | "repositoryNamespace": "", 26 | "bundleNamespace": "", 27 | "entityNamespace": "", 28 | "tablenamePrefix": "", 29 | "relatedVarNameFormat": "%name%_%related%", 30 | "skipColumnWithRelation": false, 31 | "generatedValueStrategy": "auto", 32 | "nullableAttribute": "auto", 33 | "defaultCascade": false, 34 | "annotationPrefix": "ORM\\", 35 | "extendsClass": "", 36 | "skipGetterAndSetter": false, 37 | "quoteIdentifierStrategy": "auto", 38 | "generateEntitySerialization": true, 39 | "generateExtendableEntity": false, 40 | "extendableEntityHasDiscriminator": true, 41 | "useBehavioralExtensions": false, 42 | "enableTypehint": false, 43 | "argumentTypehint": true, 44 | "returnValueTypehint": true, 45 | "ignoreTypehintColumns": [] 46 | } 47 | } -------------------------------------------------------------------------------- /export2.json: -------------------------------------------------------------------------------- 1 | { 2 | "export": "doctrine2-yaml", 3 | "zip": false, 4 | "dir": "build", 5 | "params": { 6 | "language": "english", 7 | "useTab": false, 8 | "indentation": 4, 9 | "eolDelimiter": "win", 10 | "filename": "%entity%.dcm.%extension%", 11 | "backupExistingFile": true, 12 | "addGeneratorInfoAsComment": true, 13 | "namingStrategy": "as-is", 14 | "identifierStrategy": "none", 15 | "cleanUserDatatypePrefix": "", 16 | "enhanceManyToManyDetection": true, 17 | "sortTableAndView": true, 18 | "skipManyToManyTables": true, 19 | "skipPluralNameChecking": false, 20 | "exportOnlyInCategory": "", 21 | "logToConsole": false, 22 | "logFile": "", 23 | "useLoggedStorage": false, 24 | "useAutomaticRepository": true, 25 | "repositoryNamespace": "", 26 | "bundleNamespace": "", 27 | "entityNamespace": "", 28 | "tablenamePrefix": "", 29 | "relatedVarNameFormat": "%name%_%related%", 30 | "skipColumnWithRelation": false, 31 | "generatedValueStrategy": "auto", 32 | "nullableAttribute": "auto", 33 | "defaultCascade": false, 34 | "extendTableNameWithSchemaName": false 35 | } 36 | } -------------------------------------------------------------------------------- /export3.json: -------------------------------------------------------------------------------- 1 | { 2 | "export": "doctrine2-zf2inputfilterannotation", 3 | "zip": false, 4 | "dir": "build", 5 | "params": { 6 | "language": "english", 7 | "useTab": false, 8 | "indentation": 4, 9 | "eolDelimiter": "win", 10 | "filename": "Entity\/%entity%.%extension%", 11 | "backupExistingFile": true, 12 | "addGeneratorInfoAsComment": true, 13 | "namingStrategy": "as-is", 14 | "identifierStrategy": "none", 15 | "cleanUserDatatypePrefix": "", 16 | "enhanceManyToManyDetection": true, 17 | "sortTableAndView": true, 18 | "skipManyToManyTables": true, 19 | "skipPluralNameChecking": false, 20 | "exportOnlyInCategory": "", 21 | "logToConsole": false, 22 | "logFile": "", 23 | "useLoggedStorage": false, 24 | "useAutomaticRepository": true, 25 | "repositoryNamespace": "", 26 | "bundleNamespace": "", 27 | "entityNamespace": "", 28 | "tablenamePrefix": "", 29 | "relatedVarNameFormat": "%name%_%related%", 30 | "skipColumnWithRelation": false, 31 | "generatedValueStrategy": "auto", 32 | "nullableAttribute": "auto", 33 | "defaultCascade": false, 34 | "annotationPrefix": "ORM\\", 35 | "extendsClass": "", 36 | "skipGetterAndSetter": false, 37 | "quoteIdentifierStrategy": "auto", 38 | "generateEntitySerialization": true, 39 | "generateExtendableEntity": false, 40 | "extendableEntityHasDiscriminator": true, 41 | "useBehavioralExtensions": false, 42 | "enableTypehint": false, 43 | "argumentTypehint": true, 44 | "returnValueTypehint": true, 45 | "ignoreTypehintColumns": [], 46 | "generateEntityPopulate": true, 47 | "generateEntityGetArrayCopy": true 48 | } 49 | } -------------------------------------------------------------------------------- /lib/Annotation/Configuration/AnnotationPrefix.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Doctrine annotation prefix. 33 | * 34 | * @author Toha 35 | * @config annotationPrefix|useAnnotationPrefix 36 | * @label Annotation prefix 37 | */ 38 | class AnnotationPrefix extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = 'ORM\\'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/BehavioralExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Use Doctrine2 behavioral extension like create table with name '_img' then can be 33 | * auto create plugin support. 34 | * 35 | * @author Toha 36 | * @config useBehavioralExtensions 37 | * @label Enable behavioral extension 38 | */ 39 | class BehavioralExtension extends Configuration 40 | { 41 | protected function initialize() 42 | { 43 | $this->category = 'doctrineConfiguration'; 44 | $this->defaultValue = false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/ClassExtend.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Allows to define a base class from which all generated entities extend. 33 | * 34 | * @author Toha 35 | * @config extendsClass 36 | * @label Base class to extend to 37 | */ 38 | class ClassExtend extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = ''; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/EntityExtend.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Generate two class for each tables in schema, one for base and one other for extend class. 33 | * The extend class would not be generated if it already exist. So it is safe to place custom code 34 | * inside the extend class. 35 | * 36 | * This option will generate entity using Single Table Inheritance. 37 | * 38 | * @author Toha 39 | * @config generateExtendableEntity 40 | * @label Generate extendable entity 41 | */ 42 | class EntityExtend extends Configuration 43 | { 44 | protected function initialize() 45 | { 46 | $this->category = 'doctrineConfiguration'; 47 | $this->defaultValue = false; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/EntityExtendDiscriminator.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Allows `DiscriminatorColumn` and `DiscriminatorMap` annotations. 33 | * 34 | * @author Toha 35 | * @config extendableEntityHasDiscriminator 36 | * @label Enable generated discriminator for extendable entity 37 | */ 38 | class EntityExtendDiscriminator extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/EntitySerialize.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Generate method `__sleep()` to include only real columns when entity is serialized. 33 | * 34 | * @author Toha 35 | * @config generateEntitySerialization 36 | * @label Generate entity serialization method 37 | */ 38 | class EntitySerialize extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/GetterSetterSkip.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Don't generate columns getter and setter. 33 | * 34 | * @author Toha 35 | * @config skipGetterAndSetter 36 | * @label Skip getter and setter 37 | */ 38 | class GetterSetterSkip extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/IdentifierQuotingStrategy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * This option determine wheter identifier quoting is applied or not, depend on 33 | * the strategy value. 34 | * 35 | * `auto`, indentifier quoting enabled if identifier is a reserved word 36 | * `always`, always quote identifier 37 | * `none`, never quote identifier 38 | * 39 | * @author Toha 40 | * @config quoteIdentifierStrategy 41 | * @label Identifier quoting strategy 42 | */ 43 | class IdentifierQuotingStrategy extends Configuration 44 | { 45 | public const AUTO = 'auto'; 46 | public const ALWAYS = 'always'; 47 | public const NONE = 'none'; 48 | 49 | protected function initialize() 50 | { 51 | $this->category = 'doctrineConfiguration'; 52 | $this->defaultValue = static::AUTO; 53 | $this->choices = [ 54 | static::AUTO, 55 | static::ALWAYS, 56 | static::NONE, 57 | ]; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/Typehint.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Enable typehint on generated models such as on argument or return value. 33 | * 34 | * @author Toha 35 | * @config enableTypehint|php7Typehints 36 | * @label Enable some typehints in generated model 37 | */ 38 | class Typehint extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/TypehintArgument.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Enable typehint on method arguments. 33 | * 34 | * @author Toha 35 | * @config argumentTypehint|php7ArgTypehints 36 | * @label Enable typehint on argument 37 | */ 38 | class TypehintArgument extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | $this->depends = [ 45 | Typehint::class => true, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/TypehintReturnValue.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Enable typehint on function return value. 33 | * 34 | * @author Toha 35 | * @config returnValueTypehint|php7ReturnTypehints 36 | * @label Enable typehint on function return value 37 | */ 38 | class TypehintReturnValue extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | $this->depends = [ 45 | Typehint::class => true, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/Annotation/Configuration/TypehintSkip.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Allow blacklist the columns to be typehinted. 33 | * 34 | * @author Toha 35 | * @config ignoreTypehintColumns|php7SkippedColumnsTypehints 36 | * @label Ignore typehint on some columns 37 | */ 38 | class TypehintSkip extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = []; 44 | $this->depends = [ 45 | Typehint::class => true, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/Annotation/DatatypeConverter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Annotation; 29 | 30 | use MwbExporter\Formatter\Doctrine2\DatatypeConverter as BaseDatatypeConverter; 31 | 32 | class DatatypeConverter extends BaseDatatypeConverter 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /lib/Annotation/Formatter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Annotation; 29 | 30 | use MwbExporter\Configuration\Indentation as IndentationConfiguration; 31 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\AnnotationPrefix as AnnotationPrefixConfiguration; 32 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\BehavioralExtension as BehavioralExtensionConfiguration; 33 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\ClassExtend as ClassExtendConfiguration; 34 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\EntityExtend as EntityExtendConfiguration; 35 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\EntityExtendDiscriminator as EntityExtendDiscriminatorConfiguration; 36 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\EntitySerialize as EntitySerializeConfiguration; 37 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\GetterSetterSkip as GetterSetterSkipConfiguration; 38 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\IdentifierQuotingStrategy as IdentifierQuotingStrategyConfiguration; 39 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\Typehint as TypehintConfiguration; 40 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\TypehintArgument as TypehintArgumentConfiguration; 41 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\TypehintReturnValue as TypehintReturnValueConfiguration; 42 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\TypehintSkip as TypehintSkipConfiguration; 43 | use MwbExporter\Formatter\Doctrine2\Formatter as BaseFormatter; 44 | use MwbExporter\Helper\Comment; 45 | use MwbExporter\Model\Base; 46 | 47 | class Formatter extends BaseFormatter 48 | { 49 | protected function init() 50 | { 51 | parent::init(); 52 | $this->getConfigurations() 53 | ->add(new AnnotationPrefixConfiguration()) 54 | ->add(new ClassExtendConfiguration()) 55 | ->add(new GetterSetterSkipConfiguration()) 56 | ->add(new IdentifierQuotingStrategyConfiguration()) 57 | ->add(new EntitySerializeConfiguration()) 58 | ->add(new EntityExtendConfiguration()) 59 | ->add(new EntityExtendDiscriminatorConfiguration()) 60 | ->add(new BehavioralExtensionConfiguration()) 61 | ->add(new TypehintConfiguration()) 62 | ->add(new TypehintArgumentConfiguration()) 63 | ->add(new TypehintReturnValueConfiguration()) 64 | ->add(new TypehintSkipConfiguration()) 65 | ->merge([ 66 | IndentationConfiguration::class => 4, 67 | ], true) 68 | ; 69 | $this->commentFormat = Comment::FORMAT_PHP; 70 | } 71 | 72 | /** 73 | * (non-PHPdoc) 74 | * @see \MwbExporter\Formatter\Formatter::createDatatypeConverter() 75 | */ 76 | protected function createDatatypeConverter() 77 | { 78 | return new DatatypeConverter(); 79 | } 80 | 81 | /** 82 | * (non-PHPdoc) 83 | * @see \MwbExporter\Formatter\Formatter::createTable() 84 | */ 85 | public function createTable(Base $parent, $node) 86 | { 87 | return new Model\Table($parent, $node); 88 | } 89 | 90 | /** 91 | * (non-PHPdoc) 92 | * @see \MwbExporter\Formatter\FormatterInterface::createColumn() 93 | */ 94 | public function createColumn(Base $parent, $node) 95 | { 96 | return new Model\Column($parent, $node); 97 | } 98 | 99 | public function getTitle() 100 | { 101 | return 'Doctrine 2.0 Annotation Classes'; 102 | } 103 | 104 | public function getFileExtension() 105 | { 106 | return 'php'; 107 | } 108 | 109 | /** 110 | * Get configuration scope. 111 | * 112 | * @return string 113 | */ 114 | public static function getScope() 115 | { 116 | return 'Doctrine 2.0 Annotation'; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /lib/Annotation/Model/Column.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Annotation\Model; 29 | 30 | use MwbExporter\Formatter\DatatypeConverterInterface; 31 | use MwbExporter\Formatter\Doctrine2\Configuration\GeneratedValueStrategy as GeneratedValueStrategyConfiguration; 32 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\BehavioralExtension as BehavioralExtensionConfiguration; 33 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\Typehint as TypehintConfiguration; 34 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\TypehintArgument as TypehintArgumentConfiguration; 35 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\TypehintReturnValue as TypehintReturnValueConfiguration; 36 | use MwbExporter\Formatter\Doctrine2\Annotation\Configuration\TypehintSkip as TypehintSkipConfiguration; 37 | use MwbExporter\Formatter\Doctrine2\Model\Column as BaseColumn; 38 | use MwbExporter\Writer\WriterInterface; 39 | 40 | /** 41 | * @method \MwbExporter\Formatter\Doctrine2\Annotation\Model\Table getTable() 42 | */ 43 | class Column extends BaseColumn 44 | { 45 | public function getColumnName($raw = true) 46 | { 47 | $name = parent::getColumnName(); 48 | 49 | return $raw ? $name : $this->getNaming($name); 50 | } 51 | 52 | private function getStringDefaultValue() 53 | { 54 | $defaultValue = $this->getDefaultValue(); 55 | if (is_null($defaultValue) || $this->isDefaultValueCurrentTimestamp()) { 56 | $defaultValue = ''; 57 | } else { 58 | if ($this->getColumnType() == DatatypeConverterInterface::DATATYPE_VARCHAR) { 59 | $defaultValue = " = $defaultValue"; 60 | } elseif ($this->isBoolean()) { 61 | $defaultValue = " = ".($defaultValue == 0 ? 'false' : 'true'); 62 | } else { 63 | $defaultValue = " = $defaultValue"; 64 | } 65 | } 66 | 67 | return $defaultValue; 68 | } 69 | 70 | public function writeVar(WriterInterface $writer) 71 | { 72 | if (!$this->isIgnored()) { 73 | $useBehavioralExtensions = $this->getConfig(BehavioralExtensionConfiguration::class)->getValue(); 74 | $isBehavioralColumn = strstr($this->getTable()->getName(), '_img') && $useBehavioralExtensions; 75 | $comment = $this->getComment(false); 76 | $columnName = $this->getColumnName(false); 77 | $writer 78 | ->commentStart() 79 | ->writeIf($comment, $comment) 80 | ->writeIf( 81 | $this->isPrimary, 82 | $this->getTable()->getAnnotation('Id') 83 | ) 84 | ->writeIf( 85 | $useBehavioralExtensions && $this->getColumnName() === 'created_at', 86 | '@Gedmo\Timestampable(on="create")' 87 | ) 88 | ->writeIf( 89 | $useBehavioralExtensions && $this->getColumnName() === 'updated_at', 90 | '@Gedmo\Timestampable(on="update")' 91 | ) 92 | ->write($this->getTable()->getAnnotation('Column', $this->asAnnotation())) 93 | ->writeIf( 94 | $this->isAutoIncrement(), 95 | $this->getTable()->getAnnotation('GeneratedValue', ['strategy' => strtoupper($this->getConfig(GeneratedValueStrategyConfiguration::class)->getValue())]) 96 | ) 97 | ->writeIf( 98 | $isBehavioralColumn && strstr($this->getColumnName(), 'path'), 99 | '@Gedmo\UploadableFilePath' 100 | ) 101 | ->writeIf( 102 | $isBehavioralColumn && strstr($this->getColumnName(), 'name'), 103 | '@Gedmo\UploadableFileName' 104 | ) 105 | ->writeIf( 106 | $isBehavioralColumn && strstr($this->getColumnName(), 'mime'), 107 | '@Gedmo\UploadableFileMimeType' 108 | ) 109 | ->writeIf( 110 | $isBehavioralColumn && strstr($this->getColumnName(), 'size'), 111 | '@Gedmo\UploadableFileSize' 112 | ) 113 | ->commentEnd() 114 | ->write('protected $'.$columnName.$this->getStringDefaultValue().';') 115 | ->write('') 116 | ; 117 | } 118 | 119 | return $this; 120 | } 121 | 122 | public function writeGetterAndSetter(WriterInterface $writer) 123 | { 124 | if (!$this->isIgnored()) { 125 | $this->getDocument()->addLog(sprintf(' Writing setter/getter for column "%s"', $this->getColumnName())); 126 | 127 | $table = $this->getTable(); 128 | $converter = $this->getFormatter()->getDatatypeConverter(); 129 | $nativeType = $converter->getNativeType($converter->getMappedType($this)); 130 | $columnName = $this->getColumnName(false); 131 | 132 | $typehints = [ 133 | 'set_phpdoc_arg' => $this->typehint($nativeType, !$this->isNotNull()), 134 | 'set_phpdoc_return' => $this->typehint($table->getNamespace(), false), 135 | 'set_arg' => $this->paramTypehint($nativeType, !$this->isNotNull()), 136 | 'set_return' => $this->returnTypehint(null, false), 137 | 138 | 'get_phpdoc' => $this->typehint($nativeType, !$this->isNotNull()), 139 | 'get_return' => $this->returnTypehint($nativeType, null === $this->getDefaultValue() ? true : !$this->isNotNull()), 140 | ]; 141 | 142 | $writer 143 | // setter 144 | ->commentStart() 145 | ->write('Set the value of '.$columnName.'.') 146 | ->write('') 147 | ->write('@param '.$typehints['set_phpdoc_arg'].' $'.$columnName) 148 | ->write('@return '.$typehints['set_phpdoc_return']) 149 | ->commentEnd() 150 | ->write('public function set'.$this->getBeautifiedColumnName().'('.$typehints['set_arg'].'$'.$columnName.')'.$typehints['set_return']) 151 | ->write('{') 152 | ->indent() 153 | ->write('$this->'.$columnName.' = $'.$columnName.';') 154 | ->write('') 155 | ->write('return $this;') 156 | ->outdent() 157 | ->write('}') 158 | ->write('') 159 | // getter 160 | ->commentStart() 161 | ->write('Get the value of '.$columnName.'.') 162 | ->write('') 163 | ->write('@return '.$typehints['get_phpdoc']) 164 | ->commentEnd() 165 | ->write('public function '.$this->getColumnGetterName().'()'.$typehints['get_return']) 166 | ->write('{') 167 | ->indent() 168 | ->write('return $this->'.$columnName.';') 169 | ->outdent() 170 | ->write('}') 171 | ->write('') 172 | ; 173 | } 174 | 175 | return $this; 176 | } 177 | 178 | /** 179 | * @return array 180 | */ 181 | public function asAnnotation() 182 | { 183 | $columnName = $this->getColumnName(false); 184 | $attributes = [ 185 | 'name' => ($quotedColumnName = $this->getTable()->quoteIdentifier($this->getColumnName())) !== $columnName ? $quotedColumnName : null, 186 | 'type' => $this->getFormatter()->getDatatypeConverter()->getMappedType($this), 187 | ]; 188 | if (($length = $this->parameters->get('length')) && ($length != -1)) { 189 | $attributes['length'] = (int) $length; 190 | } 191 | if (($precision = $this->parameters->get('precision')) && ($precision != -1) && ($scale = $this->parameters->get('scale')) && ($scale != -1)) { 192 | $attributes['precision'] = (int) $precision; 193 | $attributes['scale'] = (int) $scale; 194 | } 195 | if ($this->isNullableRequired()) { 196 | $attributes['nullable'] = $this->getNullableValue(); 197 | } 198 | 199 | $attributes['options'] = []; 200 | if ($this->isUnsigned()) { 201 | $attributes['options'] = ['unsigned' => true]; 202 | } 203 | 204 | if ('json' === $attributes['type']) { 205 | $attributes['options']['jsonb'] = true; 206 | } 207 | 208 | $rawDefaultValue = $this->parameters->get('defaultValue') == 'NULL' ? null : $this->parameters->get('defaultValue'); 209 | if ($rawDefaultValue !== '') { 210 | $attributes['options']['default'] = $rawDefaultValue === '' ? null : $rawDefaultValue; 211 | } 212 | 213 | if (count($attributes['options']) == 0) { 214 | unset($attributes['options']); 215 | } 216 | 217 | return $attributes; 218 | } 219 | 220 | protected function typehint($type, $nullable) 221 | { 222 | if (strlen($type)) { 223 | $type = strtr($type, ['integer' => 'int', 'boolean' => 'bool']); 224 | if ($this->getConfig(TypehintConfiguration::class)->getValue()) { 225 | if ($nullable || '\DateTime' === $type) { 226 | $type = '?'.$type; 227 | } 228 | } 229 | } 230 | 231 | return $type; 232 | } 233 | 234 | protected function isTypehintSkipped() 235 | { 236 | return in_array($this->getTable()->getName().'.'.$this->getColumnName(), $this->getConfig(TypehintSkipConfiguration::class)->getValue()); 237 | } 238 | 239 | protected function paramTypehint($type, $nullable) 240 | { 241 | if ($this->getConfig(TypehintConfiguration::class)->getValue() && 242 | $this->getConfig(TypehintArgumentConfiguration::class)->getValue() && 243 | !$this->isTypehintSkipped() && 244 | strlen($type)) { 245 | return $this->typehint($type, $nullable).' '; 246 | } 247 | } 248 | 249 | protected function returnTypehint($type, $nullable) 250 | { 251 | if ($this->getConfig(TypehintConfiguration::class)->getValue() && 252 | $this->getConfig(TypehintReturnValueConfiguration::class)->getValue() && 253 | !$this->isTypehintSkipped() && 254 | strlen($type)) { 255 | return ': '.$this->typehint($type, $nullable); 256 | } 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /lib/Configuration/AutomaticRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Automatically generate entity repository class name. 33 | * 34 | * @author Toha 35 | * @config useAutomaticRepository 36 | * @label Enable automatic repository 37 | */ 38 | class AutomaticRepository extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Configuration/BundleNamespace.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * The global namespace prefix for entity class name. 33 | * 34 | * @author Toha 35 | * @config bundleNamespace 36 | * @label Bundle namespace 37 | */ 38 | class BundleNamespace extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = ''; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Configuration/Cascade.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * The default cascade option to define. 33 | * 34 | * @author Toha 35 | * @config defaultCascade 36 | * @label Default cascade 37 | */ 38 | class Cascade extends Configuration 39 | { 40 | public const NONE = false; 41 | public const PERSIST = 'persist'; 42 | public const REMOVE = 'remove'; 43 | public const MERGE = 'merge'; 44 | public const DETACH = 'detach'; 45 | public const ALL = 'all'; 46 | public const REFRESH = 'refresh'; 47 | 48 | protected function initialize() 49 | { 50 | $this->category = 'doctrineConfiguration'; 51 | $this->defaultValue = static::NONE; 52 | $this->choices = [ 53 | static::NONE, 54 | static::PERSIST, 55 | static::REMOVE, 56 | static::MERGE, 57 | static::DETACH, 58 | static::ALL, 59 | static::REFRESH, 60 | ]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lib/Configuration/ColumnWithRelationSkip.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Don't generate columns definition (for YAML) or columns variable, columns getter and setter 33 | * (for Annotation) which has relation to other table. 34 | * 35 | * @author Toha 36 | * @config skipColumnWithRelation 37 | * @label Skip column which has relation 38 | */ 39 | class ColumnWithRelationSkip extends Configuration 40 | { 41 | protected function initialize() 42 | { 43 | $this->category = 'doctrineConfiguration'; 44 | $this->defaultValue = false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/Configuration/EntityNamespace.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * The entity namespace. 33 | * 34 | * @author Toha 35 | * @config entityNamespace 36 | * @label Entity namespace 37 | */ 38 | class EntityNamespace extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = ''; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Configuration/GeneratedValueStrategy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * The stragety for auto-generated values. 33 | * 34 | * @author Toha 35 | * @config generatedValueStrategy 36 | * @label Generated value strategy 37 | */ 38 | class GeneratedValueStrategy extends Configuration 39 | { 40 | public const AUTO = 'auto'; 41 | public const IDENTITY = 'identity'; 42 | public const SEQUENCE = 'sequence'; 43 | public const TABLE = 'table'; 44 | public const NONE = 'none'; 45 | 46 | protected function initialize() 47 | { 48 | $this->category = 'doctrineConfiguration'; 49 | $this->defaultValue = static::AUTO; 50 | $this->choices = [ 51 | static::AUTO, 52 | static::IDENTITY, 53 | static::SEQUENCE, 54 | static::TABLE, 55 | static::NONE, 56 | ]; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lib/Configuration/NullableAttribute.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * How nullable attribute of columns and joins is generated. Set to `auto` if you want to 33 | * automatically include nullable attribute based on its value. Set to `always` to always 34 | * include nullable attribute. 35 | * 36 | * @author Toha 37 | * @config nullableAttribute 38 | * @label Nullable attribute 39 | */ 40 | class NullableAttribute extends Configuration 41 | { 42 | public const AUTO = 'auto'; 43 | public const ALWAYS = 'always'; 44 | 45 | protected function initialize() 46 | { 47 | $this->category = 'doctrineConfiguration'; 48 | $this->defaultValue = static::AUTO; 49 | $this->choices = [ 50 | static::AUTO, 51 | static::ALWAYS, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/Configuration/RelatedVarName.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * The format for generated related column name. 33 | * 34 | * @author Toha 35 | * @config relatedVarNameFormat 36 | * @label Related variable name format 37 | */ 38 | class RelatedVarName extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = '%name%_%related%'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Configuration/RepositoryNamespace.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * The namespace prefix for entity repository class name. For this configuration to apply, 33 | * `useAutomaticRepository` must be set to `true`. 34 | * 35 | * @author Toha 36 | * @config repositoryNamespace 37 | * @label Repository namespace 38 | */ 39 | class RepositoryNamespace extends Configuration 40 | { 41 | protected function initialize() 42 | { 43 | $this->category = 'doctrineConfiguration'; 44 | $this->defaultValue = ''; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/Configuration/TableNamePrefix.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Add prefix to table name. 33 | * 34 | * @author Toha 35 | * @config tablenamePrefix|prefixTablename 36 | * @label Table name prefix 37 | */ 38 | class TableNamePrefix extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = ''; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/DatatypeConverter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2; 29 | 30 | use MwbExporter\Formatter\DatatypeConverter as BaseDatatypeConverter; 31 | use MwbExporter\Model\Column; 32 | 33 | class DatatypeConverter extends BaseDatatypeConverter 34 | { 35 | public function setup() 36 | { 37 | $this->register([ 38 | static::DATATYPE_TINYINT => 'smallint', 39 | static::DATATYPE_SMALLINT => 'smallint', 40 | static::DATATYPE_MEDIUMINT => 'integer', 41 | static::DATATYPE_INT => 'integer', 42 | static::DATATYPE_BIGINT => 'bigint', 43 | static::DATATYPE_FLOAT => 'float', 44 | static::DATATYPE_DOUBLE => 'float', 45 | static::DATATYPE_DECIMAL => 'decimal', 46 | static::DATATYPE_CHAR => 'string', 47 | static::DATATYPE_NCHAR => 'string', 48 | static::DATATYPE_VARCHAR => 'string', 49 | static::DATATYPE_NVARCHAR => 'string', 50 | static::DATATYPE_JSON => 'array', 51 | static::DATATYPE_BINARY => 'blob', 52 | static::DATATYPE_VARBINARY => 'blob', 53 | static::DATATYPE_TINYTEXT => 'text', 54 | static::DATATYPE_TEXT => 'text', 55 | static::DATATYPE_MEDIUMTEXT => 'text', 56 | static::DATATYPE_LONGTEXT => 'text', 57 | static::DATATYPE_TINYBLOB => 'blob', 58 | static::DATATYPE_BLOB => 'blob', 59 | static::DATATYPE_MEDIUMBLOB => 'blob', 60 | static::DATATYPE_LONGBLOB => 'blob', 61 | static::DATATYPE_DATETIME => 'datetime', 62 | static::DATATYPE_DATETIME_F => 'datetime', 63 | static::DATATYPE_DATE => 'date', 64 | static::DATATYPE_DATE_F => 'date', 65 | static::DATATYPE_TIME => 'time', 66 | static::DATATYPE_TIME_F => 'time', 67 | static::DATATYPE_TIMESTAMP => 'datetime', 68 | static::DATATYPE_TIMESTAMP_F => 'datetime', 69 | static::DATATYPE_YEAR => 'smallint', 70 | static::DATATYPE_GEOMETRY => 'object', 71 | static::DATATYPE_LINESTRING => 'object', 72 | static::DATATYPE_POLYGON => 'object', 73 | static::DATATYPE_MULTIPOINT => 'object', 74 | static::DATATYPE_MULTILINESTRING => 'object', 75 | static::DATATYPE_MULTIPOLYGON => 'object', 76 | static::DATATYPE_GEOMETRYCOLLECTION => 'object', 77 | static::DATATYPE_BIT => 'bigint', 78 | static::DATATYPE_ENUM => 'string', 79 | static::DATATYPE_SET => 'string', 80 | static::USERDATATYPE_BOOLEAN => 'boolean', 81 | static::USERDATATYPE_BOOL => 'boolean', 82 | static::USERDATATYPE_FIXED => 'decimal', 83 | static::USERDATATYPE_FLOAT4 => 'float', 84 | static::USERDATATYPE_FLOAT8 => 'float', 85 | static::USERDATATYPE_INT1 => 'integer', 86 | static::USERDATATYPE_INT2 => 'integer', 87 | static::USERDATATYPE_INT3 => 'integer', 88 | static::USERDATATYPE_INT4 => 'integer', 89 | static::USERDATATYPE_INT8 => 'integer', 90 | static::USERDATATYPE_INTEGER => 'integer', 91 | static::USERDATATYPE_LONGVARBINARY => 'blob', 92 | static::USERDATATYPE_LONGVARCHAR => 'blob', 93 | static::USERDATATYPE_LONG => 'bigint', 94 | static::USERDATATYPE_MIDDLEINT => 'integer', 95 | static::USERDATATYPE_NUMERIC => 'decimal', 96 | static::USERDATATYPE_DEC => 'decimal', 97 | static::USERDATATYPE_CHARACTER => 'string', 98 | ]); 99 | } 100 | 101 | public function getNativeType($type) 102 | { 103 | switch ($type) { 104 | case 'array': 105 | case 'boolean': 106 | case 'integer': 107 | case 'string': 108 | case 'float': 109 | case 'object': 110 | break; 111 | case 'datetime': 112 | case 'datetimez': 113 | case 'date': 114 | case 'time': 115 | return '\\DateTime'; 116 | break; 117 | case 'smallint': 118 | $type = 'integer'; 119 | break; 120 | case 'decimal': 121 | case 'bigint': 122 | case 'text': 123 | case 'blob': 124 | $type = 'string'; 125 | break; 126 | default: 127 | break; 128 | } 129 | 130 | return $type; 131 | } 132 | 133 | public function getMappedType(Column $column) 134 | { 135 | if ($column->isBoolean()) { 136 | return 'boolean'; 137 | } 138 | 139 | return parent::getMappedType($column); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /lib/Formatter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2; 29 | 30 | use MwbExporter\Formatter\Doctrine2\Configuration\AutomaticRepository as AutomaticRepositoryConfiguration; 31 | use MwbExporter\Formatter\Doctrine2\Configuration\BundleNamespace as BundleNamespaceConfiguration; 32 | use MwbExporter\Formatter\Doctrine2\Configuration\Cascade as CascadeConfiguration; 33 | use MwbExporter\Formatter\Doctrine2\Configuration\ColumnWithRelationSkip as ColumnWithRelationSkipConfiguration; 34 | use MwbExporter\Formatter\Doctrine2\Configuration\EntityNamespace as EntityNamespaceConfiguration; 35 | use MwbExporter\Formatter\Doctrine2\Configuration\GeneratedValueStrategy as GeneratedValueStrategyConfiguration; 36 | use MwbExporter\Formatter\Doctrine2\Configuration\NullableAttribute as NullableAttributeConfiguration; 37 | use MwbExporter\Formatter\Doctrine2\Configuration\RelatedVarName as RelatedVarNameConfiguration; 38 | use MwbExporter\Formatter\Doctrine2\Configuration\RepositoryNamespace as RepositoryNamespaceConfiguration; 39 | use MwbExporter\Formatter\Doctrine2\Configuration\TableNamePrefix as TableNamePrefixConfiguration; 40 | use MwbExporter\Formatter\Formatter as BaseFormatter; 41 | 42 | abstract class Formatter extends BaseFormatter 43 | { 44 | protected function init() 45 | { 46 | parent::init(); 47 | $this->getConfigurations() 48 | ->add(new AutomaticRepositoryConfiguration()) 49 | ->add(new RepositoryNamespaceConfiguration()) 50 | ->add(new BundleNamespaceConfiguration()) 51 | ->add(new EntityNamespaceConfiguration()) 52 | ->add(new TableNamePrefixConfiguration()) 53 | ->add(new RelatedVarNameConfiguration()) 54 | ->add(new ColumnWithRelationSkipConfiguration()) 55 | ->add(new GeneratedValueStrategyConfiguration()) 56 | ->add(new NullableAttributeConfiguration()) 57 | ->add(new CascadeConfiguration()) 58 | ; 59 | } 60 | 61 | public function getVersion() 62 | { 63 | return 'dev'; 64 | } 65 | 66 | /** 67 | * (non-PHPdoc) 68 | * @see \MwbExporter\Formatter\Formatter::createDatatypeConverter() 69 | */ 70 | protected function createDatatypeConverter() 71 | { 72 | return new DatatypeConverter(); 73 | } 74 | 75 | /** 76 | * Get owning side of relation. 77 | * 78 | * @param array $relation 79 | * @param \MwbExporter\Model\ForeignKey $mappedRelation 80 | * @return boolean 81 | */ 82 | public function isOwningSide($relation, &$mappedRelation) 83 | { 84 | $mappedRelation = $relation['reference']->getOwningTable()->getRelationToTable($relation['refTable']->getRawTableName()); 85 | 86 | // user can hint which side is the owning side (set d:owningSide on the foreign key) 87 | if ($relation['reference']->parseComment('owningSide') === 'true') { 88 | return true; 89 | } 90 | if ($mappedRelation->parseComment('owningSide') === 'true') { 91 | return false; 92 | } 93 | 94 | // if no owning side is defined, use one side randomly as owning side (the one where the column id is lower) 95 | return $relation['reference']->getLocal()->getId() < $mappedRelation->getLocal()->getId(); 96 | } 97 | 98 | /** 99 | * get the cascade option as array. Only returns values allowed by Doctrine. 100 | * 101 | * @param $cascadeValue string cascade options separated by comma 102 | * @return array array with the values or null, if no cascade values are available 103 | */ 104 | public function getCascadeOption($cascadeValue) 105 | { 106 | /** @var \MwbExporter\Formatter\Doctrine2\Configuration\Cascade $cascade */ 107 | $cascade = $this->getConfig(CascadeConfiguration::class); 108 | $defaultCascade = $cascade->getValue(); 109 | if (empty($cascadeValue) && !empty($defaultCascade)) { 110 | return [$defaultCascade]; 111 | } 112 | 113 | $cascadeValue = array_map('strtolower', array_map('trim', explode(',', (string) $cascadeValue))); 114 | $cascadeValue = array_intersect($cascadeValue, $cascade->getChoices()); 115 | $cascadeValue = array_filter($cascadeValue); 116 | if (empty($cascadeValue)) { 117 | return; 118 | } 119 | 120 | return $cascadeValue; 121 | } 122 | 123 | /** 124 | * get the cache option for an entity or a relation 125 | * 126 | * @param $cacheValue string cache option as given in comment for table or foreign key 127 | * @return string valid cache value or null 128 | */ 129 | public function getCacheOption($cacheValue) 130 | { 131 | if ($cacheValue) { 132 | $cacheValue = strtoupper($cacheValue); 133 | if (in_array($cacheValue, ['READ_ONLY', 'NONSTRICT_READ_WRITE', 'READ_WRITE'])) { 134 | return $cacheValue; 135 | } 136 | } 137 | } 138 | 139 | /** 140 | * Parse order option. 141 | * 142 | * @param string $sortValue 143 | * @return array 144 | */ 145 | public function getOrderOption($sortValue) 146 | { 147 | $orders = []; 148 | if ($sortValue = trim((string) $sortValue)) { 149 | $lines = array_map('trim', explode("\n", $sortValue)); 150 | foreach ($lines as $line) { 151 | if (count($values = array_map('trim', explode(',', $line)))) { 152 | $column = $values[0]; 153 | $order = (count($values) > 1) ? strtoupper($values[1]) : null; 154 | if (!in_array($order, ['ASC', 'DESC'])) { 155 | $order = 'ASC'; 156 | } 157 | $orders[$column] = $order; 158 | } 159 | } 160 | } 161 | 162 | return $orders; 163 | } 164 | 165 | /** 166 | * get the fetch option for a relation 167 | * 168 | * @param $fetchValue string fetch option as given in comment for foreign key 169 | * @return string valid fetch value or null 170 | */ 171 | public function getFetchOption($fetchValue) 172 | { 173 | if ($fetchValue) { 174 | $fetchValue = strtoupper($fetchValue); 175 | if (in_array($fetchValue, ['EAGER', 'LAZY', 'EXTRA_LAZY'])) { 176 | return $fetchValue; 177 | } 178 | } 179 | } 180 | 181 | /** 182 | * get the a boolean option for a relation 183 | * 184 | * @param $booleanValue string boolean option (true or false) 185 | * @return boolean or null, if booleanValue was invalid 186 | */ 187 | public function getBooleanOption($booleanValue) 188 | { 189 | if ($booleanValue) { 190 | switch (strtolower($booleanValue)) { 191 | case 'true': 192 | return true; 193 | case 'false': 194 | return false; 195 | } 196 | } 197 | } 198 | 199 | /** 200 | * get the onDelete rule. this will set the database level ON DELETE and can be set 201 | * to CASCADE or SET NULL. Do not confuse this with the Doctrine-level cascade rules. 202 | */ 203 | public function getDeleteRule($deleteRule) 204 | { 205 | if ($deleteRule == 'NO ACTION' || $deleteRule == 'RESTRICT' || empty($deleteRule)) { 206 | // NO ACTION acts the same as RESTRICT, 207 | // RESTRICT is the default 208 | // http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html 209 | $deleteRule = null; 210 | } 211 | 212 | return $deleteRule; 213 | } 214 | 215 | /** 216 | * (non-PHPdoc) 217 | * @see \MwbExporter\Formatter\Formatter::getCommentTagPrefixes() 218 | */ 219 | protected function getCommentTagPrefixes() 220 | { 221 | return array_merge(parent::getCommentTagPrefixes(), ['d', 'doctrine']); 222 | } 223 | 224 | public static function getDocDir() 225 | { 226 | return __DIR__.'/../docs'; 227 | } 228 | 229 | /** 230 | * Get configuration scope. 231 | * 232 | * @return string 233 | */ 234 | public static function getScope() 235 | { 236 | return 'Doctrine 2.0 Global'; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /lib/Model/Column.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Model; 28 | 29 | use MwbExporter\Formatter\DatatypeConverterInterface; 30 | use MwbExporter\Formatter\Doctrine2\Configuration\ColumnWithRelationSkip as ColumnWithRelationSkipConfiguration; 31 | use MwbExporter\Formatter\Doctrine2\Configuration\NullableAttribute as NullableAttributeConfiguration; 32 | use MwbExporter\Model\Column as BaseColumn; 33 | 34 | class Column extends BaseColumn 35 | { 36 | public const RELATION_ONE_TO_ONE = '1:1'; 37 | public const RELATION_ONE_TO_MANY = '1:M'; 38 | public const RELATION_MANY_TO_ONE = 'M:1'; 39 | public const RELATION_MANY_TO_MANY = 'M:M'; 40 | 41 | /** 42 | * Current Doctrine default value for nullable column attribute. 43 | */ 44 | public const NULLABLE_DEFAULT = false; 45 | 46 | /** 47 | * Is nullable attribute always required. 48 | * 49 | * @return boolean 50 | */ 51 | protected function isAlwaysNullable() 52 | { 53 | return $this->getConfig(NullableAttributeConfiguration::class)->getValue() === NullableAttributeConfiguration::ALWAYS; 54 | } 55 | 56 | /** 57 | * Is nullable attribute required. 58 | * 59 | * @return boolean 60 | */ 61 | public function isNullableRequired($defaultValue = self::NULLABLE_DEFAULT) 62 | { 63 | $isNullable = !$this->isNotNull(); 64 | 65 | return $isNullable === $defaultValue ? ($this->isAlwaysNullable() ? true : false) : true; 66 | } 67 | 68 | /** 69 | * Get nullable attribute value. 70 | * 71 | * @return boolean 72 | */ 73 | public function getNullableValue($defaultValue = self::NULLABLE_DEFAULT) 74 | { 75 | $isNullable = !$this->isNotNull(); 76 | 77 | return $isNullable === $defaultValue ? ($this->isAlwaysNullable() ? $isNullable : null) : $isNullable; 78 | } 79 | 80 | /** 81 | * Check if column is ignored. 82 | * 83 | * @return boolean 84 | */ 85 | public function isIgnored() 86 | { 87 | // don't ignore primary key 88 | if ($this->isPrimary) { 89 | return false; 90 | } 91 | // don't ignore when configuration is not set 92 | if (!$this->getConfig(ColumnWithRelationSkipConfiguration::class)->getValue()) { 93 | return false; 94 | } 95 | // don't ignore when column has no relation 96 | if (0 === (count($this->getLocalForeignKeys()) + count($this->getForeignKeys()))) { 97 | return false; 98 | } 99 | 100 | return true; 101 | } 102 | 103 | /** 104 | * Check If column is boolean. 105 | * 106 | * @return boolean 107 | */ 108 | public function isBoolean() 109 | { 110 | $columnType = $this->getColumnType(); 111 | 112 | if ( 113 | DatatypeConverterInterface::USERDATATYPE_BOOL == $columnType || 114 | DatatypeConverterInterface::USERDATATYPE_BOOLEAN == $columnType || 115 | ( 116 | DatatypeConverterInterface::DATATYPE_TINYINT == $columnType && 117 | preg_match('/^(is|has|can)_/', $this->getColumnName()) 118 | ) 119 | ) { 120 | return true; 121 | } 122 | 123 | return false; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /lib/Model/Table.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Model; 28 | 29 | use MwbExporter\Formatter\Doctrine2\Configuration\BundleNamespace as BundleNamespaceConfiguration; 30 | use MwbExporter\Formatter\Doctrine2\Configuration\EntityNamespace as EntityNamespaceConfiguration; 31 | use MwbExporter\Formatter\Doctrine2\Configuration\RelatedVarName as RelatedVarNameConfiguration; 32 | use MwbExporter\Model\Table as BaseTable; 33 | 34 | class Table extends BaseTable 35 | { 36 | /** 37 | * Get the entity namespace. 38 | * 39 | * @return string 40 | */ 41 | public function getEntityNamespace() 42 | { 43 | $namespace = ''; 44 | if (($bundleNamespace = $this->parseComment('bundleNamespace')) || ($bundleNamespace = $this->getConfig(BundleNamespaceConfiguration::class)->getValue())) { 45 | $namespace = $bundleNamespace.'\\'; 46 | } 47 | if ($entityNamespace = $this->getConfig(EntityNamespaceConfiguration::class)->getValue()) { 48 | $namespace .= $entityNamespace; 49 | } else { 50 | $namespace .= 'Entity'; 51 | } 52 | 53 | return $namespace; 54 | } 55 | 56 | public function getBaseEntityNamespace() 57 | { 58 | return 'Base\\'.$this->getEntityNamespace(); 59 | } 60 | 61 | /** 62 | * Get the entity cacheMode. 63 | * 64 | * @return string 65 | */ 66 | public function getEntityCacheMode() 67 | { 68 | $cacheMode = strtoupper(trim((string) $this->parseComment('cache'))); 69 | if (in_array($cacheMode, ['READ_ONLY', 'NONSTRICT_READ_WRITE', 'READ_WRITE'])) { 70 | return $cacheMode; 71 | } 72 | } 73 | 74 | /** 75 | * Get namespace of a class. 76 | * 77 | * @param string $class The class name 78 | * @return string 79 | */ 80 | public function getNamespace($class = null, $absolute = true, $base = false) 81 | { 82 | return sprintf( 83 | '%s%s\%s', 84 | $absolute ? '\\' : '', 85 | $base ? $this->getBaseEntityNamespace() : $this->getEntityNamespace(), 86 | null === $class ? $this->getModelName() : $class 87 | ); 88 | } 89 | 90 | /** 91 | * Get Model Name in FQCN format. If reference namespace is suplied and the entity namespace 92 | * is equal then relative model name returned instead. 93 | * 94 | * @param string $referenceNamespace The reference namespace 95 | * @return string 96 | */ 97 | public function getModelNameAsFQCN($referenceNamespace = null) 98 | { 99 | $namespace = $this->getEntityNamespace(); 100 | $fqcn = ($namespace == $referenceNamespace) ? false : true; 101 | 102 | return $fqcn ? $namespace.'\\'.$this->getModelName() : $this->getModelName(); 103 | } 104 | 105 | /** 106 | * Get lifecycleCallbacks. 107 | * 108 | * @return array 109 | */ 110 | public function getLifecycleCallbacks() 111 | { 112 | $result = []; 113 | if ($lifecycleCallbacks = trim((string) $this->parseComment('lifecycleCallbacks'))) { 114 | foreach (explode("\n", $lifecycleCallbacks) as $callback) { 115 | list($method, $handler) = explode(':', $callback, 2); 116 | $method = lcfirst(trim($method)); 117 | if (!in_array($method, ['postLoad', 'prePersist', 'postPersist', 'preRemove', 'postRemove', 'preUpdate', 'postUpdate'])) { 118 | continue; 119 | } 120 | if (!isset($result[$method])) { 121 | $result[$method] = []; 122 | } 123 | $result[$method][] = trim($handler); 124 | } 125 | } 126 | 127 | return $result; 128 | } 129 | 130 | /** 131 | * Get identifier name formatting. 132 | * 133 | * @param string $name Identifier name 134 | * @param string $related Related name 135 | * @param string $plural Return plural form 136 | * @return string 137 | */ 138 | public function getRelatedVarName($name, $related = null, $plural = false) 139 | { 140 | /** 141 | * if $name does not match the current ModelName (in case a relation column), check if the table comment includes the `relatedNames` tag 142 | * and parse that to see if for $name was provided a custom value 143 | */ 144 | 145 | $nameFromCommentTag = ''; 146 | $relatedNames = trim((string) $this->parseComment('relatedNames')); 147 | 148 | if ('' !== $relatedNames) { 149 | foreach (explode("\n", $relatedNames) as $relationMap) { 150 | list($toChange, $replacement) = explode(':', $relationMap, 2); 151 | if ($name === $toChange) { 152 | $nameFromCommentTag = $replacement; 153 | break; 154 | } 155 | } 156 | } 157 | if ($nameFromCommentTag) { 158 | $name = $nameFromCommentTag; 159 | } else { 160 | $name = $related ? strtr($this->getConfig(RelatedVarNameConfiguration::class)->getValue(), ['%name%' => $name, '%related%' => $related]) : $name; 161 | } 162 | 163 | return $plural ? $this->pluralize($name) : $name; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /lib/Yaml/Configuration/TableNameExtend.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\Yaml\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Include schema name in table name. 33 | * 34 | * @author Toha 35 | * @config extendTableNameWithSchemaName 36 | * @label Extend table name with schema name 37 | */ 38 | class TableNameExtend extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Yaml/DatatypeConverter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Yaml; 29 | 30 | use MwbExporter\Formatter\Doctrine2\DatatypeConverter as BaseDatatypeConverter; 31 | use MwbExporter\Model\Column; 32 | 33 | class DatatypeConverter extends BaseDatatypeConverter 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /lib/Yaml/Formatter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Yaml; 29 | 30 | use MwbExporter\Configuration\Filename as FilenameConfiguration; 31 | use MwbExporter\Configuration\Indentation as IndentationConfiguration; 32 | use MwbExporter\Formatter\Doctrine2\Yaml\Configuration\TableNameExtend as TableNameExtendConfiguration; 33 | use MwbExporter\Formatter\Doctrine2\Formatter as BaseFormatter; 34 | use MwbExporter\Model\Base; 35 | 36 | class Formatter extends BaseFormatter 37 | { 38 | protected function init() 39 | { 40 | parent::init(); 41 | $this->getConfigurations() 42 | ->add(new TableNameExtendConfiguration()) 43 | ->merge([ 44 | IndentationConfiguration::class => 4, 45 | FilenameConfiguration::class => '%entity%.dcm.%extension%', 46 | ], true) 47 | ; 48 | } 49 | 50 | /** 51 | * (non-PHPdoc) 52 | * @see \MwbExporter\Formatter\Formatter::createDatatypeConverter() 53 | */ 54 | protected function createDatatypeConverter() 55 | { 56 | return new DatatypeConverter(); 57 | } 58 | 59 | /** 60 | * (non-PHPdoc) 61 | * @see \MwbExporter\Formatter\Formatter::createTable() 62 | */ 63 | public function createTable(Base $parent, $node) 64 | { 65 | return new Model\Table($parent, $node); 66 | } 67 | 68 | /** 69 | * (non-PHPdoc) 70 | * @see \MwbExporter\Formatter\FormatterInterface::createColumn() 71 | */ 72 | public function createColumn(Base $parent, $node) 73 | { 74 | return new Model\Column($parent, $node); 75 | } 76 | 77 | public function getTitle() 78 | { 79 | return 'Doctrine 2.0 YAML'; 80 | } 81 | 82 | public function getFileExtension() 83 | { 84 | return 'yml'; 85 | } 86 | 87 | /** 88 | * Get configuration scope. 89 | * 90 | * @return string 91 | */ 92 | public static function getScope() 93 | { 94 | return 'Doctrine 2.0 Yaml'; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /lib/Yaml/Model/Column.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Yaml\Model; 29 | 30 | use MwbExporter\Formatter\DatatypeConverterInterface; 31 | use MwbExporter\Formatter\Doctrine2\Configuration\GeneratedValueStrategy as GeneratedValueStrategyConfiguration; 32 | use MwbExporter\Formatter\Doctrine2\Model\Column as BaseColumn; 33 | 34 | class Column extends BaseColumn 35 | { 36 | public function asYAML() 37 | { 38 | $values = []; 39 | $values['type'] = $this->getFormatter()->getDatatypeConverter()->getMappedType($this); 40 | if (($length = $this->getParameters()->get('length')) && ($length != -1)) { 41 | $values['length'] = (int) $length; 42 | } 43 | if (($precision = $this->getParameters()->get('precision')) && ($precision != -1) && ($scale = $this->getParameters()->get('scale')) && ($scale != -1)) { 44 | $values['precision'] = (int) $precision; 45 | $values['scale'] = (int) $scale; 46 | } 47 | if ($this->isNullableRequired()) { 48 | $values['nullable'] = $this->getNullableValue(); 49 | } 50 | if ($this->isUnsigned()) { 51 | $values['unsigned'] = true; 52 | } 53 | if ($this->isAutoIncrement()) { 54 | $values['generator'] = ['strategy' => strtoupper($this->getConfig(GeneratedValueStrategyConfiguration::class)->getValue())]; 55 | } 56 | if ($this->getDefaultValue() !== null) { 57 | $values['options']['default'] = $this->isStringType() 58 | ? "'" . $this->getDefaultValue() . "'" 59 | : $this->getDefaultValue() ; 60 | } 61 | 62 | return $values; 63 | } 64 | 65 | /** 66 | * Get if the type is a string or not. 67 | * @return bool Return true if the datatype is a string, else return false. 68 | */ 69 | private function isStringType() 70 | { 71 | switch($this->getColumnType()) { 72 | case DatatypeConverterInterface::DATATYPE_CHAR: 73 | case DatatypeConverterInterface::DATATYPE_VARCHAR: 74 | return true; 75 | default: 76 | return false; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /lib/Yaml/Model/Table.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | 28 | namespace MwbExporter\Formatter\Doctrine2\Yaml\Model; 29 | 30 | use MwbExporter\Configuration\Comment as CommentConfiguration; 31 | use MwbExporter\Configuration\Header as HeaderConfiguration; 32 | use MwbExporter\Configuration\Indentation as IndentationConfiguration; 33 | use MwbExporter\Configuration\Language as LanguageConfiguration; 34 | use MwbExporter\Configuration\M2MSkip as M2MSkipConfiguration; 35 | use MwbExporter\Formatter\Doctrine2\Configuration\AutomaticRepository as AutomaticRepositoryConfiguration; 36 | use MwbExporter\Formatter\Doctrine2\Configuration\RepositoryNamespace as RepositoryNamespaceConfiguration; 37 | use MwbExporter\Formatter\Doctrine2\Configuration\TableNamePrefix as TableNamePrefixConfiguration; 38 | use MwbExporter\Formatter\Doctrine2\Model\Table as BaseTable; 39 | use MwbExporter\Helper\Comment; 40 | use MwbExporter\Model\ForeignKey; 41 | use MwbExporter\Writer\WriterInterface; 42 | use NTLAB\Object\YAML; 43 | 44 | /** 45 | * @method \MwbExporter\Formatter\Doctrine2\Yaml\Formatter getFormatter() 46 | */ 47 | class Table extends BaseTable 48 | { 49 | public function writeTable(WriterInterface $writer) 50 | { 51 | switch (true) { 52 | case $this->isExternal(): 53 | return self::WRITE_EXTERNAL; 54 | case $this->getConfig(M2MSkipConfiguration::class)->getValue() && $this->isManyToMany(): 55 | return self::WRITE_M2M; 56 | default: 57 | $this->getDocument()->addLog(sprintf('Writing table "%s"', $this->getModelName())); 58 | $writer 59 | ->open($this->getTableFileName()) 60 | ->writeCallback(function(WriterInterface $writer, ?Table $_this = null) { 61 | /** @var \MwbExporter\Configuration\Header $header */ 62 | $header = $this->getConfig(HeaderConfiguration::class); 63 | if ($content = $header->getHeader()) { 64 | $writer 65 | ->write($_this->getFormatter()->getFormattedComment($content, Comment::FORMAT_YAML, null)) 66 | ->write('') 67 | ; 68 | } 69 | if ($_this->getConfig(CommentConfiguration::class)->getValue()) { 70 | $writer 71 | ->write($_this->getFormatter()->getComment(Comment::FORMAT_YAML)) 72 | ->write('') 73 | ; 74 | } 75 | }) 76 | ->write($this->asYAML()) 77 | ->close() 78 | ; 79 | 80 | return self::WRITE_OK; 81 | } 82 | } 83 | 84 | public function asYAML() 85 | { 86 | $namespace = $this->getNamespace(null, false); 87 | 88 | $values = [ 89 | 'type' => 'entity', 90 | 'table' => $this->getConfig(TableNamePrefixConfiguration::class)->getValue().$this->getRawTableName(), 91 | ]; 92 | // cache Mode 93 | if (!is_null($cacheMode = $this->getEntityCacheMode())) { 94 | $values['cache'] = []; 95 | $values['cache']['usage'] = $cacheMode; 96 | } 97 | if ($this->getConfig(AutomaticRepositoryConfiguration::class)->getValue()) { 98 | if ($repositoryNamespace = $this->getConfig(RepositoryNamespaceConfiguration::class)->getValue()) { 99 | $repositoryNamespace .= '\\'; 100 | } 101 | $values['repositoryClass'] = $repositoryNamespace.$this->getModelName().'Repository'; 102 | } 103 | // indices 104 | $this->getIndicesAsYAML($values, 'indexes'); 105 | // columns => ids & fields 106 | $this->getColumnsAsYAML($values); 107 | // uniques 108 | $this->getIndicesAsYAML($values, 'uniqueConstraints'); 109 | // table relations 110 | $this->getRelationsAsYAML($values); 111 | // table m2m relations 112 | $this->getM2MRelationsAsYAML($values); 113 | // lifecycle callback 114 | if (count($lifecycleCallbacks = $this->getLifecycleCallbacks())) { 115 | $values['lifecycleCallbacks'] = $lifecycleCallbacks; 116 | } 117 | /** @var \MwbExporter\Configuration\Indentation $indentation */ 118 | $indentation = $this->getConfig(IndentationConfiguration::class); 119 | 120 | return new YAML([$namespace => $values], ['indentation' => $indentation->getIndentation(1), 'skip_null' => true]); 121 | } 122 | 123 | protected function getIndicesAsYAML(&$values, $type = 'indexes') 124 | { 125 | foreach ($this->getTableIndices() as $index) { 126 | switch (true) { 127 | case $type === 'indexes' && $index->isIndex(): 128 | case $type === 'uniqueConstraints' && $index->isUnique(): 129 | if (!isset($values[$type])) { 130 | $values[$type] = []; 131 | } 132 | $values[$type][$index->getName()] = ['columns' => $index->getColumnNames()]; 133 | break; 134 | } 135 | } 136 | 137 | return $this; 138 | } 139 | 140 | protected function getColumnsAsYAML(&$values) 141 | { 142 | foreach ($this->getColumns() as $column) { 143 | if ($column->isPrimary()) { 144 | if (!isset($values['id'])) { 145 | $values['id'] = []; 146 | } 147 | $values['id'][$column->getColumnName()] = $column->asYAML(); 148 | } else { 149 | if ($column->isIgnored()) { 150 | continue; 151 | } 152 | if (!isset($values['fields'])) { 153 | $values['fields'] = []; 154 | } 155 | $values['fields'][$column->getColumnName()] = $column->asYAML(); 156 | } 157 | } 158 | 159 | return $this; 160 | } 161 | 162 | protected function getRelationsAsYAML(&$values) 163 | { 164 | // 1 <=> ? references 165 | foreach ($this->getAllLocalForeignKeys() as $local) { 166 | if ($this->isLocalForeignKeyIgnored($local)) { 167 | continue; 168 | } 169 | $targetEntity = $local->getOwningTable()->getModelName(); 170 | $targetEntityFQCN = $local->getOwningTable()->getModelNameAsFQCN($local->getReferencedTable()->getEntityNamespace()); 171 | $mappedBy = $local->getReferencedTable()->getModelName(); 172 | $related = $local->getForeignM2MRelatedName(); 173 | 174 | $this->getDocument()->addLog(sprintf(' Writing 1 <=> ? relation "%s"', $targetEntity)); 175 | 176 | if ($local->isManyToOne()) { 177 | $this->getDocument()->addLog(' Relation considered as "1 <=> N"'); 178 | 179 | $type = 'oneToMany'; 180 | $relationName = lcfirst($this->getRelatedVarName($targetEntity, $related, true)); 181 | if (!isset($values[$type])) { 182 | $values[$type] = []; 183 | } 184 | $values[$type][$relationName] = array_merge([ 185 | 'targetEntity' => $targetEntity, 186 | 'mappedBy' => lcfirst($this->getRelatedVarName($mappedBy, $related)), 187 | 'cascade' => $this->getFormatter()->getCascadeOption($local->parseComment('cascade')), 188 | 'fetch' => $this->getFormatter()->getFetchOption($local->parseComment('fetch')), 189 | 'orphanRemoval' => $this->getFormatter()->getBooleanOption($local->parseComment('orphanRemoval')), 190 | ], $this->getJoins($local)); 191 | } else { 192 | $this->getDocument()->addLog(' Relation considered as "1 <=> 1"'); 193 | 194 | $type = 'oneToOne'; 195 | $relationName = lcfirst($targetEntity); 196 | if (!isset($values[$type])) { 197 | $values[$type] = []; 198 | } 199 | $values[$type][$relationName] = array_merge([ 200 | 'targetEntity' => $targetEntity, 201 | 'mappedBy' => lcfirst($this->getRelatedVarName($mappedBy, $related)), 202 | ], $this->getJoins($local)); 203 | } 204 | if (!is_null($cacheMode = $this->getFormatter()->getCacheOption($local->parseComment('cache')))) { 205 | $values[$type][$relationName]['cache']['usage'] = $cacheMode; 206 | } 207 | } 208 | 209 | // N <=> ? references 210 | foreach ($this->getAllForeignKeys() as $foreign) { 211 | if ($this->isForeignKeyIgnored($foreign)) { 212 | continue; 213 | } 214 | $targetEntity = $foreign->getReferencedTable()->getModelName(); 215 | $targetEntityFQCN = $foreign->getReferencedTable()->getModelNameAsFQCN($foreign->getOwningTable()->getEntityNamespace()); 216 | $inversedBy = $foreign->getOwningTable()->getModelName(); 217 | $related = $this->getRelatedName($foreign); 218 | 219 | $this->getDocument()->addLog(sprintf(' Writing N <=> ? relation "%s"', $targetEntity)); 220 | 221 | if ($foreign->isManyToOne()) { 222 | $this->getDocument()->addLog(' Relation considered as "N <=> 1"'); 223 | 224 | $type = 'manyToOne'; 225 | $relationName = lcfirst($this->getRelatedVarName($targetEntity, $related)); 226 | if (!isset($values[$type])) { 227 | $values[$type] = []; 228 | } 229 | $values[$type][$relationName] = array_merge([ 230 | 'targetEntity' => $targetEntityFQCN, 231 | 'inversedBy' => lcfirst($this->getRelatedVarName($inversedBy, $related, true)), 232 | ], $this->getJoins($foreign, false)); 233 | } else { 234 | $this->getDocument()->addLog(' Relation considered as "1 <=> 1"'); 235 | 236 | $type = 'oneToOne'; 237 | $relationName = lcfirst($targetEntity); 238 | if (!isset($values[$type])) { 239 | $values[$type] = []; 240 | } 241 | $values[$type][$relationName] = array_merge([ 242 | 'targetEntity' => $targetEntityFQCN, 243 | 'inversedBy' => $foreign->isUnidirectional() ? null : lcfirst($this->getRelatedVarName($inversedBy, $related)), 244 | ], $this->getJoins($foreign, false)); 245 | } 246 | if (!is_null($cacheMode = $this->getFormatter()->getCacheOption($foreign->parseComment('cache')))) { 247 | $values[$type][$relationName]['cache']['usage'] = $cacheMode; 248 | } 249 | } 250 | 251 | return $this; 252 | } 253 | 254 | protected function getM2MRelationsAsYAML(&$values) 255 | { 256 | // many to many relations 257 | foreach ($this->getTableM2MRelations() as $relation) { 258 | $fk1 = $relation['reference']; 259 | $isOwningSide = $this->getFormatter()->isOwningSide($relation, $fk2); 260 | $mappings = [ 261 | 'targetEntity' => $relation['refTable']->getModelNameAsFQCN($this->getEntityNamespace()), 262 | 'mappedBy' => null, 263 | 'inversedBy' => lcfirst($this->getPluralModelName()), 264 | 'cascade' => $this->getFormatter()->getCascadeOption($fk1->parseComment('cascade')), 265 | 'fetch' => $this->getFormatter()->getFetchOption($fk1->parseComment('fetch')), 266 | ]; 267 | 268 | $relationName = $this->pluralize($relation['refTable']->getRawTableName()); 269 | /** @var \MwbExporter\Configuration\Language $lang */ 270 | $lang = $this->getConfig(LanguageConfiguration::class); 271 | if ($inflector = $lang->getInflector()) { 272 | $relationName = $inflector->camelize($relationName); 273 | } 274 | 275 | // if this is the owning side, also output the JoinTable Annotation 276 | // otherwise use "mappedBy" feature 277 | if ($isOwningSide) { 278 | if ($fk1->isUnidirectional()) { 279 | unset($mappings['inversedBy']); 280 | } 281 | 282 | $type = 'manyToMany'; 283 | if (!isset($values[$type])) { 284 | $values[$type] = []; 285 | } 286 | $values[$type][$relationName] = array_merge($mappings, [ 287 | 'joinTable' => [ 288 | 'name' => $fk1->getOwningTable()->getRawTableName(), 289 | 'joinColumns' => $this->convertJoinColumns($this->getJoins($fk1, false)), 290 | 'inverseJoinColumns' => $this->convertJoinColumns($this->getJoins($fk2, false)), 291 | ], 292 | ]); 293 | if (!is_null($cacheMode = $this->getFormatter()->getCacheOption($fk1->parseComment('cache')))) { 294 | $values[$type][$relationName]['cache']['usage'] = $cacheMode; 295 | } 296 | } else { 297 | if ($fk2->isUnidirectional()) { 298 | continue; 299 | } 300 | $mappings['mappedBy'] = $mappings['inversedBy']; 301 | $mappings['inversedBy'] = null; 302 | 303 | $type = 'manyToMany'; 304 | if (!isset($values[$type])) { 305 | $values[$type] = []; 306 | } 307 | $values[$type][$relationName] = $mappings; 308 | if (!is_null($cacheMode = $this->getFormatter()->getCacheOption($fk2->parseComment('cache')))) { 309 | $values[$type][$relationName]['cache']['usage'] = $cacheMode; 310 | } 311 | } 312 | } 313 | 314 | return $this; 315 | } 316 | 317 | protected function convertJoinColumns($joins = []) 318 | { 319 | $result = []; 320 | foreach ($joins as $join) { 321 | if (!isset($join['name'])) { 322 | continue; 323 | } 324 | $key = $join['name']; 325 | unset($join['name']); 326 | $result[$key] = $join; 327 | } 328 | 329 | return $result; 330 | } 331 | 332 | /** 333 | * Get foreign key join descriptor. 334 | * 335 | * @param \MwbExporter\Model\ForeignKey $fkey Foreign key 336 | * @param string $owningSide Is join for owning side or vice versa 337 | * @return array 338 | */ 339 | protected function getJoins(ForeignKey $fkey, $owningSide = true) 340 | { 341 | $joins = []; 342 | $lcols = $owningSide ? $fkey->getForeigns() : $fkey->getLocals(); 343 | $fcols = $owningSide ? $fkey->getLocals() : $fkey->getForeigns(); 344 | $onDelete = $this->getFormatter()->getDeleteRule($fkey->getParameters()->get('deleteRule')); 345 | for ($i = 0; $i < count($lcols); $i++) { 346 | $joins[] = [ 347 | 'name' => $lcols[$i]->getColumnName(), 348 | 'referencedColumnName' => $fcols[$i]->getColumnName(), 349 | 'nullable' => $lcols[$i]->getNullableValue(), 350 | 'onDelete' => $onDelete, 351 | ]; 352 | } 353 | 354 | return count($joins) > 1 ? ['joinColumns' => $this->convertJoinColumns($joins)] : ['joinColumn' => $joins[0]]; 355 | } 356 | 357 | /** 358 | * (non-PHPdoc) 359 | * @see \MwbExporter\Model\Base::getVars() 360 | */ 361 | protected function getVars() 362 | { 363 | return array_merge(parent::getVars(), ['%entity-fqcn%' => str_replace('\\', '.', $this->getModelNameAsFQCN())]); 364 | } 365 | } 366 | -------------------------------------------------------------------------------- /lib/ZF2InputFilterAnnotation/Configuration/EntityArrayCopy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Generate `getArrayCopy()` method for entity class. 33 | * 34 | * @author Toha 35 | * @config generateEntityGetArrayCopy 36 | * @label Generate entity getArrayCopy method 37 | */ 38 | class EntityArrayCopy extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/ZF2InputFilterAnnotation/Configuration/EntityPopulate.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | namespace MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Configuration; 28 | 29 | use MwbExporter\Configuration\Configuration; 30 | 31 | /** 32 | * Generate `populate()` method for entity class. 33 | * 34 | * @author Toha 35 | * @config generateEntityPopulate 36 | * @label Generate entity populate 37 | */ 38 | class EntityPopulate extends Configuration 39 | { 40 | protected function initialize() 41 | { 42 | $this->category = 'doctrineConfiguration'; 43 | $this->defaultValue = true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/ZF2InputFilterAnnotation/DatatypeConverter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * Copyright (c) 2013 WitteStier 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | 29 | namespace MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation; 30 | 31 | use MwbExporter\Formatter\Doctrine2\Annotation\DatatypeConverter as BaseDatatypeConverter; 32 | 33 | class DatatypeConverter extends BaseDatatypeConverter 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /lib/ZF2InputFilterAnnotation/Formatter.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * Copyright (c) 2013 WitteStier 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | 29 | namespace MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation; 30 | 31 | use MwbExporter\Configuration\Filename as FilenameConfiguration; 32 | use MwbExporter\Formatter\Doctrine2\Annotation\Formatter as BaseFormatter; 33 | use MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Configuration\EntityArrayCopy as EntityArrayCopyConfiguration; 34 | use MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Configuration\EntityPopulate as EntityPopulateConfiguration; 35 | use MwbExporter\Model\Base; 36 | 37 | class Formatter extends BaseFormatter 38 | { 39 | /** 40 | * (non-PHPdoc) 41 | * @see \MwbExporter\Formatter\Formatter::init() 42 | */ 43 | protected function init() 44 | { 45 | parent::init(); 46 | $this->getConfigurations() 47 | ->add(new EntityPopulateConfiguration()) 48 | ->add(new EntityArrayCopyConfiguration()) 49 | ->merge([ 50 | FilenameConfiguration::class => 'Entity/%entity%.%extension%', 51 | ], true) 52 | ; 53 | } 54 | 55 | /** 56 | * (non-PHPdoc) 57 | * @see \MwbExporter\Formatter\Formatter::createDatatypeConverter() 58 | */ 59 | protected function createDatatypeConverter() 60 | { 61 | return new DatatypeConverter(); 62 | } 63 | 64 | /** 65 | * (non-PHPdoc) 66 | * @see \MwbExporter\Formatter\Formatter::createTable() 67 | */ 68 | public function createTable(Base $parent, $node) 69 | { 70 | return new Model\Table($parent, $node); 71 | } 72 | 73 | /** 74 | * (non-PHPdoc) 75 | * @see \MwbExporter\Formatter\Formatter::getTitle() 76 | */ 77 | public function getTitle() 78 | { 79 | return 'Doctrine 2.0 Annotation with ZF2 input filter Classes'; 80 | } 81 | 82 | /** 83 | * (non-PHPdoc) 84 | * @see \MwbExporter\Formatter\Formatter::getFileExtension() 85 | */ 86 | public function getFileExtension() 87 | { 88 | return 'php'; 89 | } 90 | 91 | /** 92 | * Get configuration scope. 93 | * 94 | * @return string 95 | */ 96 | public static function getScope() 97 | { 98 | return 'Doctrine 2.0 Annotation ZF2 Input Filter'; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /lib/ZF2InputFilterAnnotation/Model/Table.php: -------------------------------------------------------------------------------- 1 | 7 | * Copyright (c) 2012-2024 Toha 8 | * Copyright (c) 2013 WitteStier 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | 29 | namespace MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Model; 30 | 31 | use MwbExporter\Formatter\Doctrine2\Annotation\Model\Table as BaseTable; 32 | use MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Configuration\EntityArrayCopy as EntityArrayCopyConfiguration; 33 | use MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Configuration\EntityPopulate as EntityPopulateConfiguration; 34 | use MwbExporter\Writer\WriterInterface; 35 | 36 | class Table extends BaseTable 37 | { 38 | protected function getClassImplementations() 39 | { 40 | return 'InputFilterAwareInterface'; 41 | } 42 | 43 | protected function includeUses() 44 | { 45 | parent::includeUses(); 46 | $this->usedClasses = array_merge($this->usedClasses, [ 47 | 'Zend\InputFilter\InputFilter', 48 | 'Zend\InputFilter\Factory as InputFactory', 49 | 'Zend\InputFilter\InputFilterAwareInterface', 50 | 'Zend\InputFilter\InputFilterInterface', 51 | ]); 52 | } 53 | 54 | public function writePreClassHandler(WriterInterface $writer) 55 | { 56 | $writer 57 | ->commentStart() 58 | ->write('Instance of InputFilterInterface.') 59 | ->write('') 60 | ->write('@var InputFilter') 61 | ->commentEnd() 62 | ->write('private $inputFilter;') 63 | ->write('') 64 | ; 65 | 66 | return $this; 67 | } 68 | 69 | public function writePostClassHandler(WriterInterface $writer) 70 | { 71 | $this->writeInputFilter($writer); 72 | if ($this->getConfig(EntityPopulateConfiguration::class)->getValue()) { 73 | $this->writePopulate($writer); 74 | } 75 | if ($this->getConfig(EntityArrayCopyConfiguration::class)->getValue()) { 76 | $this->writeGetArrayCopy($writer); 77 | } 78 | 79 | return $this; 80 | } 81 | 82 | /** 83 | * Write \Zend\InputFilter\InputFilterInterface methods. 84 | * http://framework.zend.com/manual/2.1/en/modules/zend.input-filter.intro.html 85 | * 86 | * @param \MwbExporter\Writer\WriterInterface $writer 87 | * @return \MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Model\Table 88 | */ 89 | public function writeInputFilter(WriterInterface $writer) 90 | { 91 | $writer 92 | ->commentStart() 93 | ->write('Not used, Only defined to be compatible with InputFilterAwareInterface.') 94 | ->write('') 95 | ->write('@param \Zend\InputFilter\InputFilterInterface $inputFilter') 96 | ->write('@throws \Exception') 97 | ->commentEnd() 98 | ->write('public function setInputFilter(InputFilterInterface $inputFilter)') 99 | ->write('{') 100 | ->indent() 101 | ->write('throw new \Exception("Not used.");') 102 | ->outdent() 103 | ->write('}') 104 | ->write('') 105 | ->commentStart() 106 | ->write('Return a for this entity configured input filter instance.') 107 | ->write('') 108 | ->write('@return InputFilterInterface') 109 | ->commentEnd() 110 | ->write('public function getInputFilter()') 111 | ->write('{') 112 | ->indent() 113 | ->write('if ($this->inputFilter instanceof InputFilterInterface) {') 114 | ->indent() 115 | ->write('return $this->inputFilter;') 116 | ->outdent() 117 | ->write('}') 118 | ->write('$factory = new InputFactory();') 119 | ->write('$filters = [') 120 | ->indent() 121 | ->writeCallback(function(WriterInterface $writer, ?Table $_this = null) { 122 | $_this->writeInputFilterColumns($writer); 123 | }) 124 | ->outdent() 125 | ->write('];') 126 | ->write('$this->inputFilter = $factory->createInputFilter($filters);') 127 | ->write('') 128 | ->write('return $this->inputFilter;') 129 | ->outdent() 130 | ->write('}') 131 | ->write('') 132 | ; 133 | 134 | return $this; 135 | } 136 | 137 | public function writeInputFilterColumns(WriterInterface $writer) 138 | { 139 | foreach ($this->getColumns() as $column) { 140 | // by type 141 | switch ($this->getFormatter()->getDatatypeConverter()->getDataType($column->getColumnType())) { 142 | case 'string': 143 | $s_filters = '[ 144 | [\'name\' => \'Zend\Filter\StripTags\'], 145 | [\'name\' => \'Zend\Filter\StringTrim\'], 146 | ]'; 147 | $s_validators = sprintf('[ 148 | [ 149 | \'name\' => \'Zend\Validator\StringLength\', 150 | \'options\' => [ 151 | \'encoding\' => \'UTF-8\', 152 | \'min\' => %s, 153 | \'max\' => ' . $column->getLength() . ' 154 | ], 155 | ], 156 | ]', $column->isNotNull() ? '1' : '0'); 157 | break; 158 | case 'smallint': 159 | case 'integer': 160 | $s_filters = '[ 161 | [\'name\' => \'Zend\Filter\ToInt\'], 162 | ]'; 163 | $s_validators = '[ 164 | [\'name\' => \'Zend\I18n\Validator\IsInt\'], 165 | ]'; 166 | break; 167 | case 'boolean': 168 | $s_filters = '[ 169 | [\'name\' => \'Zend\Filter\Boolean\'], 170 | ]'; 171 | $s_validators = '[]'; 172 | break; 173 | case 'datetime': 174 | $s_filters = '[]'; 175 | $s_validators = '[]'; 176 | break; 177 | case 'float': 178 | $s_filters = '[ 179 | [\'name\' => \'Zend\I18n\Filter\NumberFormat\'], 180 | ]'; 181 | $s_validators = '[ 182 | [\'name\' => \'Zend\I18n\Validator\IsFloat\'], 183 | ]'; 184 | break; 185 | case 'decimal': 186 | $s_filters = '[ 187 | [\'name\' => \'Zend\Filter\Digits\'], 188 | ]'; 189 | $s_validators = '[ 190 | [\'name\' => \'Zend\Validator\Digits\'], 191 | ]'; 192 | break; 193 | case 'text': 194 | $s_filters = '[ 195 | ]'; 196 | if ($column->getLength() > 0) { 197 | $s_validators = sprintf('[ 198 | [ 199 | \'name\' => \'Zend\Validator\StringLength\', 200 | \'options\' => [ 201 | \'encoding\' => \'UTF-8\', 202 | \'min\' => %s, 203 | \'max\' => ' . $column->getLength() . ' 204 | ], 205 | ], 206 | ]', $column->isNotNull() ? '1' : '0'); 207 | } else { 208 | $s_validators = '[]'; 209 | } 210 | break; 211 | default: 212 | $s_filters = '[]'; 213 | $s_validators = '[]'; 214 | break; 215 | } 216 | 217 | // by name 218 | if (strstr($column->getColumnName(), 'phone') or strstr($column->getColumnName(), '_tel')) { 219 | $s_validators = '[ 220 | [\'name\' => \'Zend\I18n\Validator\PhoneNumber\'], 221 | ]'; 222 | } elseif (strstr($column->getColumnName(), 'email')) { 223 | $s_validators = '[ 224 | [\'name\' => \'Zend\Validator\EmailAddress\'], 225 | ]'; 226 | } elseif (strstr($column->getColumnName(), 'postcode') or strstr($column->getColumnName(), '_zip')) { 227 | $s_validators = '[ 228 | [\'name\' => \'Zend\I18n\Validator\PostCode\'], 229 | ]'; 230 | } 231 | 232 | $writer 233 | ->write('[') 234 | ->indent() 235 | ->write('\'name\' => \'%s\',', $column->getColumnName()) 236 | ->write('\'required\' => %s,', $column->isNotNull() && !$column->isPrimary() ? 'true' : 'false') 237 | ->write('\'filters\' => %s,', $s_filters) 238 | ->write('\'validators\' => %s,', $s_validators) 239 | ->outdent() 240 | ->write('],') 241 | ; 242 | } 243 | 244 | return $this; 245 | } 246 | 247 | /** 248 | * Write entity populate method. 249 | * 250 | * @see \Zend\Stdlib\Hydrator\ArraySerializable::extract() 251 | * @param \MwbExporter\Writer\WriterInterface $writer 252 | * @return \MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Model\Table 253 | */ 254 | public function writePopulate(WriterInterface $writer) 255 | { 256 | $writer 257 | ->commentStart() 258 | ->write('Populate entity with the given data.') 259 | ->write('The set* method will be used to set the data.') 260 | ->write('') 261 | ->write('@param array $data') 262 | ->write('@return boolean') 263 | ->commentEnd() 264 | ->write('public function populate(array $data = [])') 265 | ->write('{') 266 | ->indent() 267 | ->write('foreach ($data as $field => $value) {') 268 | ->indent() 269 | ->write('$setter = sprintf(\'set%s\', ucfirst(') 270 | ->indent() 271 | ->write('str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $field)))') 272 | ->outdent() 273 | ->write('));') 274 | ->write('if (method_exists($this, $setter)) {') 275 | ->indent() 276 | ->write('$this->{$setter}($value);') 277 | ->outdent() 278 | ->write('}') 279 | ->outdent() 280 | ->write('}') 281 | ->write('') 282 | ->write('return true;') 283 | ->outdent() 284 | ->write('}') 285 | ->write('') 286 | ; 287 | 288 | return $this; 289 | } 290 | 291 | /** 292 | * Write getArrayCopy method. 293 | * 294 | * @see \Zend\Stdlib\Hydrator\ArraySerializable::hydrate() 295 | * @param \MwbExporter\Writer\WriterInterface $writer 296 | * @return \MwbExporter\Formatter\Doctrine2\ZF2InputFilterAnnotation\Model\Table 297 | */ 298 | public function writeGetArrayCopy(WriterInterface $writer) 299 | { 300 | $columns = $this->getColumns(); 301 | $relations = $this->getTableRelations(); 302 | 303 | $writer 304 | ->commentStart() 305 | ->write('Return a array with all fields and data.') 306 | ->write('Default the relations will be ignored.') 307 | ->write('') 308 | ->write('@param array $fields') 309 | ->write('@return array') 310 | ->commentEnd() 311 | ->write('public function getArrayCopy(array $fields = [])') 312 | ->write('{') 313 | ->indent() 314 | ->write('$dataFields = [%s];', implode(', ', array_map(function($column) { 315 | return sprintf('\'%s\'', $column); 316 | }, $columns->getColumnNames()))) 317 | ->write('$relationFields = [%s];', implode(', ', array_map(function($relation) { 318 | return sprintf('\'%s\'', lcfirst($relation->getReferencedTable()->getModelName())); 319 | }, $relations))) 320 | ->write('$copiedFields = [];') 321 | ->write('foreach ($relationFields as $relationField) {') 322 | ->indent() 323 | ->write('$map = null;') 324 | ->write('if (array_key_exists($relationField, $fields)) {') 325 | ->indent() 326 | ->write('$map = $fields[$relationField];') 327 | ->write('$fields[] = $relationField;') 328 | ->write('unset($fields[$relationField]);') 329 | ->outdent() 330 | ->write('}') 331 | ->write('if (!in_array($relationField, $fields)) {') 332 | ->indent() 333 | ->write('continue;') 334 | ->outdent() 335 | ->write('}') 336 | ->write('$getter = sprintf(\'get%s\', ucfirst(str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $relationField)))));') 337 | ->write('$relationEntity = $this->{$getter}();') 338 | ->write('$copiedFields[$relationField] = (!is_null($map))') 339 | ->indent() 340 | ->write('? $relationEntity->getArrayCopy($map)') 341 | ->write(': $relationEntity->getArrayCopy();') 342 | ->outdent() 343 | ->write('$fields = array_diff($fields, [$relationField]);') 344 | ->outdent() 345 | ->write('}') 346 | ->write('foreach ($dataFields as $dataField) {') 347 | ->indent() 348 | ->write('if (!in_array($dataField, $fields) && !empty($fields)) {') 349 | ->indent() 350 | ->write('continue;') 351 | ->outdent() 352 | ->write('}') 353 | ->write('$getter = sprintf(\'get%s\', ucfirst(str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $dataField)))));') 354 | ->write('$copiedFields[$dataField] = $this->{$getter}();') 355 | ->outdent() 356 | ->write('}') 357 | ->write('') 358 | ->write('return $copiedFields;') 359 | ->outdent() 360 | ->write('}') 361 | ->write('') 362 | ; 363 | 364 | return $this; 365 | } 366 | } 367 | --------------------------------------------------------------------------------