-
Notifications
You must be signed in to change notification settings - Fork 3
add dbal related code from DoctrineBundle #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
99e4572
add dbal config & extension
dmaicher 3a589e9
cleanup config: remove orm stuff
dmaicher dfca364
require doctrine/dbal
dmaicher 193d4ec
move more dbal related things
dmaicher afcbb2c
add data collector + some fixes
dmaicher 300d236
fix data collector
dmaicher 5f7fec1
add ProfilerController
dmaicher 6d75488
add ConnectionRegistry
dmaicher d7d6ce7
use registry
dmaicher 20b3cb2
start adding tests
dmaicher ebe8d49
add some more tests
dmaicher 7356d86
add some more tests
dmaicher c944ac6
adjust composer requirements
dmaicher af74eec
adjust composer requirements
dmaicher 7630931
CS fixes
dmaicher 4f5ec77
add more tests
dmaicher 2c6f5bd
add schema + extension tests
dmaicher 98fb67e
cleanup
dmaicher 4f78716
more cleanup
dmaicher 25dc5ad
address first review comments
dmaicher ded7eb8
add RunSqlDoctrineCommand proxy
dmaicher bd278bf
cs fix
dmaicher cdc3fd4
add 2 more commands + tests
dmaicher ea8b8be
define command services + cleanup
dmaicher ed66ca2
cleanup
dmaicher 1a3d3e6
use correct version of factory from 2.0.x
dmaicher d05284d
fix CS
dmaicher 479e43f
remove unused class
dmaicher fe82cd8
fix registry + add test
dmaicher 4ccb226
drop support for phpunit 7
dmaicher 1c46aa5
fix phpunit 7 compat
dmaicher 4d595a3
fix phpunit warnings
dmaicher 5436c29
fix CS
dmaicher 4df8eea
fix deprecations for doctrine/dbal >= 2.11
dmaicher 8d51194
fix CS
dmaicher a7361d8
fix comments
dmaicher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?xml version="1.0"?> | ||
| <ruleset> | ||
| <arg name="basepath" value=""/> | ||
| <arg name="extensions" value="php"/> | ||
| <arg name="parallel" value="80"/> | ||
| <arg name="cache" value=".phpcs-cache"/> | ||
| <arg name="colors"/> | ||
|
|
||
| <!-- Ignore warnings, show progress of the run and show sniff names --> | ||
| <arg value="nps"/> | ||
|
|
||
| <file>.</file> | ||
| <exclude-pattern>vendor/*</exclude-pattern> | ||
|
|
||
| <rule ref="Doctrine"> | ||
| <exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility"/> | ||
| <exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/> | ||
| <exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/> | ||
| <exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator.NullCoalesceOperatorNotUsed"/> | ||
| <exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/> | ||
| <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/> | ||
| </rule> | ||
|
|
||
| <rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses"> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="Squiz.Classes.ClassFileName.NoMatch"> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty"> | ||
| <exclude-pattern>tests/Fixtures/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"> | ||
| <exclude-pattern>src/DependencyInjection/*</exclude-pattern> | ||
| <exclude-pattern>src/Twig/DoctrineDBALExtension.php</exclude-pattern> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"> | ||
| <exclude-pattern>src/DependencyInjection/*</exclude-pattern> | ||
| <exclude-pattern>src/Twig/DoctrineDBALExtension.php</exclude-pattern> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"> | ||
| <exclude-pattern>src/DependencyInjection/*</exclude-pattern> | ||
| <exclude-pattern>src/Twig/DoctrineDBALExtension.php</exclude-pattern> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| </ruleset> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
| <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd" | ||
| backupGlobals="false" | ||
| colors="true" | ||
| bootstrap="vendor/autoload.php" | ||
| failOnRisky="true" | ||
| > | ||
| <testsuites> | ||
| <testsuite name="Doctrine DBAL Bundle Test Suite"> | ||
| <directory>tests/</directory> | ||
| <exclude>tests/Fixtures</exclude> | ||
| </testsuite> | ||
| </testsuites> | ||
|
|
||
| <filter> | ||
| <whitelist> | ||
| <directory>./src/</directory> | ||
| </whitelist> | ||
| </filter> | ||
| </phpunit> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| namespace Doctrine\Bundle\DBALBundle\Command\Proxy; | ||
|
|
||
| use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; | ||
| use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
|
|
||
| trait ApplicationConnectionHelper | ||
| { | ||
| private function setConnectionHelper(Application $application, ?string $connectionName) | ||
| { | ||
| $connection = $application->getKernel()->getContainer()->get('doctrine.dbal.connection_registry')->getConnection($connectionName); | ||
dmaicher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $helperSet = $application->getHelperSet(); | ||
| $helperSet->set(new ConnectionHelper($connection), 'db'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| namespace Doctrine\Bundle\DBALBundle\Command\Proxy; | ||
|
|
||
| use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| /** | ||
| * Execute a SQL query and output the results. | ||
| */ | ||
| class RunSqlDoctrineCommand extends RunSqlCommand | ||
| { | ||
| use ApplicationConnectionHelper; | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| protected function configure() | ||
| { | ||
| parent::configure(); | ||
|
|
||
| $this | ||
| ->setName('doctrine:query:sql') | ||
| ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command') | ||
| ->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 | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| $this->setConnectionHelper($this->getApplication(), $input->getOption('connection')); | ||
|
|
||
| return parent::execute($input, $output); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| <?php | ||
|
|
||
| namespace Doctrine\Bundle\DBALBundle; | ||
|
|
||
| use Doctrine\Common\EventManager; | ||
| use Doctrine\DBAL\Configuration; | ||
| use Doctrine\DBAL\Connection; | ||
| use Doctrine\DBAL\DBALException; | ||
| use Doctrine\DBAL\DriverManager; | ||
| use Doctrine\DBAL\Exception\DriverException; | ||
| use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
| use Doctrine\DBAL\Types\Type; | ||
| use const E_USER_DEPRECATED; | ||
| use function get_class; | ||
| use function trigger_error; | ||
|
|
||
| class ConnectionFactory | ||
| { | ||
| /** @var mixed[][] */ | ||
| private $typesConfig = []; | ||
|
|
||
| /** @var bool */ | ||
| private $initialized = false; | ||
|
|
||
| /** | ||
| * @param mixed[][] $typesConfig | ||
| */ | ||
| public function __construct(array $typesConfig) | ||
| { | ||
| $this->typesConfig = $typesConfig; | ||
| } | ||
|
|
||
| /** | ||
| * Create a connection by name. | ||
| * | ||
| * @param mixed[] $params | ||
| * @param string[]|Type[] $mappingTypes | ||
| * | ||
| * @return Connection | ||
| */ | ||
| public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = []) | ||
| { | ||
| if (! $this->initialized) { | ||
| $this->initializeTypes(); | ||
| } | ||
|
|
||
| $connection = DriverManager::getConnection($params, $config, $eventManager); | ||
|
|
||
| if (! empty($mappingTypes)) { | ||
| $platform = $this->getDatabasePlatform($connection); | ||
| foreach ($mappingTypes as $dbType => $doctrineType) { | ||
| $platform->registerDoctrineTypeMapping($dbType, $doctrineType); | ||
| } | ||
| } | ||
|
|
||
| if (! empty($this->typesConfig)) { | ||
| $this->markTypesCommented($this->getDatabasePlatform($connection)); | ||
| } | ||
|
|
||
| return $connection; | ||
| } | ||
|
|
||
| /** | ||
| * Try to get the database platform. | ||
| * | ||
| * This could fail if types should be registered to an predefined/unused connection | ||
| * and the platform version is unknown. | ||
| * For details have a look at DoctrineBundle issue #673. | ||
| * | ||
| * @return AbstractPlatform | ||
| * | ||
| * @throws DBALException | ||
| */ | ||
| private function getDatabasePlatform(Connection $connection) | ||
| { | ||
| try { | ||
| return $connection->getDatabasePlatform(); | ||
| } catch (DriverException $driverException) { | ||
| throw new DBALException( | ||
| 'An exception occured while establishing a connection to figure out your platform version.' . PHP_EOL . | ||
| "You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL . | ||
| 'For further information have a look at:' . PHP_EOL . | ||
| 'https://github.com/doctrine/DoctrineBundle/issues/673', | ||
| 0, | ||
| $driverException | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * initialize the types | ||
| */ | ||
| private function initializeTypes() | ||
| { | ||
| foreach ($this->typesConfig as $typeName => $typeConfig) { | ||
| if (Type::hasType($typeName)) { | ||
| Type::overrideType($typeName, $typeConfig['class']); | ||
| } else { | ||
| Type::addType($typeName, $typeConfig['class']); | ||
| } | ||
| } | ||
|
|
||
| $this->initialized = true; | ||
| } | ||
|
|
||
| private function markTypesCommented(AbstractPlatform $platform) : void | ||
| { | ||
| foreach ($this->typesConfig as $typeName => $typeConfig) { | ||
| $type = Type::getType($typeName); | ||
| $requiresSQLCommentHint = $type->requiresSQLCommentHint($platform); | ||
|
|
||
| // Attribute is missing, make sure a type that doesn't require a comment is marked as commented | ||
| // This is deprecated behaviour that will be dropped in 2.0. | ||
| if ($typeConfig['commented'] === null) { | ||
| if (! $requiresSQLCommentHint) { | ||
| @trigger_error( | ||
| sprintf( | ||
| 'The type "%s" was implicitly marked as commented due to the configuration. This is deprecated and will be removed in DoctrineBundle 2.0. Either set the "commented" attribute in the configuration to "false" or mark the type as commented in "%s::requiresSQLCommentHint()."', | ||
| $typeName, | ||
| get_class($type) | ||
| ), | ||
| E_USER_DEPRECATED | ||
| ); | ||
|
|
||
| $platform->markDoctrineTypeCommented($type); | ||
| } | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| // The following logic generates appropriate deprecation notices telling the user how to update their type configuration. | ||
| if ($typeConfig['commented']) { | ||
| if (! $requiresSQLCommentHint) { | ||
| @trigger_error( | ||
| sprintf( | ||
| 'The type "%s" was marked as commented in its configuration but not in the type itself. This is deprecated and will be removed in DoctrineBundle 2.0. Please update the return value of "%s::requiresSQLCommentHint()."', | ||
| $typeName, | ||
| get_class($type) | ||
| ), | ||
| E_USER_DEPRECATED | ||
| ); | ||
|
|
||
| $platform->markDoctrineTypeCommented($type); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| @trigger_error( | ||
| sprintf( | ||
| 'The type "%s" was explicitly marked as commented in its configuration. This is no longer necessary and will be removed in DoctrineBundle 2.0. Please remove the "commented" attribute from the type configuration.', | ||
| $typeName | ||
| ), | ||
| E_USER_DEPRECATED | ||
| ); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| if (! $requiresSQLCommentHint) { | ||
| continue; | ||
| } | ||
|
|
||
| @trigger_error( | ||
| sprintf( | ||
| 'The type "%s" was marked as uncommented in its configuration but commented in the type itself. This is deprecated and will be removed in DoctrineBundle 2.0. Please update the return value of "%s::requiresSQLCommentHint()" or remove the "commented" attribute from the type configuration.', | ||
| $typeName, | ||
| get_class($type) | ||
| ), | ||
| E_USER_DEPRECATED | ||
| ); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| namespace Doctrine\Bundle\DBALBundle; | ||
|
|
||
| use Doctrine\DBAL\Connection; | ||
|
|
||
| interface ConnectionRegistry | ||
dmaicher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /** | ||
| * Gets the default connection name. | ||
| * | ||
| * @return string The default connection name. | ||
| */ | ||
| public function getDefaultConnectionName() : string; | ||
|
|
||
| /** | ||
| * Gets the named connection. | ||
| * | ||
| * @param string $name The connection name (null for the default one). | ||
| */ | ||
| public function getConnection(?string $name = null) : Connection; | ||
|
|
||
| /** | ||
| * Gets an array of all registered connections. | ||
| * | ||
| * @return array<string, Connection> An array of Connection instances. | ||
| */ | ||
| public function getConnections() : array; | ||
|
|
||
| /** | ||
| * Gets all connection names. | ||
| * | ||
| * @return array<string> An array of connection names. | ||
| */ | ||
| public function getConnectionNames() : array; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.