1
1
Console Commands
2
2
================
3
3
4
- Doctrine MongoDB ODM offers some console commands to ease your development process:
4
+ Doctrine MongoDB ODM offers some console commands, which utilize Symfony2's
5
+ Console component, to ease your development process:
5
6
6
7
- ``odm:clear-cache:metadata `` - Clear all metadata cache of the various cache drivers.
7
8
- ``odm:query `` - Query mongodb and inspect the outputted results from your document classes.
@@ -11,45 +12,41 @@ Doctrine MongoDB ODM offers some console commands to ease your development proce
11
12
- ``odm:generate:repositories `` - Generate repository classes from your mapping information.
12
13
- ``odm:schema:create `` - Allows you to create databases, collections and indexes for your documents
13
14
- ``odm:schema:drop `` - Allows you to drop databases, collections and indexes for your documents
15
+ - ``odm:schema:update `` - Allows you to update indexes for your documents
14
16
15
- You can setup a console command easily with the following code. You just need an existing
16
- `` DocumentManager `` instance :
17
+ Provided you have an existing `` DocumentManager `` instance, you can setup a
18
+ console command easily with the following code :
17
19
18
20
.. code-block :: php
19
21
20
22
<?php
21
23
22
24
// mongodb.php
23
25
24
- // ...
26
+ // ... include Composer autoloader and configure DocumentManager instance
25
27
26
- $helpers = array(
27
- 'dm' => new Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper($dm),
28
- );
29
-
30
- $helperSet = isset($helperSet) ? $helperSet : new \Symfony\Component\Console\Helper\HelperSet();
31
- foreach ($helpers as $name => $helper) {
32
- $helperSet->set($helper, $name);
33
- }
28
+ $helperSet = \Symfony\Component\Console\Helper\HelperSet(array(
29
+ 'dm' => new \Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper($dm),
30
+ ));
34
31
35
- $cli = new \Symfony\Component\Console\Application('Doctrine ODM MongoDB Command Line Interface');
36
- $cli->setCatchExceptions(true);
37
- $cli->setHelperSet($helperSet);
38
- $cli->addCommands(array(
39
- new \Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand(),
32
+ $app = new Application('Doctrine MongoDB ODM');
33
+ $app->setHelperSet($helperSet);
34
+ $app->addCommands(array(
40
35
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateDocumentsCommand(),
41
- new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand(),
42
- new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand(),
43
36
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateHydratorsCommand(),
37
+ new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand(),
38
+ new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand(),
39
+ new \Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand(),
44
40
new \Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache\MetadataCommand(),
45
41
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\CreateCommand(),
46
- new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\UpdateCommand(),
47
42
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\DropCommand(),
43
+ new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\UpdateCommand(),
48
44
));
49
- $cli->run();
50
-
51
- Now you can run commands like the following:
52
45
53
- $ php mongodb.php odm:query User "{ username : 'jwage' }"
46
+ $app->run();
54
47
55
- The above would output the results from the query.
48
+ A reference implementation of the console command may be found in the
49
+ ``tools/sandbox `` directory of the project repository. That command is
50
+ configured to store generated hydrators and proxies in the same directory, and
51
+ relies on the main project's Composer dependencies. You will want to customize
52
+ its configuration files if you intend to use it in your own project.
0 commit comments