
| Current Path : /var/www/html/c12park/vendor/chi-teck/drupal-code-generator/src/Command/PhpStormMeta/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/c12park/vendor/chi-teck/drupal-code-generator/src/Command/PhpStormMeta/Database.php |
<?php
declare(strict_types=1);
namespace DrupalCodeGenerator\Command\PhpStormMeta;
use Drupal\Core\Database\Connection;
use DrupalCodeGenerator\Asset\File;
/**
* Generates PhpStorm meta-data for Drupal database.
*/
final class Database {
/**
* Constructs the object.
*/
public function __construct(
private readonly Connection $connection,
) {}
/**
* Generator callback.
*/
public function __invoke(): File {
$driver = $this->connection->driver();
$tables = [];
// @todo Support PostgreSQL.
if ($driver === 'mysql') {
/** @psalm-suppress PossiblyNullReference, PossiblyInvalidMethodCall */
$tables = $this->connection->query('SHOW TABLES')->fetchCol();
}
elseif ($driver === 'sqlite') {
$query = <<< 'SQL'
SELECT name
FROM sqlite_schema
WHERE type ='table' AND name NOT LIKE 'sqlite_%'
ORDER BY name
SQL;
/** @psalm-suppress PossiblyNullReference, PossiblyInvalidMethodCall */
$tables = $this->connection->query($query)->fetchCol();
}
return File::create('.phpstorm.meta.php/database.php')
->template('database.php.twig')
->vars(['tables' => $tables]);
}
}