Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/tests/App/
/tests/Database/
/tests/lion_database.sqlite
/public/lion_database.sqlite
.phpunit.result.cache
# Ignore dependency files ----------------------------------------------------------------------------------------------
/vendor/
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions public/connections.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* -----------------------------------------------------------------------------
* Start database service
* -----------------------------------------------------------------------------
* describe connections to establish connecting to multiple databases
* -----------------------------------------------------------------------------
*/

use Lion\Database\Driver;

$privateConnections = [
env('DB_DEFAULT') => [
'type' => env('DB_TYPE'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'dbname' => env('DB_NAME'),
'user' => env('DB_USER'),
'password' => env('DB_PASSWORD'),
],
env('DB_NAME_TEST') => [
'type' => env('DB_TYPE_TEST'),
'host' => env('DB_HOST_TEST'),
'port' => env('DB_PORT_TEST'),
'dbname' => env('DB_NAME_TEST'),
'user' => env('DB_USER_TEST'),
'password' => env('DB_PASSWORD_TEST'),
],
env('DB_NAME_TEST_POSTGRESQL') => [
'type' => env('DB_TYPE_TEST_POSTGRESQL'),
'host' => env('DB_HOST_TEST_POSTGRESQL'),
'port' => env('DB_PORT_TEST_POSTGRESQL'),
'dbname' => env('DB_NAME'),
'user' => env('DB_USER_TEST_POSTGRESQL'),
'password' => env('DB_PASSWORD_TEST_POSTGRESQL'),
],
'lion_database_sqlite' => [
'type' => env('DB_TYPE_TEST_SQLITE'),
'dbname' => __DIR__ . '/' . env('DB_NAME_TEST_SQLITE'),
],
];

Driver::run([
'default' => env('DB_DEFAULT'),
'connections' => $privateConnections,
]);

define('NUMBER_OF_ACTIVE_CONNECTIONS', count($privateConnections));
25 changes: 21 additions & 4 deletions src/LionBundle/Commands/Lion/DB/CrudCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,29 @@
{
$this
->setName('db:crud')
->setDescription(
'Command to generate controller and model of an entity with their respective CRUD functions.'
)
->setDescription('Command to generate controller and model of an entity with their respective CRUD functions.') // phpcs:ignore
->addArgument('entity', InputArgument::REQUIRED, 'Entity name.');
}

/**
* Initializes the command after the input has been bound and before the input
* is validated.
*
* This is mainly useful when a lot of commands extends one main command where
* some things need to be initialized based on the input arguments and options.
*
* @param InputInterface $input InputInterface is the interface implemented by
* all input classes.
* @param OutputInterface $output OutputInterface is the interface implemented
* by all Output classes.
*
* @return void
*/
protected function initialize(InputInterface $input, OutputInterface $output): void

Check warning on line 112 in src/LionBundle/Commands/Lion/DB/CrudCommand.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this method "initialize" to simply inherit it.

See more on https://sonarcloud.io/project/issues?id=lion-packages_bundle&issues=AZ9CUuut3wYsaW3iJtpN&open=AZ9CUuut3wYsaW3iJtpN&pullRequest=302
{
parent::initialize($input, $output);
}

/**
* Executes the current command.
*
Expand All @@ -121,7 +138,7 @@
/** @var string $entity */
$entity = $input->getArgument('entity');

$selectedConnection = $this->selectConnection($input, $output);
$selectedConnection = $this->selectConnection();

$connectionName = Connection::getConnections()[$selectedConnection][Connection::CONNECTION_DBNAME];

Expand Down
68 changes: 23 additions & 45 deletions src/LionBundle/Commands/Lion/DB/DBSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,21 @@
namespace Lion\Bundle\Commands\Lion\DB;

use DI\Attribute\Inject;
use InvalidArgumentException;
use Lion\Bundle\Helpers\Commands\ClassFactory;
use Lion\Bundle\Helpers\Commands\Migrations\Migrations;
use Lion\Bundle\Helpers\Commands\Selection\MenuCommand;
use Lion\Bundle\Helpers\DatabaseEngine;
use Lion\Bundle\Interface\SeedInterface;
use Lion\Command\Command;
use Lion\Database\Connection;
use Lion\Files\Store;
use Lion\Helpers\Str;
use Lion\Request\Http;
use LogicException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Execute the database connection seeds.
*/
class DBSeedCommand extends Command
class DBSeedCommand extends MenuCommand
{
/**
* Manipulate system files.
*
* @var Store $store
*/
private Store $store;

/**
* Modify and construct strings with different formats.
*
* @var Str $str
*/
private Str $str;

/**
* Manages basic database engine processes.
*
Expand All @@ -61,22 +42,6 @@
*/
private ClassFactory $classFactory;

#[Inject]
public function setStore(Store $store): DBSeedCommand
{
$this->store = $store;

return $this;
}

#[Inject]
public function setStr(Str $str): DBSeedCommand
{
$this->str = $str;

return $this;
}

#[Inject]
public function setDatabaseEngine(DatabaseEngine $databaseEngine): DBSeedCommand
{
Expand Down Expand Up @@ -110,8 +75,26 @@
{
$this
->setName('db:seed')
->setDescription('Run the available seeds.')
->addOption('connection', 'c', InputOption::VALUE_REQUIRED, 'The connection to run.');
->setDescription('Run the available seeds.');
}

/**
* Initializes the command after the input has been bound and before the input
* is validated.
*
* This is mainly useful when a lot of commands extends one main command where
* some things need to be initialized based on the input arguments and options.
*
* @param InputInterface $input InputInterface is the interface implemented by
* all input classes.
* @param OutputInterface $output OutputInterface is the interface implemented
* by all Output classes.
*
* @return void
*/
protected function initialize(InputInterface $input, OutputInterface $output): void

Check warning on line 95 in src/LionBundle/Commands/Lion/DB/DBSeedCommand.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this method "initialize" to simply inherit it.

See more on https://sonarcloud.io/project/issues?id=lion-packages_bundle&issues=AZ9CUNiwTRWAAPg0-F1W&open=AZ9CUNiwTRWAAPg0-F1W&pullRequest=302
{
parent::initialize($input, $output);
}

/**
Expand All @@ -132,12 +115,7 @@
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string|null $connectionName */
$connectionName = $input->getOption('connection');

if (!$connectionName) {
throw new InvalidArgumentException("The '--connection' option is required.", Http::INTERNAL_SERVER_ERROR);
}
$connectionName = $this->selectConnection();

$connections = Connection::getConnections();

Expand Down
24 changes: 5 additions & 19 deletions src/LionBundle/Commands/Lion/Migrations/FreshMigrationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use DI\Attribute\Inject;
use Exception;
use InvalidArgumentException;
use Lion\Bundle\Helpers\Commands\Migrations\Migrations;
use Lion\Bundle\Helpers\Commands\Selection\MenuCommand;
use Lion\Bundle\Helpers\DatabaseEngine;
Expand All @@ -16,7 +15,6 @@
use Lion\Bundle\Interface\Migrations\ViewInterface;
use Lion\Bundle\Interface\MigrationUpInterface;
use Lion\Database\Connection;
use Lion\Request\Http;
use LogicException;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -69,8 +67,7 @@ protected function configure(): void
$this
->setName('migrate:fresh')
->setDescription('Drop all tables and re-run all migrations')
->addOption('seed', 's', InputOption::VALUE_OPTIONAL, 'Do you want to run the seeds?', 'none')
->addOption('connection', 'c', InputOption::VALUE_REQUIRED, 'The connection to run.');
->addOption('seed', 's', InputOption::VALUE_OPTIONAL, 'Do you want to run the seeds?', 'none');
}

/**
Expand Down Expand Up @@ -113,12 +110,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string|null $connectionName */
$connectionName = $input->getOption('connection');

if (!$connectionName) {
throw new InvalidArgumentException("The '--connection' option is required.", Http::INTERNAL_SERVER_ERROR);
}
$connectionName = $this->selectConnection();

$connections = Connection::getConnections();

Expand Down Expand Up @@ -170,15 +162,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$seed = $input->getOption('seed');

if ($seed != 'none') {
$output->writeln('');

$this
->getApplication()
/** @phpstan-ignore-next-line */
->find('db:seed')
->run(new ArrayInput([
'--connection' => $connectionName,
]), $output);
$this->getApplication()
?->find('db:seed')
->run(new ArrayInput([]), $output);
}

return parent::SUCCESS;
Expand Down
36 changes: 24 additions & 12 deletions src/LionBundle/Commands/Lion/New/MigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use LogicException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -80,8 +79,26 @@
$this
->setName('new:migration')
->setDescription('Command required to generate a new migration.')
->addArgument('migration', InputArgument::REQUIRED, 'Migration name.')
->addOption('connection', 'c', InputOption::VALUE_REQUIRED, 'The connection to run.');
->addArgument('migration', InputArgument::REQUIRED, 'Migration name.');
}

/**
* Initializes the command after the input has been bound and before the input
* is validated.
*
* This is mainly useful when a lot of commands extends one main command where
* some things need to be initialized based on the input arguments and options.
*
* @param InputInterface $input InputInterface is the interface implemented by
* all input classes.
* @param OutputInterface $output OutputInterface is the interface implemented
* by all Output classes.
*
* @return void
*/
protected function initialize(InputInterface $input, OutputInterface $output): void

Check warning on line 99 in src/LionBundle/Commands/Lion/New/MigrationCommand.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this method "initialize" to simply inherit it.

See more on https://sonarcloud.io/project/issues?id=lion-packages_bundle&issues=AZ9CUNmXTRWAAPg0-F1X&open=AZ9CUNmXTRWAAPg0-F1X&pullRequest=302
{
parent::initialize($input, $output);
}

/**
Expand All @@ -106,16 +123,13 @@
/** @var string $migration */
$migration = $input->getArgument('migration');

if (STR->of($migration)->test("/.*\//")) {
if ($this->str->of($migration)->test("/.*\//")) {
throw new InvalidArgumentException('Migration cannot be inside subfolders.', Http::INTERNAL_SERVER_ERROR);
}

/** @var string|null $connectionName */
$connectionName = $input->getOption('connection');
$connectionName = $this->selectConnection();

if (!$connectionName) {
throw new InvalidArgumentException("The '--connection' option is required.", Http::INTERNAL_SERVER_ERROR);
}
$migrationType = $this->selectMigrationType();

$connections = Connection::getConnections();

Expand All @@ -128,8 +142,6 @@

$driver = $this->databaseEngine->getDriver($databaseEngineType);

$selectedType = $this->selectMigrationType($input, $output, MigrationFactory::MIGRATIONS_OPTIONS);

/** @var string $migrationClassName */
$migrationClassName = $this->str
->of($migration)
Expand All @@ -148,7 +160,7 @@
->trim()
->get();

$dataMigration = $this->migrationFactory->getBody($migrationClassName, $selectedType, $dbNameFormat, $driver);
$dataMigration = $this->migrationFactory->getBody($migrationClassName, $migrationType, $dbNameFormat, $driver);

/** @var string $path */
$path = $dataMigration->path;
Expand Down
Loading
Loading