From 3102485433b019b92dcb529f95c556a6e07eff17 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Mon, 14 Jul 2025 16:17:46 +0300 Subject: [PATCH 1/3] Use internal table locator with fallback classes --- src/Command/BakeCommand.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Command/BakeCommand.php b/src/Command/BakeCommand.php index 930ac6b9..9dbad0f8 100644 --- a/src/Command/BakeCommand.php +++ b/src/Command/BakeCommand.php @@ -67,6 +67,18 @@ public static function defaultName(): string return 'bake ' . $name; } + /** + * @inheritDoc + */ + public function initialize(): void + { + parent::initialize(); + // Use our own table locator with fallback classes + $locator = new TableLocator(); + $locator->allowFallbackClass(true); + $this->setTableLocator($locator); + } + /** * Handles splitting up the plugin prefix and classname. * From 329a9c0881fa6de188ab90c0543b4aba51471a02 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Mon, 14 Jul 2025 16:20:26 +0300 Subject: [PATCH 2/3] Add missing use --- src/Command/BakeCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Command/BakeCommand.php b/src/Command/BakeCommand.php index 9dbad0f8..56254937 100644 --- a/src/Command/BakeCommand.php +++ b/src/Command/BakeCommand.php @@ -27,6 +27,7 @@ use Cake\Core\ConventionsTrait; use Cake\Event\Event; use Cake\Event\EventManager; +use Cake\ORM\Locator\TableLocator; use InvalidArgumentException; use function Cake\Core\pluginSplit; From c6e9a2ce4b89412103ad390842c91e79267f4eef Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Mon, 14 Jul 2025 16:32:33 +0300 Subject: [PATCH 3/3] Do not create another table locator if fallback is enabled. --- src/Command/BakeCommand.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Command/BakeCommand.php b/src/Command/BakeCommand.php index 56254937..3f77ce01 100644 --- a/src/Command/BakeCommand.php +++ b/src/Command/BakeCommand.php @@ -27,6 +27,7 @@ use Cake\Core\ConventionsTrait; use Cake\Event\Event; use Cake\Event\EventManager; +use Cake\ORM\Exception\MissingTableClassException; use Cake\ORM\Locator\TableLocator; use InvalidArgumentException; use function Cake\Core\pluginSplit; @@ -74,10 +75,23 @@ public static function defaultName(): string public function initialize(): void { parent::initialize(); - // Use our own table locator with fallback classes - $locator = new TableLocator(); - $locator->allowFallbackClass(true); - $this->setTableLocator($locator); + + $locator = $this->getTableLocator(); + + try { + $locator->get('NonExistingTable'); + $fallbackEnabled = true; + $locator->remove('NonExistingTable'); + } catch (MissingTableClassException $e) { + $fallbackEnabled = false; + } + + if (!$fallbackEnabled) { + // Use our own table locator with fallback classes + $locator = new TableLocator(); + $locator->allowFallbackClass(true); + $this->setTableLocator($locator); + } } /**