1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Doctrine MongoDBBundle |
5
|
|
|
* |
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* (c) Doctrine Project |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Saxulum\DoctrineMongodbOdmCommands\Command; |
16
|
|
|
|
17
|
|
|
use Doctrine\ODM\MongoDB\Tools\DocumentGenerator; |
18
|
|
|
use Symfony\Component\Console\Command\Command; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Base class for Doctrine ODM console commands to extend. |
22
|
|
|
* |
23
|
|
|
* @author Justin Hileman <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
abstract class DoctrineODMCommand extends Command |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @return DocumentGenerator |
29
|
|
|
*/ |
30
|
|
|
protected function getDocumentGenerator() |
31
|
|
|
{ |
32
|
|
|
$documentGenerator = new DocumentGenerator(); |
33
|
|
|
$documentGenerator->setGenerateAnnotations(false); |
34
|
|
|
$documentGenerator->setGenerateStubMethods(true); |
35
|
|
|
$documentGenerator->setRegenerateDocumentIfExists(false); |
36
|
|
|
$documentGenerator->setUpdateDocumentIfExists(true); |
37
|
|
|
$documentGenerator->setNumSpaces(4); |
38
|
|
|
|
39
|
|
|
return $documentGenerator; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get a doctrine document manager by symfony name. |
44
|
|
|
* |
45
|
|
|
* @param string $name |
46
|
|
|
* |
47
|
|
|
* @return \Doctrine\ODM\MongoDB\Tools\DocumentGenerator |
48
|
|
|
*/ |
49
|
|
|
protected function getDocumentManager($name) |
50
|
|
|
{ |
51
|
|
|
$helperSet = $this->getHelperSet(); |
52
|
|
|
|
53
|
|
|
return $helperSet->get('doctrine_mongodb')->getManager($name); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get a doctrine document manager by symfony name. |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
protected function getDefaultManagerName() |
62
|
|
|
{ |
63
|
|
|
$helperSet = $this->getHelperSet(); |
64
|
|
|
|
65
|
|
|
return $helperSet->get('doctrine_mongodb')->getDefaultManagerName(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get a doctrine dbal connection by symfony name. |
71
|
|
|
* |
72
|
|
|
* @param string $name |
73
|
|
|
* |
74
|
|
|
* @return \Doctrine\MongoDB\Connection |
75
|
|
|
*/ |
76
|
|
|
protected function getDoctrineConnection($name) |
77
|
|
|
{ |
78
|
|
|
$helperSet = $this->getHelperSet(); |
79
|
|
|
|
80
|
|
|
return $helperSet->get('doctrine_mongodb')->getConnection($name); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|