DoctrineCommandHelper::setApplicationConnection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
4
5
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
8
use Symfony\Bundle\FrameworkBundle\Console\Application;
9
10
/**
11
 * Provides some helper and convenience methods to configure doctrine commands in the context of bundles
12
 * and multiple connections/entity managers.
13
 */
14
abstract class DoctrineCommandHelper
15
{
16
    /**
17
     * Convenience method to push the helper sets of a given entity manager into the application.
18
     *
19
     * @param string $emName
20
     */
21
    public static function setApplicationEntityManager(Application $application, $emName)
22
    {
23
        /** @var EntityManager $em */
24
        $em        = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
25
        $helperSet = $application->getHelperSet();
26
        $helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\DBAL\Tools\Cons...Helper\ConnectionHelper has been deprecated with message: use a ConnectionProvider instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
27
        $helperSet->set(new EntityManagerHelper($em), 'em');
28
    }
29
30
    /**
31
     * Convenience method to push the helper sets of a given connection into the application.
32
     *
33
     * @param string $connName
34
     */
35
    public static function setApplicationConnection(Application $application, $connName)
36
    {
37
        $connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName);
38
        $helperSet  = $application->getHelperSet();
39
        $helperSet->set(new ConnectionHelper($connection), 'db');
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\DBAL\Tools\Cons...Helper\ConnectionHelper has been deprecated with message: use a ConnectionProvider instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
40
    }
41
}
42