Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
crayner committed Oct 30, 2018
2 parents 21a96cf + d57c1a3 commit eb77097
Show file tree
Hide file tree
Showing 49 changed files with 604 additions and 335 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ jobs:
- php: 7.1
env: stability=RC SYMFONY_DEPRECATIONS_HELPER=weak SYMFONY_VERSION="3.4.*"
install:
- composer config minimum-stability RC
- travis_retry composer update -n --prefer-dist

- php: 7.1
env: stability=dev SYMFONY_DEPRECATIONS_HELPER=weak SYMFONY_VERSION="4.1.*"
install:
- composer require --dev "symfony/messenger" --no-update
- travis_retry composer update -n --prefer-dist

- php: 7.2
Expand All @@ -58,7 +63,7 @@ jobs:
env: CODING_STANDARDS
php: 7.1
install:
- travis_retry composer require -n --prefer-dist --dev doctrine/coding-standard:^4.0
- travis_retry composer require -n --prefer-dist --dev doctrine/coding-standard:^5.0
script:
- ./vendor/bin/phpcs

Expand Down
10 changes: 6 additions & 4 deletions Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\DriverManager;
use Exception;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Database tool allows you to easily drop and create your configured databases.
* Database tool allows you to easily create your configured databases.
*/
class CreateDatabaseDoctrineCommand extends DoctrineCommand
{
Expand Down Expand Up @@ -41,7 +43,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$connectionName = $input->getOption('connection');
if (empty($connectionName) === true) {
if (empty($connectionName)) {
$connectionName = $this->getContainer()->get('doctrine')->getDefaultConnectionName();
}
$connection = $this->getDoctrineConnection($connectionName);
Expand Down Expand Up @@ -75,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$hasPath = isset($params['path']);
$name = $hasPath ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
if (! $name) {
throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created.");
}
// Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url
unset($params['dbname'], $params['path'], $params['url']);
Expand All @@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tmpConnection->getSchemaManager()->createDatabase($name);
$output->writeln(sprintf('<info>Created database <comment>%s</comment> for connection named <comment>%s</comment></info>', $name, $connectionName));
}
} catch (\Exception $e) {
} catch (Exception $e) {
$output->writeln(sprintf('<error>Could not create database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
$error = true;
Expand Down
5 changes: 3 additions & 2 deletions Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\EntityGenerator;
use LogicException;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;

/**
Expand Down Expand Up @@ -35,7 +36,7 @@ protected function getEntityGenerator()
* Get a doctrine entity manager by symfony name.
*
* @param string $name
* @param null|int $shardId
* @param int|null $shardId
*
* @return EntityManager
*/
Expand All @@ -45,7 +46,7 @@ protected function getEntityManager($name, $shardId = null)

if ($shardId) {
if (! $manager->getConnection() instanceof PoolingShardConnection) {
throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $name));
throw new LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $name));
}

$manager->getConnection()->connect($shardId);
Expand Down
27 changes: 17 additions & 10 deletions Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\DriverManager;
use Exception;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Database tool allows you to easily drop and create your configured databases.
* Database tool allows you to easily drop your configured databases.
*/
class DropDatabaseDoctrineCommand extends DoctrineCommand
{
Expand All @@ -24,8 +26,8 @@ protected function configure()
$this
->setName('doctrine:database:drop')
->setDescription('Drops the configured database')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
->addOption('if-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database doesn\'t exist')
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action')
->setHelp(<<<EOT
Expand All @@ -49,8 +51,13 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$connection = $this->getDoctrineConnection($input->getOption('connection'));
$ifExists = $input->getOption('if-exists');
$connectionName = $input->getOption('connection');
if (empty($connectionName)) {
$connectionName = $this->getContainer()->get('doctrine')->getDefaultConnectionName();
}
$connection = $this->getDoctrineConnection($connectionName);

$ifExists = $input->getOption('if-exists');

$params = $connection->getParams();
if (isset($params['master'])) {
Expand All @@ -75,14 +82,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

$name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
if (! $name) {
throw new \InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
}
unset($params['dbname'], $params['url']);

if (! $input->getOption('force')) {
$output->writeln('<error>ATTENTION:</error> This operation should not be executed in a production environment.');
$output->writeln('');
$output->writeln(sprintf('<info>Would drop the database named <comment>%s</comment>.</info>', $name));
$output->writeln(sprintf('<info>Would drop the database <comment>%s</comment> for connection named <comment>%s</comment>.</info>', $name, $connectionName));
$output->writeln('Please run the operation with --force to execute');
$output->writeln('<error>All data will be lost!</error>');

Expand All @@ -103,12 +110,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
if ($shouldDropDatabase) {
$connection->getSchemaManager()->dropDatabase($name);
$output->writeln(sprintf('<info>Dropped database for connection named <comment>%s</comment></info>', $name));
$output->writeln(sprintf('<info>Dropped database <comment>%s</comment> for connection named <comment>%s</comment></info>', $name, $connectionName));
} else {
$output->writeln(sprintf('<info>Database for connection named <comment>%s</comment> doesn\'t exist. Skipped.</info>', $name));
$output->writeln(sprintf('<info>Database <comment>%s</comment> for connection named <comment>%s</comment> doesn\'t exist. Skipped.</info>', $name, $connectionName));
}
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Could not drop database for connection named <comment>%s</comment></error>', $name));
} catch (Exception $e) {
$output->writeln(sprintf('<error>Could not drop database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName));
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));

return self::RETURN_CODE_NOT_DROP;
Expand Down
6 changes: 4 additions & 2 deletions Command/GenerateEntitiesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
use Doctrine\ORM\Tools\EntityRepositoryGenerator;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -86,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
$metadata = $manager->getBundleMetadata($bundle);
} catch (\InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
$name = strtr($input->getArgument('name'), '/', '\\');
$pos = strpos($name, ':');

Expand Down Expand Up @@ -117,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
try {
$entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
// fall back to the bundle metadata when no entity class could be found
$entityMetadata = $metadata;
}
Expand Down
5 changes: 3 additions & 2 deletions Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\ORM\Tools\Console\MetadataFilter;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function configure()
Generate annotation mappings into the src/ directory using App as the namespace:
<info>php %command.full_name% App\\\Entity annotation --path=src/Entity</info>
Generate annotation mappings into the config/doctrine/ directory using App as the namespace:
Generate xml mappings into the config/doctrine/ directory using App as the namespace:
<info>php %command.full_name% App\\\Entity xml --path=config/doctrine</info>
Generate XML mappings into a bundle:
Expand Down Expand Up @@ -89,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$namespace = $namespaceOrBundle;
$destPath = $input->getOption('path');
if ($destPath === null) {
throw new \InvalidArgumentException('The --path option is required when passing a namespace (e.g. --path=src). If you intended to pass a bundle name, check your spelling.');
throw new InvalidArgumentException('The --path option is required when passing a namespace (e.g. --path=src). If you intended to pass a bundle name, check your spelling.');
}
}

Expand Down
3 changes: 2 additions & 1 deletion Command/Proxy/DelegateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;

use Doctrine\ORM\Version;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function isEnabled()
protected function wrapCommand($entityManagerName)
{
if (! $this->isVersionCompatible()) {
throw new \RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion()));
throw new RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion()));
}

DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $entityManagerName);
Expand Down
2 changes: 1 addition & 1 deletion ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function createConnection(array $params, Configuration $config = null, Ev
* and the platform version is unknown.
* For details have a look at DoctrineBundle issue #673.
*
*
* @return AbstractPlatform
*
* @throws DBALException
*/
private function getDatabasePlatform(Connection $connection)
Expand Down
8 changes: 5 additions & 3 deletions Controller/ProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Exception;
use PDO;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -61,7 +63,7 @@ public function explainAction($token, $connectionName, $query)
} else {
$results = $this->explainOtherPlatform($connection, $query);
}
} catch (\Exception $e) {
} catch (Exception $e) {
return new Response('This query cannot be explained.');
}

Expand All @@ -87,7 +89,7 @@ private function explainSQLServerPlatform(Connection $connection, $query)

$stmt = $connection->executeQuery($sql, $params, $query['types']);
$stmt->nextRowset();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

private function explainOtherPlatform(Connection $connection, $query)
Expand All @@ -99,6 +101,6 @@ private function explainOtherPlatform(Connection $connection, $query)
}

return $connection->executeQuery('EXPLAIN ' . $query['sql'], $params, $query['types'])
->fetchAll(\PDO::FETCH_ASSOC);
->fetchAll(PDO::FETCH_ASSOC);
}
}
12 changes: 8 additions & 4 deletions DataCollector/DoctrineDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use Doctrine\ORM\Cache\Logging\CacheLoggerChain;
use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\ORM\Version;
use Exception;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector as BaseCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -37,7 +40,7 @@ public function __construct(ManagerRegistry $registry)
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, Exception $exception = null)
{
parent::collect($request, $response, $exception);

Expand All @@ -58,13 +61,14 @@ public function collect(Request $request, Response $response, \Exception $except
],
];

/** @var EntityManager $em */
foreach ($this->registry->getManagers() as $name => $em) {
$entities[$name] = [];
/** @var ClassMetadataFactory $factory */
$factory = $em->getMetadataFactory();
$validator = new SchemaValidator($em);

/** @var $class \Doctrine\ORM\Mapping\ClassMetadataInfo */
/** @var ClassMetadataInfo $class */
foreach ($factory->getLoadedMetadata() as $class) {
if (isset($entities[$name][$class->getName()])) {
continue;
Expand Down Expand Up @@ -224,11 +228,11 @@ public function getGroupedQueries()
$connectionGroupedQueries[$key]['count']++;
$totalExecutionMS += $query['executionMS'];
}
usort($connectionGroupedQueries, function ($a, $b) {
usort($connectionGroupedQueries, static function ($a, $b) {
if ($a['executionMS'] === $b['executionMS']) {
return 0;
}
return ($a['executionMS'] < $b['executionMS']) ? 1 : -1;
return $a['executionMS'] < $b['executionMS'] ? 1 : -1;
});
$this->groupedQueries[$connection] = $connectionGroupedQueries;
}
Expand Down
27 changes: 27 additions & 0 deletions DependencyInjection/Compiler/MessengerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Messenger\MessageBusInterface;

/**
* Class for Symfony Messenger component integrations
*/
class MessengerPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasAlias('message_bus') && is_subclass_of($container->findDefinition('message_bus')->getClass(), MessageBusInterface::class)) {
return;
}

// Remove wired services if the Messenger component actually isn't enabled:
$container->removeDefinition('doctrine.orm.messenger.middleware_factory.transaction');
$container->removeDefinition('messenger.middleware.doctrine_transaction_middleware');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function process(ContainerBuilder $container)
return;
}

$repoReferences = array_map(function ($id) {
$repoReferences = array_map(static function ($id) {
return new Reference($id);
}, $repoServiceIds);

Expand Down

0 comments on commit eb77097

Please sign in to comment.