From 7a5a74f16e99281d5cdf49a65b010325978d7ada Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 25 Jul 2021 00:38:13 -0500 Subject: [PATCH 01/16] =?UTF-8?q?=F0=9F=94=A7=20lets=20try=20supporting=20?= =?UTF-8?q?points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index fd162dc..9ec1be8 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -5,6 +5,7 @@ use Exception; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use ReflectionClass; use ReflectionMethod; @@ -17,7 +18,6 @@ class ModelInterface { - public array $mappings = [ 'bigint' => 'number', 'int' => 'number', @@ -28,8 +28,16 @@ class ModelInterface 'bool' => 'boolean', 'boolean' => 'boolean', 'json' => '[]', + 'point' => 'Point', ]; + + public function __construct() + { + DB::getDoctrineSchemaManager() + ->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point'); + } + /** * Combine all instances together * @return string From f9ea7e39104445fb4d87fb93deaa87808d8cc346 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 25 Jul 2021 00:38:53 -0500 Subject: [PATCH 02/16] =?UTF-8?q?=F0=9F=94=A7=20lets=20try=20supporting=20?= =?UTF-8?q?points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 46a917c..e5977d0 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -242,10 +242,7 @@ private function getColumns(Model $model): array */ private function getColumnList(Model $model): array { - try { - return $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable()); - } catch (Exception $exception) { - } + return $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable()); } /** From 2ff69c85a3a0d5f0755ede2ea644ace2862c7103 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 25 Jul 2021 00:46:22 -0500 Subject: [PATCH 03/16] =?UTF-8?q?=F0=9F=9A=A7=20more=20attempts=20for=20a?= =?UTF-8?q?=20point=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +- composer.lock | 785 +++++++++++++++++++++++++++++++++++------ src/ModelInterface.php | 3 + 3 files changed, 676 insertions(+), 115 deletions(-) diff --git a/composer.json b/composer.json index 9e44ad5..a83fc78 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "type": "library", "require": { "php": "^8.0", - "illuminate/support": "8.*" + "illuminate/support": "8.*", + "vinyvicente/doctrine-point-type": "^2.3" }, "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index 76243d2..6cfc001 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,352 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "266436de886e7cf3e61d4e6752e3f21c", + "content-hash": "6aaa8bdb770c785ef3f534903164e725", "packages": [ + { + "name": "doctrine/cache", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "331b4d5dbaeab3827976273e9356b3b453c300ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/331b4d5dbaeab3827976273e9356b3b453c300ce", + "reference": "331b4d5dbaeab3827976273e9356b3b453c300ce", + "shasum": "" + }, + "require": { + "php": "~7.1 || ^8.0" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "cache/integration-tests": "dev-master", + "doctrine/coding-standard": "^8.0", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "predis/predis": "~1.0", + "psr/cache": "^1.0 || ^2.0 || ^3.0", + "symfony/cache": "^4.4 || ^5.2 || ^6.0@dev", + "symfony/var-exporter": "^4.4 || ^5.2 || ^6.0@dev" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.", + "homepage": "https://www.doctrine-project.org/projects/cache.html", + "keywords": [ + "abstraction", + "apcu", + "cache", + "caching", + "couchdb", + "memcached", + "php", + "redis", + "xcache" + ], + "support": { + "issues": "https://github.com/doctrine/cache/issues", + "source": "https://github.com/doctrine/cache/tree/2.1.1" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache", + "type": "tidelift" + } + ], + "time": "2021-07-17T14:49:29+00:00" + }, + { + "name": "doctrine/dbal", + "version": "2.13.2", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "8dd39d2ead4409ce652fd4f02621060f009ea5e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/8dd39d2ead4409ce652fd4f02621060f009ea5e4", + "reference": "8dd39d2ead4409ce652fd4f02621060f009ea5e4", + "shasum": "" + }, + "require": { + "doctrine/cache": "^1.0|^2.0", + "doctrine/deprecations": "^0.5.3", + "doctrine/event-manager": "^1.0", + "ext-pdo": "*", + "php": "^7.1 || ^8" + }, + "require-dev": { + "doctrine/coding-standard": "9.0.0", + "jetbrains/phpstorm-stubs": "2020.2", + "phpstan/phpstan": "0.12.81", + "phpunit/phpunit": "^7.5.20|^8.5|9.5.5", + "squizlabs/php_codesniffer": "3.6.0", + "symfony/cache": "^4.4", + "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", + "vimeo/psalm": "4.6.4" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\DBAL\\": "lib/Doctrine/DBAL" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.", + "homepage": "https://www.doctrine-project.org/projects/dbal.html", + "keywords": [ + "abstraction", + "database", + "db2", + "dbal", + "mariadb", + "mssql", + "mysql", + "oci8", + "oracle", + "pdo", + "pgsql", + "postgresql", + "queryobject", + "sasql", + "sql", + "sqlanywhere", + "sqlite", + "sqlserver", + "sqlsrv" + ], + "support": { + "issues": "https://github.com/doctrine/dbal/issues", + "source": "https://github.com/doctrine/dbal/tree/2.13.2" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal", + "type": "tidelift" + } + ], + "time": "2021-06-18T21:48:39+00:00" + }, + { + "name": "doctrine/deprecations", + "version": "v0.5.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "9504165960a1f83cc1480e2be1dd0a0478561314" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/9504165960a1f83cc1480e2be1dd0a0478561314", + "reference": "9504165960a1f83cc1480e2be1dd0a0478561314", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0|^7.0|^8.0", + "phpunit/phpunit": "^7.0|^8.0|^9.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/v0.5.3" + }, + "time": "2021-03-21T12:59:47+00:00" + }, + { + "name": "doctrine/event-manager", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/event-manager.git", + "reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/41370af6a30faa9dc0368c4a6814d596e81aba7f", + "reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/common": "<2.9@dev" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" + } + ], + "description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.", + "homepage": "https://www.doctrine-project.org/projects/event-manager.html", + "keywords": [ + "event", + "event dispatcher", + "event manager", + "event system", + "events" + ], + "support": { + "issues": "https://github.com/doctrine/event-manager/issues", + "source": "https://github.com/doctrine/event-manager/tree/1.1.x" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager", + "type": "tidelift" + } + ], + "time": "2020-05-29T18:28:51+00:00" + }, { "name": "doctrine/inflector", "version": "2.0.3", @@ -443,48 +787,176 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "support": { - "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.1" - }, - "time": "2021-03-05T17:36:06+00:00" + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/1.1.1" + }, + "time": "2021-03-05T17:36:06+00:00" + }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/master" + }, + "time": "2017-10-23T01:57:42+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", + "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-03-23T23:28:01+00:00" }, { - "name": "psr/simple-cache", - "version": "1.0.1", + "name": "symfony/polyfill-ctype", + "version": "v1.22.1", "source": { "type": "git", - "url": "https://github.com/php-fig/simple-cache.git", - "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", - "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { "psr-4": { - "Psr\\SimpleCache\\": "src/" - } + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -492,22 +964,40 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Common interfaces for simple caching", + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", "keywords": [ - "cache", - "caching", - "psr", - "psr-16", - "simple-cache" + "compatibility", + "ctype", + "polyfill", + "portable" ], "support": { - "source": "https://github.com/php-fig/simple-cache/tree/master" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" }, - "time": "2017-10-23T01:57:42+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -672,6 +1162,108 @@ ], "time": "2021-01-07T16:49:33+00:00" }, + { + "name": "symfony/serializer", + "version": "v5.3.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/serializer.git", + "reference": "96f6ff6582d1bf1bf08281b563a6c7c917efe6c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/serializer/zipball/96f6ff6582d1bf1bf08281b563a6c7c917efe6c1", + "reference": "96f6ff6582d1bf1bf08281b563a6c7c917efe6c1", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-php80": "^1.15" + }, + "conflict": { + "doctrine/annotations": "<1.12", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/dependency-injection": "<4.4", + "symfony/property-access": "<4.4", + "symfony/property-info": "<5.3", + "symfony/yaml": "<4.4" + }, + "require-dev": { + "doctrine/annotations": "^1.12", + "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", + "symfony/cache": "^4.4|^5.0", + "symfony/config": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/error-handler": "^4.4|^5.0", + "symfony/filesystem": "^4.4|^5.0", + "symfony/form": "^4.4|^5.0", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/mime": "^4.4|^5.0", + "symfony/property-access": "^4.4.9|^5.0.9", + "symfony/property-info": "^5.3", + "symfony/uid": "^5.1", + "symfony/validator": "^4.4|^5.0", + "symfony/var-dumper": "^4.4|^5.0", + "symfony/var-exporter": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0" + }, + "suggest": { + "psr/cache-implementation": "For using the metadata cache.", + "symfony/config": "For using the XML mapping loader.", + "symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.", + "symfony/property-access": "For using the ObjectNormalizer.", + "symfony/property-info": "To deserialize relations.", + "symfony/var-exporter": "For using the metadata compiler.", + "symfony/yaml": "For using the default YAML mapping loader." + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Serializer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/serializer/tree/v5.3.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-06-10T18:05:39+00:00" + }, { "name": "symfony/translation", "version": "v5.2.8", @@ -843,6 +1435,50 @@ ], "time": "2021-03-23T23:28:01+00:00" }, + { + "name": "vinyvicente/doctrine-point-type", + "version": "v2.3.0", + "source": { + "type": "git", + "url": "https://github.com/vinyvicente/doctrine-point-type.git", + "reference": "b15b10dc589810c7aef153b82a6c193226d29e35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vinyvicente/doctrine-point-type/zipball/b15b10dc589810c7aef153b82a6c193226d29e35", + "reference": "b15b10dc589810c7aef153b82a6c193226d29e35", + "shasum": "" + }, + "require": { + "doctrine/dbal": "^2.5", + "php": ">=7.2", + "symfony/serializer": "^5.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Viny\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Vinicius", + "email": "vinyvicente@gmail.com" + } + ], + "support": { + "issues": "https://github.com/vinyvicente/doctrine-point-type/issues", + "source": "https://github.com/vinyvicente/doctrine-point-type/tree/v2.3.0" + }, + "time": "2021-04-07T13:49:33+00:00" + }, { "name": "voku/portable-ascii", "version": "1.5.6", @@ -2160,85 +2796,6 @@ ], "time": "2021-05-16T13:07:46+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.22.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.22-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-01-07T16:49:33+00:00" - }, { "name": "symfony/polyfill-iconv", "version": "v1.22.1", diff --git a/src/ModelInterface.php b/src/ModelInterface.php index e5977d0..66bfba5 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -11,10 +11,12 @@ use ReflectionMethod; use ReflectionException; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Types\Type; use Illuminate\Container\Container; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; +use Viny\PointType; class ModelInterface { @@ -34,6 +36,7 @@ class ModelInterface public function __construct() { + Type::addType('point', PointType::class); DB::getDoctrineSchemaManager() ->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point'); } From 1901c233ef05a98e7a9bdba13cd84ebb5ac843e5 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 25 Jul 2021 04:29:05 -0500 Subject: [PATCH 04/16] =?UTF-8?q?=E2=9C=A8=20add=20type=20decimal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 66bfba5..4914501 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -26,6 +26,7 @@ class ModelInterface 'integer' => 'number', 'text' => 'string', 'string' => 'string', + 'decimal' => 'number', 'datetime' => 'Date', 'bool' => 'boolean', 'boolean' => 'boolean', From 741beeec9a625d83b269ba1a95db4a18b4fd20de Mon Sep 17 00:00:00 2001 From: kevin olson Date: Tue, 17 Aug 2021 21:00:48 -0500 Subject: [PATCH 05/16] =?UTF-8?q?=E2=9C=A8=20custom=20interface=20support?= =?UTF-8?q?=20take=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 22 ++++++++++++++++++++++ src/ModelInterface.php | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index a87a0bd..8ea2357 100644 --- a/readme.md +++ b/readme.md @@ -75,5 +75,27 @@ public function getFirstNameAttribute(): string // <- this } ``` +### Custom Interfaces +If you have custom interfaces you are using for your models you can specify them in a reserved `interfaces` array +For example for a custom `Point` interface in a `Location` model you can put this in the model +```php +public array $interfaces = [ + 'coordinate' => [ + 'name' => 'Point', + 'import' => "@/types/api", + ], +]; +``` + +And it should generate: + +```ts +import { Point } from '@/types/api' + +export interface Location { + // columns + coordinate: Point +} +``` diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 4914501..a844b93 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -34,6 +34,8 @@ class ModelInterface 'point' => 'Point', ]; + public array $imports = []; + public function __construct() { @@ -49,8 +51,8 @@ public function __construct() */ public function generate(): string { - $allCode = ''; $models = $this->getModels(); + $allCode = $this->getImports($models); foreach ($models as $model) { $interface = $this->getInterface(new $model()); $allCode .= $this->getCode($interface); @@ -58,6 +60,27 @@ public function generate(): string return $allCode; } + /** + * Generate a list of imports from specified interfaces + * @param Collection $models + * @return string + */ + private function getImports(Collection $models): string { + $code = ''; + $imports = []; + foreach ($models as $model) { + if ($interfaces = (new $model())->interfaces) { + foreach ($interfaces as $interface) { + $imports[$interface['import']][] = $interface['name']; + } + } + } + foreach ($imports as $import=>$names) { + $code .= "import { ". join(', ', array_unique($names)) . " } from '$import'\n"; + } + return $code; + } + /** * Build an interface from a model * @param Model $model @@ -128,7 +151,6 @@ public function getRelations(Model $model): array $type = (string) $reflection->getReturnType(); $code = file($reflection->getFileName())[$reflection->getEndLine()-2]; preg_match('/\((.*?)::class/', $code, $matches); - if (strstr($type, 'or')) ray($type); if ($matches && $matches[1]) { if ($type === 'Illuminate\Database\Eloquent\Relations\BelongsTo' || @@ -181,6 +203,12 @@ public function getMutators(Model $model): array $mutations = []; $mutators = $model->getMutatedAttributes(); foreach ($mutators as $mutator) { + + if (isset($model->interfaces) && isset($model->interfaces[$mutator])) { + $mutations[$mutator] = $model->interfaces[$mutator]['name']; + continue; + } + $method = 'get' . $this->camelize($mutator) . 'Attribute'; $reflection = new ReflectionMethod($model, $method); if (!$reflection->hasReturnType()) { @@ -219,10 +247,17 @@ private function getColumns(Model $model): array { $columns = []; foreach ($this->getColumnList($model) as $columnName) { + try { $column = $this->getColumn($model, $columnName); - if (!isset($this->mappings[$column->getType()->getName()])) { + if ($model->interfaces && $model->interfaces[$columnName]) { + if ($column->getNotnull()) { + $columns [ $columnName ] = $model->interfaces[ $columnName ][ 'name' ]; + } else { + $columns [ $columnName . '?' ] = $model->interfaces[ $columnName ][ 'name' ]; + } + } else if (!isset($this->mappings[$column->getType()->getName()])) { throw new Exception('Unknown type found: ' . $column->getType()->getName()); } else { if ($column->getNotnull()) { From 905ac0d0597700d69de342b1dfdf0ad4b0f58b6d Mon Sep 17 00:00:00 2001 From: kevin olson Date: Tue, 17 Aug 2021 21:01:30 -0500 Subject: [PATCH 06/16] =?UTF-8?q?=F0=9F=8E=A8=20readme=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 8ea2357..5808e34 100644 --- a/readme.md +++ b/readme.md @@ -99,3 +99,5 @@ export interface Location { coordinate: Point } ``` + +This will override all columns or mutators From ac696f204f3abafb5e61ff64ff3e66ec789b9619 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Tue, 17 Aug 2021 21:07:12 -0500 Subject: [PATCH 07/16] =?UTF-8?q?=F0=9F=90=9B=20remove=20that=20annoying?= =?UTF-8?q?=20extra=20br?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index a844b93..0d0d1d5 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -57,7 +57,7 @@ public function generate(): string $interface = $this->getInterface(new $model()); $allCode .= $this->getCode($interface); } - return $allCode; + return substr($allCode, 0, strrpos($allCode, "\n")); } /** @@ -112,19 +112,19 @@ private function getCode(TypescriptInterface $interface): string if (count($interface->columns) > 0) { $code .= " // columns\n"; foreach ($interface->columns as $key => $value) { - $code .= " {$key}: {$value}\n"; + $code .= " $key: $value\n"; } } if (count($interface->mutators) > 0) { $code .= " // mutators\n"; foreach ($interface->mutators as $key => $value) { - $code .= " {$key}: {$value}\n"; + $code .= " $key: $value\n"; } } if (count($interface->relations) > 0) { $code .= " // relations\n"; foreach ($interface->relations as $key => $value) { - $code .= " {$key}: {$value}\n"; + $code .= " $key: $value\n"; } } $code .= "}\n"; From 052775a3ad3afaf191073e8ac37384be6ada9fb8 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Tue, 17 Aug 2021 22:08:14 -0500 Subject: [PATCH 08/16] =?UTF-8?q?=F0=9F=90=9B=20fix=20for=20not=20properly?= =?UTF-8?q?=20continuing=20column=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 0d0d1d5..61f92a3 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -250,15 +250,16 @@ private function getColumns(Model $model): array try { $column = $this->getColumn($model, $columnName); - - if ($model->interfaces && $model->interfaces[$columnName]) { + if (isset($model->interfaces) && isset($model->interfaces[$columnName])) { if ($column->getNotnull()) { $columns [ $columnName ] = $model->interfaces[ $columnName ][ 'name' ]; } else { $columns [ $columnName . '?' ] = $model->interfaces[ $columnName ][ 'name' ]; } - } else if (!isset($this->mappings[$column->getType()->getName()])) { - throw new Exception('Unknown type found: ' . $column->getType()->getName()); + continue; + } + if (!isset($this->mappings[$column->getType()->getName()])) { + throw new Exception('Unknown type found: ' . $column->getType()->getName()); } else { if ($column->getNotnull()) { $columns[ $columnName ] = $this->mappings[ $column->getType()->getName() ]; From ca301fa88b16d861e77624cc900b0ea27e575f56 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 22 Aug 2021 05:26:11 -0500 Subject: [PATCH 09/16] =?UTF-8?q?=E2=9C=A8=20make=20sure=20to=20add=20any?= =?UTF-8?q?=20remaining=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 45 +++++++++++++++++++++++++++++++++++-- src/TypescriptInterface.php | 1 + 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 61f92a3..ea099e1 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -31,6 +31,7 @@ class ModelInterface 'bool' => 'boolean', 'boolean' => 'boolean', 'json' => '[]', + 'array' => 'string[]', 'point' => 'Point', ]; @@ -93,14 +94,17 @@ private function getInterface(Model $model): TypescriptInterface $columns = $this->getColumns($model); $mutators = $this->getMutators($model); $relations = $this->getRelations($model); + $interfaces = $this->getInterfaces($model, $columns, $mutators, $relations); return new TypescriptInterface( name: (new ReflectionClass($model))->getShortName(), columns: $columns, mutators: $mutators, relations: $relations, + interfaces: $interfaces, ); } + /** * Build TS code from an interface * @param TypescriptInterface $interface @@ -127,6 +131,12 @@ private function getCode(TypescriptInterface $interface): string $code .= " $key: $value\n"; } } + if (count($interface->interfaces) > 0) { + $code .= " // interfaces\n"; + foreach ($interface->interfaces as $key => $value) { + $code .= " $key: $value\n"; + } + } $code .= "}\n"; $plural = Str::plural($interface->name); $code .= "export type $plural = Array<{$interface->name}>\n\n"; @@ -192,6 +202,37 @@ public function getRelations(Model $model): array return $relations; } + /** + * Return any other remaining interfaces + * + * @param Model $model + * @param array $columns + * @param array $mutators + * @param array $relations + * @return array + */ + private function getInterfaces(Model $model, array $columns, array $mutators, array $relations): array + { + if (!isset($model->interfaces)) { + return []; + } + $interfaces = []; + foreach ($model->interfaces as $key=>$interface) { + if (array_key_exists($key, $columns)) { + continue; + } + if (array_key_exists($key, $mutators)) { + continue; + } + if (array_key_exists($key, $relations)) { + continue; + } + $interfaces[$key] = $interface['name']; + } + return $interfaces; + } + + /** * Find and map our get mutators * @param Model $model @@ -285,8 +326,8 @@ private function getColumnList(Model $model): array return $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable()); } -/** - * Get column details + /** + * Get column details * @param Model $model * @param string $column * @return Column diff --git a/src/TypescriptInterface.php b/src/TypescriptInterface.php index d793268..18e277f 100644 --- a/src/TypescriptInterface.php +++ b/src/TypescriptInterface.php @@ -9,6 +9,7 @@ public function __construct( public array $columns, public array $mutators, public array $relations, + public array $interfaces, ) { } } From 04e0c28d2a68a2ce587e677502deee1391ca1504 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 22 Aug 2021 05:48:44 -0500 Subject: [PATCH 10/16] =?UTF-8?q?=F0=9F=90=9B=20interface=20bug=20with=20n?= =?UTF-8?q?ulls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index ea099e1..9a31e0a 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -218,13 +218,13 @@ private function getInterfaces(Model $model, array $columns, array $mutators, ar } $interfaces = []; foreach ($model->interfaces as $key=>$interface) { - if (array_key_exists($key, $columns)) { + if (array_key_exists($key, $columns) || array_key_exists($key . '?', $columns)) { continue; } - if (array_key_exists($key, $mutators)) { + if (array_key_exists($key, $mutators) || array_key_exists($key . '?', $mutators)) { continue; } - if (array_key_exists($key, $relations)) { + if (array_key_exists($key, $relations) || array_key_exists($key . '?', $relations)) { continue; } $interfaces[$key] = $interface['name']; From c15ff081470ec0d6ac3327393428d6b075a6b2f8 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Wed, 1 Sep 2021 20:00:31 -0500 Subject: [PATCH 11/16] =?UTF-8?q?=E2=9C=A8=20ability=20to=20stack=20interf?= =?UTF-8?q?aces=20onto=20relations=20to=20give=20pivots=20-=20allow=20null?= =?UTF-8?q?able=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 9a31e0a..563fb56 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -158,6 +158,18 @@ public function getRelations(Model $model): array foreach ($methods as $method) { $reflection = new ReflectionMethod($model, $method); if ($reflection->hasReturnType()) { + if ($model->interfaces) { + foreach ($model->interfaces as $key => $value) { + if ($key === $method) { + if (isset($value['nullable']) && $value['nullable'] === true) { + $relations[ $key . '?' ] = $value[ 'name' ]; + } else { + $relations[ $key ] = $value[ 'name' ]; + } + continue 2; + } + } + } $type = (string) $reflection->getReturnType(); $code = file($reflection->getFileName())[$reflection->getEndLine()-2]; preg_match('/\((.*?)::class/', $code, $matches); From 7c659992391db604e94ad85b32c285224fa723f5 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Wed, 1 Sep 2021 20:09:28 -0500 Subject: [PATCH 12/16] =?UTF-8?q?=F0=9F=8E=A8=20readme=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5808e34..870e105 100644 --- a/readme.md +++ b/readme.md @@ -100,4 +100,16 @@ export interface Location { } ``` -This will override all columns or mutators +This will override all columns, mutators and relationships + +You can also specify an interface is nullable: + +```php + public array $interfaces = [ + 'choices' => [ + 'name' => 'ChoicesWithPivot', + 'import' => '@/types/api', + 'nullable' => true, + ], + ]; +``` From d0e23695728fbb5f1d873909eba68defebd1128b Mon Sep 17 00:00:00 2001 From: kevin olson Date: Thu, 21 Oct 2021 15:40:14 -0500 Subject: [PATCH 13/16] =?UTF-8?q?=E2=9C=A8=20support=20for=20global=20with?= =?UTF-8?q?=20models=20namesapce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Commands/ModelTyper.php | 6 +++-- src/ModelInterface.php | 44 ++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Commands/ModelTyper.php b/src/Commands/ModelTyper.php index e3db1ed..99b3ed8 100644 --- a/src/Commands/ModelTyper.php +++ b/src/Commands/ModelTyper.php @@ -4,6 +4,7 @@ use FumeApp\ModelTyper\ModelInterface; use Illuminate\Console\Command; +use ReflectionException; class ModelTyper extends Command { @@ -12,7 +13,7 @@ class ModelTyper extends Command * * @var string */ - protected $signature = 'model:typer'; + protected $signature = 'model:typer {--global}'; /** * The console command description. @@ -35,10 +36,11 @@ public function __construct() * Execute the console command. * * @return int + * @throws ReflectionException */ public function handle() { - echo (new ModelInterface())->generate(); + echo (new ModelInterface($this->option('global') !== null))->generate(); return 0; } } diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 563fb56..f7022e8 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -37,8 +37,12 @@ class ModelInterface public array $imports = []; + private string $space = ''; - public function __construct() + + public function __construct( + private bool $global = false, + ) { Type::addType('point', PointType::class); DB::getDoctrineSchemaManager() @@ -52,12 +56,20 @@ public function __construct() */ public function generate(): string { + $allCode = ''; + if ($this->global) { + $allCode = "export {}\ndeclare global {\n export namespace models {\n\n"; + $this->space = ' '; + } $models = $this->getModels(); - $allCode = $this->getImports($models); + $allCode .= $this->getImports($models); foreach ($models as $model) { $interface = $this->getInterface(new $model()); $allCode .= $this->getCode($interface); } + if ($this->global) { + $allCode .= " }\n}"; + } return substr($allCode, 0, strrpos($allCode, "\n")); } @@ -72,12 +84,14 @@ private function getImports(Collection $models): string { foreach ($models as $model) { if ($interfaces = (new $model())->interfaces) { foreach ($interfaces as $interface) { - $imports[$interface['import']][] = $interface['name']; + if (isset($interfaces['import'])) { + $imports[ $interface[ 'import' ] ][] = $interface[ 'name' ]; + } } } } foreach ($imports as $import=>$names) { - $code .= "import { ". join(', ', array_unique($names)) . " } from '$import'\n"; + $code .= "{$this->space}import { " . join(', ', array_unique($names)) . " } from '$import'\n"; } return $code; } @@ -112,34 +126,34 @@ interfaces: $interfaces, */ private function getCode(TypescriptInterface $interface): string { - $code = "export interface {$interface->name} {\n"; + $code = "{$this->space}export interface {$interface->name} {\n"; if (count($interface->columns) > 0) { - $code .= " // columns\n"; + $code .= "{$this->space} // columns\n"; foreach ($interface->columns as $key => $value) { - $code .= " $key: $value\n"; + $code .= "{$this->space} $key: $value\n"; } } if (count($interface->mutators) > 0) { - $code .= " // mutators\n"; + $code .= "{$this->space} // mutators\n"; foreach ($interface->mutators as $key => $value) { - $code .= " $key: $value\n"; + $code .= "{$this->space} $key: $value\n"; } } if (count($interface->relations) > 0) { - $code .= " // relations\n"; + $code .= "{$this->space} // relations\n"; foreach ($interface->relations as $key => $value) { - $code .= " $key: $value\n"; + $code .= "{$this->space} $key: $value\n"; } } if (count($interface->interfaces) > 0) { - $code .= " // interfaces\n"; + $code .= "{$this->space} // interfaces\n"; foreach ($interface->interfaces as $key => $value) { - $code .= " $key: $value\n"; + $code .= "{$this->space} $key: $value\n"; } } - $code .= "}\n"; + $code .= "{$this->space}}\n"; $plural = Str::plural($interface->name); - $code .= "export type $plural = Array<{$interface->name}>\n\n"; + $code .= "{$this->space}export type $plural = Array<{$interface->name}>\n\n"; return $code; } From c7419f1105170450578f4328d3599c4d332e5346 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Thu, 21 Oct 2021 15:47:07 -0500 Subject: [PATCH 14/16] =?UTF-8?q?=F0=9F=8E=A8=20readme=20update=20for=20gl?= =?UTF-8?q?obal=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 20 ++++++++++++++++++++ src/Commands/ModelTyper.php | 2 +- src/ModelInterface.php | 13 +++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 870e105..d4d6dc8 100644 --- a/readme.md +++ b/readme.md @@ -113,3 +113,23 @@ You can also specify an interface is nullable: ], ]; ``` + + +### Declare global +Generate your interfaces in a global namespace named `model` +```bash +artisn model:typer --global +``` + +```ts +export {} +declare global { + export namespace models { + + export interface Provider { + // columns + id: number + user_id: number + avatar?: string +... +``` diff --git a/src/Commands/ModelTyper.php b/src/Commands/ModelTyper.php index 99b3ed8..bfdf662 100644 --- a/src/Commands/ModelTyper.php +++ b/src/Commands/ModelTyper.php @@ -40,7 +40,7 @@ public function __construct() */ public function handle() { - echo (new ModelInterface($this->option('global') !== null))->generate(); + echo (new ModelInterface($this->option('global')))->generate(); return 0; } } diff --git a/src/ModelInterface.php b/src/ModelInterface.php index f7022e8..18e128b 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -56,13 +56,14 @@ public function __construct( */ public function generate(): string { - $allCode = ''; + $models = $this->getModels(); + $allCode = $this->getImports($models); + if ($this->global) { - $allCode = "export {}\ndeclare global {\n export namespace models {\n\n"; + $allCode .= "export {}\ndeclare global {\n export namespace models {\n\n"; $this->space = ' '; } - $models = $this->getModels(); - $allCode .= $this->getImports($models); + foreach ($models as $model) { $interface = $this->getInterface(new $model()); $allCode .= $this->getCode($interface); @@ -84,14 +85,14 @@ private function getImports(Collection $models): string { foreach ($models as $model) { if ($interfaces = (new $model())->interfaces) { foreach ($interfaces as $interface) { - if (isset($interfaces['import'])) { + if (isset($interface['import'])) { $imports[ $interface[ 'import' ] ][] = $interface[ 'name' ]; } } } } foreach ($imports as $import=>$names) { - $code .= "{$this->space}import { " . join(', ', array_unique($names)) . " } from '$import'\n"; + $code .= "import { " . join(', ', array_unique($names)) . " } from '$import'\n"; } return $code; } From 197f6d33c99d9503eed95e6bc118c2b4fda91115 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Sun, 24 Oct 2021 15:56:15 -0500 Subject: [PATCH 15/16] =?UTF-8?q?=F0=9F=8E=A8=20proper=20closing=20for=20g?= =?UTF-8?q?lobal=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 18e128b..2210556 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -69,7 +69,7 @@ public function generate(): string $allCode .= $this->getCode($interface); } if ($this->global) { - $allCode .= " }\n}"; + $allCode .= " }\n}\n\n"; } return substr($allCode, 0, strrpos($allCode, "\n")); } From 70f902a3a4e8a78d762eb6a6c906030b333deed0 Mon Sep 17 00:00:00 2001 From: kevin olson Date: Wed, 22 Dec 2021 10:41:38 -0600 Subject: [PATCH 16/16] =?UTF-8?q?=E2=9C=A8=20add=20date=20as=20type=20Date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ModelInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ModelInterface.php b/src/ModelInterface.php index 2210556..c919ee9 100644 --- a/src/ModelInterface.php +++ b/src/ModelInterface.php @@ -28,6 +28,7 @@ class ModelInterface 'string' => 'string', 'decimal' => 'number', 'datetime' => 'Date', + 'date' => 'Date', 'bool' => 'boolean', 'boolean' => 'boolean', 'json' => '[]',