1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Doctrine Bundle |
5
|
|
|
* |
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* (c) Doctrine Project, Benjamin Eberlei <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
namespace Saxulum\DoctrineMongodbOdmCommands\Command; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
17
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
18
|
|
|
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper; |
19
|
|
|
use Symfony\Component\Console\Application; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles |
23
|
|
|
* and multiple connections/entity managers. |
24
|
|
|
* |
25
|
|
|
* @author Fabien Potencier <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
abstract class DoctrineCommandHelper |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Convenience method to push the helper sets of a given entity manager into the application. |
31
|
|
|
* @param Application|null $application |
32
|
|
|
* @param string $dmName |
33
|
|
|
* @throws \InvalidArgumentException |
34
|
|
|
*/ |
35
|
|
|
public static function setApplicationDocumentManager(Application $application = null, $dmName) |
36
|
|
|
{ |
37
|
|
|
if (is_null($application)) { |
38
|
|
|
throw new \InvalidArgumentException('Application instance needed!'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$helperSet = $application->getHelperSet(); |
42
|
|
|
|
43
|
|
|
/** @var ManagerRegistry $doctrine */ |
44
|
|
|
$doctrine = $helperSet->get('doctrine_mongodb'); |
45
|
|
|
|
46
|
|
|
/** @var DocumentManager $dm */ |
47
|
|
|
$dm = $doctrine->getManager($dmName); |
48
|
|
|
|
49
|
|
|
$helperSet->set(new DocumentManagerHelper($dm), 'dm'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|