File manager - Edit - /var/www/payraty/helpdesk/public/storage/branding_media/images/Tools.tar
Back
DsnParser.php 0000755 00000015115 00000000000 0007125 0 ustar 00 <?php namespace Doctrine\DBAL\Tools; use Doctrine\DBAL\Driver; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception\MalformedDsnException; use SensitiveParameter; use function array_merge; use function assert; use function is_a; use function is_string; use function parse_str; use function parse_url; use function preg_replace; use function rawurldecode; use function str_replace; use function strpos; use function substr; /** @psalm-import-type Params from DriverManager */ final class DsnParser { /** @var array<string, string|class-string<Driver>> */ private array $schemeMapping; /** @param array<string, string|class-string<Driver>> $schemeMapping An array used to map DSN schemes to DBAL drivers */ public function __construct(array $schemeMapping = []) { $this->schemeMapping = $schemeMapping; } /** * @psalm-return Params * * @throws MalformedDsnException */ public function parse( #[SensitiveParameter] string $dsn ): array { // (pdo-)?sqlite3?:///... => (pdo-)?sqlite3?://localhost/... or else the URL will be invalid $url = preg_replace('#^((?:pdo-)?sqlite3?):///#', '$1://localhost/', $dsn); assert($url !== null); $url = parse_url($url); if ($url === false) { throw MalformedDsnException::new(); } foreach ($url as $param => $value) { if (! is_string($value)) { continue; } $url[$param] = rawurldecode($value); } $params = []; if (isset($url['scheme'])) { $params['driver'] = $this->parseDatabaseUrlScheme($url['scheme']); } if (isset($url['host'])) { $params['host'] = $url['host']; } if (isset($url['port'])) { $params['port'] = $url['port']; } if (isset($url['user'])) { $params['user'] = $url['user']; } if (isset($url['pass'])) { $params['password'] = $url['pass']; } if (isset($params['driver']) && is_a($params['driver'], Driver::class, true)) { $params['driverClass'] = $params['driver']; unset($params['driver']); } $params = $this->parseDatabaseUrlPath($url, $params); $params = $this->parseDatabaseUrlQuery($url, $params); return $params; } /** * Parses the given connection URL and resolves the given connection parameters. * * Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters * via {@see parseDatabaseUrlScheme}. * * @see parseDatabaseUrlScheme * * @param mixed[] $url The URL parts to evaluate. * @param mixed[] $params The connection parameters to resolve. * * @return mixed[] The resolved connection parameters. */ private function parseDatabaseUrlPath(array $url, array $params): array { if (! isset($url['path'])) { return $params; } $url['path'] = $this->normalizeDatabaseUrlPath($url['path']); // If we do not have a known DBAL driver, we do not know any connection URL path semantics to evaluate // and therefore treat the path as a regular DBAL connection URL path. if (! isset($params['driver'])) { return $this->parseRegularDatabaseUrlPath($url, $params); } if (strpos($params['driver'], 'sqlite') !== false) { return $this->parseSqliteDatabaseUrlPath($url, $params); } return $this->parseRegularDatabaseUrlPath($url, $params); } /** * Normalizes the given connection URL path. * * @return string The normalized connection URL path */ private function normalizeDatabaseUrlPath(string $urlPath): string { // Trim leading slash from URL path. return substr($urlPath, 1); } /** * Parses the query part of the given connection URL and resolves the given connection parameters. * * @param mixed[] $url The connection URL parts to evaluate. * @param mixed[] $params The connection parameters to resolve. * * @return mixed[] The resolved connection parameters. */ private function parseDatabaseUrlQuery(array $url, array $params): array { if (! isset($url['query'])) { return $params; } $query = []; parse_str($url['query'], $query); // simply ingest query as extra params, e.g. charset or sslmode return array_merge($params, $query); // parse_str wipes existing array elements } /** * Parses the given regular connection URL and resolves the given connection parameters. * * Assumes that the "path" URL part is already normalized via {@see normalizeDatabaseUrlPath}. * * @see normalizeDatabaseUrlPath * * @param mixed[] $url The regular connection URL parts to evaluate. * @param mixed[] $params The connection parameters to resolve. * * @return mixed[] The resolved connection parameters. */ private function parseRegularDatabaseUrlPath(array $url, array $params): array { $params['dbname'] = $url['path']; return $params; } /** * Parses the given SQLite connection URL and resolves the given connection parameters. * * Assumes that the "path" URL part is already normalized via {@see normalizeDatabaseUrlPath}. * * @see normalizeDatabaseUrlPath * * @param mixed[] $url The SQLite connection URL parts to evaluate. * @param mixed[] $params The connection parameters to resolve. * * @return mixed[] The resolved connection parameters. */ private function parseSqliteDatabaseUrlPath(array $url, array $params): array { if ($url['path'] === ':memory:') { $params['memory'] = true; return $params; } $params['path'] = $url['path']; // pdo_sqlite driver uses 'path' instead of 'dbname' key return $params; } /** * Parses the scheme part from given connection URL and resolves the given connection parameters. * * @return string The resolved driver. */ private function parseDatabaseUrlScheme(string $scheme): string { // URL schemes must not contain underscores, but dashes are ok $driver = str_replace('-', '_', $scheme); // If the driver is an alias (e.g. "postgres"), map it to the actual name ("pdo-pgsql"). // Otherwise, let checkParams decide later if the driver exists. return $this->schemeMapping[$driver] ?? $driver; } } Console/ConnectionNotFound.php 0000755 00000000212 00000000000 0012372 0 ustar 00 <?php namespace Doctrine\DBAL\Tools\Console; use OutOfBoundsException; final class ConnectionNotFound extends OutOfBoundsException { } Console/ConnectionProvider.php 0000755 00000000504 00000000000 0012434 0 ustar 00 <?php namespace Doctrine\DBAL\Tools\Console; use Doctrine\DBAL\Connection; interface ConnectionProvider { public function getDefaultConnection(): Connection; /** @throws ConnectionNotFound in case a connection with the given name does not exist. */ public function getConnection(string $name): Connection; } Console/ConnectionProvider/SingleConnectionProvider.php 0000755 00000001715 00000000000 0017415 0 ustar 00 <?php namespace Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\ConnectionNotFound; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use function sprintf; class SingleConnectionProvider implements ConnectionProvider { private Connection $connection; private string $defaultConnectionName; public function __construct(Connection $connection, string $defaultConnectionName = 'default') { $this->connection = $connection; $this->defaultConnectionName = $defaultConnectionName; } public function getDefaultConnection(): Connection { return $this->connection; } public function getConnection(string $name): Connection { if ($name !== $this->defaultConnectionName) { throw new ConnectionNotFound(sprintf('Connection with name "%s" does not exist.', $name)); } return $this->connection; } } Console/ConsoleRunner.php 0000755 00000004622 00000000000 0011423 0 ustar 00 <?php namespace Doctrine\DBAL\Tools\Console; use Composer\InstalledVersions; use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Exception; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use function assert; /** * Handles running the Console Tools inside Symfony Console context. * * @deprecated Use Symfony Console documentation to bootstrap a command-line application. */ class ConsoleRunner { /** * Runs console with the given connection provider. * * @param Command[] $commands * * @return void * * @throws Exception */ public static function run(ConnectionProvider $connectionProvider, $commands = []) { $version = InstalledVersions::getVersion('doctrine/dbal'); assert($version !== null); $cli = new Application('Doctrine Command Line Interface', $version); $cli->setCatchExceptions(true); self::addCommands($cli, $connectionProvider); $cli->addCommands($commands); $cli->run(); } /** @return void */ public static function addCommands(Application $cli, ConnectionProvider $connectionProvider) { $cli->addCommands([ new RunSqlCommand($connectionProvider), new ReservedWordsCommand($connectionProvider), ]); } /** * Prints the instructions to create a configuration file * * @deprecated This method will be removed without replacement. * * @return void */ public static function printCliConfigTemplate() { echo <<<'HELP' You are missing a "cli-config.php" or "config/cli-config.php" file in your project, which is required to get the Doctrine-DBAL Console working. You can use the following sample as a template: <?php use Doctrine\DBAL\Tools\Console\ConnectionProvider\SingleConnectionProvider; // You can append new commands to $commands array, if needed // replace with the mechanism to retrieve DBAL connection(s) in your app // and return a Doctrine\DBAL\Tools\Console\ConnectionProvider instance. $connection = getDBALConnection(); // in case you have a single connection you can use SingleConnectionProvider // otherwise you need to implement the Doctrine\DBAL\Tools\Console\ConnectionProvider interface with your custom logic return new SingleConnectionProvider($connection); HELP; } } Console/Command/CommandCompatibility.php 0000755 00000001550 00000000000 0014312 0 ustar 00 <?php declare(strict_types=1); namespace Doctrine\DBAL\Tools\Console\Command; use ReflectionMethod; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; if ((new ReflectionMethod(Command::class, 'execute'))->hasReturnType()) { /** @internal */ trait CommandCompatibility { protected function execute(InputInterface $input, OutputInterface $output): int { return $this->doExecute($input, $output); } } } else { /** @internal */ trait CommandCompatibility { /** * {@inheritDoc} * * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { return $this->doExecute($input, $output); } } } Console/Command/RunSqlCommand.php 0000755 00000007323 00000000000 0012731 0 ustar 00 <?php namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use function array_keys; use function assert; use function is_bool; use function is_string; use function sprintf; use function stripos; /** * Task for executing arbitrary SQL that can come from a file or directly from * the command line. */ class RunSqlCommand extends Command { use CommandCompatibility; private ConnectionProvider $connectionProvider; public function __construct(ConnectionProvider $connectionProvider) { parent::__construct(); $this->connectionProvider = $connectionProvider; } /** @return void */ protected function configure() { $this ->setName('dbal:run-sql') ->setDescription('Executes arbitrary SQL directly from the command line.') ->setDefinition([ new InputOption('connection', null, InputOption::VALUE_REQUIRED, 'The named database connection'), new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'), new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set (deprecated).'), new InputOption('force-fetch', null, InputOption::VALUE_NONE, 'Forces fetching the result.'), ]) ->setHelp(<<<'EOT' The <info>%command.name%</info> command executes the given SQL query and outputs the results: <info>php %command.full_name% "SELECT * FROM users"</info> EOT); } /** @throws Exception */ private function doExecute(InputInterface $input, OutputInterface $output): int { $conn = $this->getConnection($input); $io = new SymfonyStyle($input, $output); $sql = $input->getArgument('sql'); if ($sql === null) { throw new RuntimeException("Argument 'SQL' is required in order to execute this command correctly."); } assert(is_string($sql)); if ($input->getOption('depth') !== null) { $io->warning('Parameter "depth" is deprecated and has no effect anymore.'); } $forceFetch = $input->getOption('force-fetch'); assert(is_bool($forceFetch)); if (stripos($sql, 'select') === 0 || $forceFetch) { $this->runQuery($io, $conn, $sql); } else { $this->runStatement($io, $conn, $sql); } return 0; } private function getConnection(InputInterface $input): Connection { $connectionName = $input->getOption('connection'); assert(is_string($connectionName) || $connectionName === null); if ($connectionName !== null) { return $this->connectionProvider->getConnection($connectionName); } return $this->connectionProvider->getDefaultConnection(); } /** @throws Exception */ private function runQuery(SymfonyStyle $io, Connection $conn, string $sql): void { $resultSet = $conn->fetchAllAssociative($sql); if ($resultSet === []) { $io->success('The query yielded an empty result set.'); return; } $io->table(array_keys($resultSet[0]), $resultSet); } /** @throws Exception */ private function runStatement(SymfonyStyle $io, Connection $conn, string $sql): void { $io->success(sprintf('%d rows affected.', $conn->executeStatement($sql))); } } Console/Command/ReservedWordsCommand.php 0000755 00000015676 00000000000 0014315 0 ustar 00 <?php namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL84Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; use Doctrine\DBAL\Platforms\Keywords\OracleKeywords; use Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords; use Doctrine\DBAL\Platforms\Keywords\PostgreSQL94Keywords; use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator; use Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords; use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\Deprecations\Deprecation; use InvalidArgumentException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use function array_keys; use function assert; use function count; use function implode; use function is_array; use function is_string; /** @deprecated Use database documentation instead. */ class ReservedWordsCommand extends Command { use CommandCompatibility; /** @var array<string,KeywordList> */ private array $keywordLists; private ConnectionProvider $connectionProvider; public function __construct(ConnectionProvider $connectionProvider) { Deprecation::triggerIfCalledFromOutside( 'doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5431', 'ReservedWordsCommand is deprecated. Use database documentation instead.', ); parent::__construct(); $this->connectionProvider = $connectionProvider; $this->keywordLists = [ 'db2' => new DB2Keywords(), 'mariadb102' => new MariaDb102Keywords(), 'mysql' => new MySQLKeywords(), 'mysql57' => new MySQL57Keywords(), 'mysql80' => new MySQL80Keywords(), 'mysql84' => new MySQL84Keywords(), 'oracle' => new OracleKeywords(), 'pgsql' => new PostgreSQL94Keywords(), 'pgsql100' => new PostgreSQL100Keywords(), 'sqlite' => new SQLiteKeywords(), 'sqlserver' => new SQLServer2012Keywords(), ]; } /** * Add or replace a keyword list. */ public function setKeywordList(string $name, KeywordList $keywordList): void { $this->keywordLists[$name] = $keywordList; } /** * If you want to add or replace a keywords list use this command. * * @param string $name * @param class-string<KeywordList> $class * * @return void */ public function setKeywordListClass($name, $class) { Deprecation::trigger( 'doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4510', 'ReservedWordsCommand::setKeywordListClass() is deprecated,' . ' use ReservedWordsCommand::setKeywordList() instead.', ); $this->keywordLists[$name] = new $class(); } /** @return void */ protected function configure() { $this ->setName('dbal:reserved-words') ->setDescription('Checks if the current database contains identifiers that are reserved.') ->setDefinition([ new InputOption('connection', null, InputOption::VALUE_REQUIRED, 'The named database connection'), new InputOption( 'list', 'l', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Keyword-List name.', ), ]) ->setHelp(<<<'EOT' Checks if the current database contains tables and columns with names that are identifiers in this dialect or in other SQL dialects. By default all supported platform keywords are checked: <info>%command.full_name%</info> If you want to check against specific dialects you can pass them to the command: <info>%command.full_name% -l mysql -l pgsql</info> The following keyword lists are currently shipped with Doctrine: * db2 * mariadb102 * mysql * mysql57 * mysql80 * mysql84 * oracle * pgsql * pgsql100 * sqlite * sqlserver EOT); } /** @throws Exception */ private function doExecute(InputInterface $input, OutputInterface $output): int { $output->writeln( '<comment>The <info>dbal:reserved-words</info> command is deprecated.</comment>' . ' Use the documentation on the used database platform(s) instead.', ); $output->writeln(''); $conn = $this->getConnection($input); $keywordLists = $input->getOption('list'); if (is_string($keywordLists)) { $keywordLists = [$keywordLists]; } elseif (! is_array($keywordLists)) { $keywordLists = []; } if (count($keywordLists) === 0) { $keywordLists = array_keys($this->keywordLists); } $keywords = []; foreach ($keywordLists as $keywordList) { if (! isset($this->keywordLists[$keywordList])) { throw new InvalidArgumentException( "There exists no keyword list with name '" . $keywordList . "'. " . 'Known lists: ' . implode(', ', array_keys($this->keywordLists)), ); } $keywords[] = $this->keywordLists[$keywordList]; } $output->write( 'Checking keyword violations for <comment>' . implode(', ', $keywordLists) . '</comment>...', true, ); $schema = $conn->getSchemaManager()->introspectSchema(); $visitor = new ReservedKeywordsValidator($keywords); $schema->visit($visitor); $violations = $visitor->getViolations(); if (count($violations) !== 0) { $output->write( 'There are <error>' . count($violations) . '</error> reserved keyword violations' . ' in your database schema:', true, ); foreach ($violations as $violation) { $output->write(' - ' . $violation, true); } return 1; } $output->write('No reserved keywords violations have been found!', true); return 0; } private function getConnection(InputInterface $input): Connection { $connectionName = $input->getOption('connection'); assert(is_string($connectionName) || $connectionName === null); if ($connectionName !== null) { return $this->connectionProvider->getConnection($connectionName); } return $this->connectionProvider->getDefaultConnection(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings