From 4a445df059b0ea4a26c0daf7f19c2d8f8eac5225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mortiz=20K=C3=BCttel?= Date: Tue, 12 Mar 2024 03:56:58 +0100 Subject: [PATCH 1/3] model handler: only try to instantiate what is instantiable When i was trying to run PHPUnit tests using the database they always instantly failed as soon as a Model with relations got used, because of the automatic scanning which tries to instaniate one of my abstract classes in my project: Error: Cannot instantiate abstract class While there is a try-catch block surrounding the new this will not catch this error, so instead use the RelectionClass is instantiable to check whether the class can be instantiated before doing so. --- src/Drafter/Handlers/ModelHandler.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Drafter/Handlers/ModelHandler.php b/src/Drafter/Handlers/ModelHandler.php index d31ef31..704d9a0 100644 --- a/src/Drafter/Handlers/ModelHandler.php +++ b/src/Drafter/Handlers/ModelHandler.php @@ -168,6 +168,10 @@ protected function getModels(): array continue; } + if (!(new \ReflectionClass($class))->isInstantiable()) { + continue; + } + // Try to instantiate try { $instance = new $class(); From 655d8e03ad0024860d79b8cb0b3e7494d3cbbc6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mortiz=20K=C3=BCttel?= Date: Tue, 12 Mar 2024 04:08:12 +0100 Subject: [PATCH 2/3] composer: change package name to mkuettel/codeigniter4-schemas --- README.md | 2 +- composer.json | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e29185..16a5c4c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Database schema management, for CodeIgniter 4 ## Quick Start -1. Install with Composer: `> composer require tatter/schemas` +1. Install with Composer: `> composer require mkuettel/codeigniter4-schemas` 2. Generate a new schema: `> php spark schemas` ## Features diff --git a/composer.json b/composer.json index 3a9267d..e9b259c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "tatter/schemas", + "name": "mkuettel/codeigniter4-schemas", "description": "Database schema management, for CodeIgniter 4", "license": "MIT", "type": "library", @@ -17,9 +17,14 @@ "email": "mgatner@tattersoftware.com", "homepage": "https://tattersoftware.com", "role": "Developer" + }, + { + "name": "Moritz Küttel", + "email": "moritz_kuettel+composer_ci4schemas@tattersoftware.com", + "role": "Developer" } ], - "homepage": "https://github.com/tattersoftware/codeigniter4-schemas", + "homepage": "https://github.com/mkuettel/codeigniter4-schemas", "require": { "php": "^7.4 || ^8.0" }, From 4aa0d5fe6749359e7c9338482e04847372b07d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mortiz=20K=C3=BCttel?= Date: Tue, 12 Mar 2024 04:37:46 +0100 Subject: [PATCH 3/3] no longer ignore the Namespace Tests\Support as I have test models Now that the ModelHandler isn't that sensitive anymore and I have a project wherein I use relations in test models within tests/_support, and i don't know how to override this, let's just remove it by default. --- src/Config/Schemas.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Config/Schemas.php b/src/Config/Schemas.php index 135ace8..81f8f23 100644 --- a/src/Config/Schemas.php +++ b/src/Config/Schemas.php @@ -33,7 +33,6 @@ class Schemas extends BaseConfig // Namespaces to ignore (mostly for ModelHandler) public $ignoredNamespaces = [ - 'Tests\Support', 'CodeIgniter\Commands\Generators', ];