From 2b8f7dc1d293fd120d5f89bfca3b56c79c5dd216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Wed, 24 Jan 2018 17:24:46 +0900 Subject: [PATCH] Added a model generator. --- app/Providers/AppServiceProvider.php | 4 +- composer.json | 1 + composer.lock | 409 ++++++++++++++++++++++++++- config/models.php | 296 +++++++++++++++++++ 4 files changed, 708 insertions(+), 2 deletions(-) create mode 100644 config/models.php diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 35471f6..530a2b2 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -23,6 +23,8 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - // + if ($this->app->environment() == 'local') { + $this->app->register(\Reliese\Coders\CodersServiceProvider::class); + } } } diff --git a/composer.json b/composer.json index 0aa7120..320f405 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "fzaninotto/faker": "~1.4", "mockery/mockery": "~1.0", "phpunit/phpunit": "~6.0", + "reliese/laravel": "^0.0.13", "symfony/thanks": "^1.0" }, "autoload": { diff --git a/composer.lock b/composer.lock index cc3d478..3caa4ed 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "b7904d07d1e1765a0a199aa11d6301a3", + "content-hash": "9393b497bc1dfff9785b67f85b4d656d", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -2224,6 +2224,361 @@ } ], "packages-dev": [ + { + "name": "doctrine/annotations", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", + "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2017-12-06T07:11:42+00:00" + }, + { + "name": "doctrine/cache", + "version": "v1.7.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "b3217d58609e9c8e661cd41357a54d926c4a2a1a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/b3217d58609e9c8e661cd41357a54d926c4a2a1a", + "reference": "b3217d58609e9c8e661cd41357a54d926c4a2a1a", + "shasum": "" + }, + "require": { + "php": "~7.1" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^5.7", + "predis/predis": "~1.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2017-08-25T07:02:50+00:00" + }, + { + "name": "doctrine/collections", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "~0.1@dev", + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2017-07-22T10:37:32+00:00" + }, + { + "name": "doctrine/common", + "version": "v2.8.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "f68c297ce6455e8fd794aa8ffaf9fa458f6ade66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/f68c297ce6455e8fd794aa8ffaf9fa458f6ade66", + "reference": "f68c297ce6455e8fd794aa8ffaf9fa458f6ade66", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/cache": "1.*", + "doctrine/collections": "1.*", + "doctrine/inflector": "1.*", + "doctrine/lexer": "1.*", + "php": "~7.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2017-08-31T08:43:38+00:00" + }, + { + "name": "doctrine/dbal", + "version": "v2.6.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "e3eed9b1facbb0ced3a0995244843a189e7d1b13" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/e3eed9b1facbb0ced3a0995244843a189e7d1b13", + "reference": "e3eed9b1facbb0ced3a0995244843a189e7d1b13", + "shasum": "" + }, + "require": { + "doctrine/common": "^2.7.1", + "ext-pdo": "*", + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.4.6", + "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", + "symfony/console": "2.*||^3.0" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Abstraction Layer", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "dbal", + "persistence", + "queryobject" + ], + "time": "2017-11-19T13:38:54+00:00" + }, { "name": "doctrine/instantiator", "version": "1.1.0", @@ -3256,6 +3611,58 @@ ], "time": "2018-01-06T05:45:45+00:00" }, + { + "name": "reliese/laravel", + "version": "v0.0.13", + "source": { + "type": "git", + "url": "https://github.com/reliese/laravel.git", + "reference": "10075c5f5e67efba18d781216ff5a0ffa3fc2d7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reliese/laravel/zipball/10075c5f5e67efba18d781216ff5a0ffa3fc2d7f", + "reference": "10075c5f5e67efba18d781216ff5a0ffa3fc2d7f", + "shasum": "" + }, + "require": { + "doctrine/dbal": "~2.5", + "illuminate/console": "~5.1", + "illuminate/contracts": "~5.1", + "illuminate/database": "~5.1", + "illuminate/filesystem": "~5.1", + "illuminate/support": "~5.1", + "php": ">=5.6.4" + }, + "require-dev": { + "fzaninotto/faker": "~1.4", + "mockery/mockery": "0.9.*", + "phpunit/phpunit": "~5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Reliese\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Cristian Llanos", + "email": "cristianllanos@outlook.com" + } + ], + "description": "Reliese Components for Laravel Framework code generation.", + "homepage": "http://cristianllanos.com", + "keywords": [ + "laravel", + "reliese" + ], + "time": "2017-02-04T15:50:39+00:00" + }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", diff --git a/config/models.php b/config/models.php new file mode 100644 index 0000000..d3ef801 --- /dev/null +++ b/config/models.php @@ -0,0 +1,296 @@ + [ + + /* + |-------------------------------------------------------------------------- + | Model Files Location + |-------------------------------------------------------------------------- + | + | We need a location to store your new generated files. All files will be + | placed within this directory. When you turn on base files, they will + | be placed within a Base directory inside this location. + | + */ + + 'path' => app_path('Models'), + + /* + |-------------------------------------------------------------------------- + | Model Namespace + |-------------------------------------------------------------------------- + | + | Every generated model will belong to this namespace. It is suggested + | that this namespace should follow PSR-4 convention and be very + | similar to the path of your models defined above. + | + */ + + 'namespace' => 'App\Models', + + /* + |-------------------------------------------------------------------------- + | Parent Class + |-------------------------------------------------------------------------- + | + | All Eloquent models should inherit from Eloquent Model class. However, + | you can define a custom Eloquent model that suits your needs. + | As an example one custom model has been added for you which + | will allow you to create custom database castings. + | + */ + + 'parent' => Reliese\Database\Eloquent\Model::class, + + /* + |-------------------------------------------------------------------------- + | Traits + |-------------------------------------------------------------------------- + | + | Sometimes you may want to append certain traits to all your models. + | If that is what you need, you may list them bellow. + | As an example we have a BitBooleans trait which will treat MySQL bit + | data type as booleans. You might probably not need it, but it is + | an example of how you can customize your models. + | + */ + + 'use' => [ + // Reliese\Database\Eloquent\BitBooleans::class, + // Reliese\Database\Eloquent\BlamableBehavior::class, + ], + + /* + |-------------------------------------------------------------------------- + | Model Connection + |-------------------------------------------------------------------------- + | + | If you wish your models had appended the connection from which they + | were generated, you should set this value to true and your + | models will have the connection property filled. + | + */ + + 'connection' => false, + + /* + |-------------------------------------------------------------------------- + | Timestamps + |-------------------------------------------------------------------------- + | + | If your tables have CREATED_AT and UPDATED_AT timestamps you may + | enable them and your models will fill their values as needed. + | You can also specify which fields should be treated as timestamps + | in case you don't follow the naming convention Eloquent uses. + | If your table doesn't have these fields, timestamps will be + | disabled for your model. + | + */ + + 'timestamps' => true, + + // 'timestamps' => [ + // 'enabled' => true, + // 'fields' => [ + // 'CREATED_AT' => 'created_at', + // 'UPDATED_AT' => 'updated_at', + // ] + // ], + + /* + |-------------------------------------------------------------------------- + | Soft Deletes + |-------------------------------------------------------------------------- + | + | If your tables support soft deletes with a DELETED_AT attribute, + | you can enable them here. You can also specify which field + | should be treated as a soft delete attribute in case you + | don't follow the naming convention Eloquent uses. + | If your table doesn't have this field, soft deletes will be + | disabled for your model. + | + */ + + 'soft_deletes' => true, + + // 'soft_deletes' => [ + // 'enabled' => true, + // 'field' => 'deleted_at', + // ], + + /* + |-------------------------------------------------------------------------- + | Date Format + |-------------------------------------------------------------------------- + | + | Here you may define your models' date format. The following format + | is the default format Eloquent uses. You won't see it in your + | models unless you change it to a more convenient value. + | + */ + + 'date_format' => 'Y-m-d H:i:s', + + /* + |-------------------------------------------------------------------------- + | Pagination + |-------------------------------------------------------------------------- + | + | Here you may define how many models Eloquent should display when + | paginating them. The default number is 15, so you might not + | see this number in your models unless you change it. + | + */ + + 'per_page' => 15, + + /* + |-------------------------------------------------------------------------- + | Base Files + |-------------------------------------------------------------------------- + | + | By default, your models will be generated in your models path, but + | when you generate them again they will be replaced by new ones. + | You may want to customize your models and, at the same time, be + | able to generate them as your tables change. For that, you + | can enable base files. These files will be replaced whenever + | you generate them, but your customized files will not be touched. + | + */ + + 'base_files' => false, + + /* + |-------------------------------------------------------------------------- + | Snake Attributes + |-------------------------------------------------------------------------- + | + | Eloquent treats your model attributes as snake cased attributes, but + | if you have camel-cased fields in your database you can disable + | that behaviour and use camel case attributes in your models. + | + */ + + 'snake_attributes' => true, + + /* + |-------------------------------------------------------------------------- + | Qualified Table Names + |-------------------------------------------------------------------------- + | + | If some of your tables have cross-database relationships (probably in + | MySQL), you can make sure your models take into account their + | respective database schema. + | + */ + + 'qualified_tables' => false, + + /* + |-------------------------------------------------------------------------- + | Hidden Attributes + |-------------------------------------------------------------------------- + | + | When casting your models into arrays or json, the need to hide some + | attributes sometimes arise. If your tables have some fields you + | want to hide, you can define them bellow. + | Some fields were defined for you. + | + */ + + 'hidden' => [ + '*secret*', '*password', '*token', + ], + + /* + |-------------------------------------------------------------------------- + | Mass Assignment Guarded Attributes + |-------------------------------------------------------------------------- + | + | You may want to protect some fields from mass assignment. You can + | define them bellow. Some fields were defined for you. + | Your fillable attributes will be those which are not in the list + | excluding your models' primary keys. + | + */ + + 'guarded' => [ + // 'created_by', 'updated_by' + ], + + /* + |-------------------------------------------------------------------------- + | Casts + |-------------------------------------------------------------------------- + | + | You may want to specify which of your table fields should be casted as + | something different than a string. For instance, you may want a + | text field be casted as an array or and object. + | + | You may define column patterns which will be casted using the value + | assigned. We have defined some fields for you. Feel free to + | modify them to fit your needs. + | + */ + + 'casts' => [ + '*_json' => 'json', + ], + + /* + |-------------------------------------------------------------------------- + | Excluded Tables + |-------------------------------------------------------------------------- + | + | When performing the generation of models you may want to skip some of + | them, because you don't want a model for them or any other reason. + | You can define those tables bellow. The migrations table was + | filled for you, since you may not want a model for it. + | + */ + + 'except' => [ + 'migrations', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Database Specifics + |-------------------------------------------------------------------------- + | + | In this section you may define the default configuration for each model + | that will be generated from a specific database. You can also nest + | table specific configurations. + | These values will override those defined in the section above. + | + */ + + // 'shop' => [ + // 'path' => app_path(), + // 'namespace' => 'App', + // 'snake_attributes' => false, + // 'qualified_tables' => true, + // 'use' => [ + // Reliese\Database\Eloquent\BitBooleans::class, + // ], + // 'except' => ['migrations'], + // // Table Specifics Bellow: + // 'user' => [ + // // Don't use any default trait + // 'use' => [], + // ] + // ], +];