Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Command/BakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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;

Expand Down Expand Up @@ -67,6 +69,31 @@
return 'bake ' . $name;
}

/**
* @inheritDoc
*/
public function initialize(): void
{
parent::initialize();

$locator = $this->getTableLocator();

try {
$locator->get('NonExistingTable');
$fallbackEnabled = true;
$locator->remove('NonExistingTable');
} catch (MissingTableClassException $e) {
$fallbackEnabled = false;

Check warning on line 86 in src/Command/BakeCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BakeCommand.php#L85-L86

Added lines #L85 - L86 were not covered by tests
}

if (!$fallbackEnabled) {
// Use our own table locator with fallback classes
$locator = new TableLocator();
$locator->allowFallbackClass(true);
$this->setTableLocator($locator);

Check warning on line 93 in src/Command/BakeCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/BakeCommand.php#L91-L93

Added lines #L91 - L93 were not covered by tests
}
}

/**
* Handles splitting up the plugin prefix and classname.
*
Expand Down
Loading