Skip to content

Commit a019fff

Browse files
committed
Revise console application and documentation
Replace trivial odm:query example with an explanation of where to find the reference implementation and how to proceed with configuration.
1 parent 7a8c7fa commit a019fff

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Console Commands
22
================
33

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:
56

67
- ``odm:clear-cache:metadata`` - Clear all metadata cache of the various cache drivers.
78
- ``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
1112
- ``odm:generate:repositories`` - Generate repository classes from your mapping information.
1213
- ``odm:schema:create`` - Allows you to create databases, collections and indexes for your documents
1314
- ``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
1416

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:
1719

1820
.. code-block:: php
1921
2022
<?php
2123
2224
// mongodb.php
2325
24-
// ...
26+
// ... include Composer autoloader and configure DocumentManager instance
2527
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+
));
3431
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(
4035
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(),
4336
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(),
4440
new \Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache\MetadataCommand(),
4541
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\CreateCommand(),
46-
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\UpdateCommand(),
4742
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\DropCommand(),
43+
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\UpdateCommand(),
4844
));
49-
$cli->run();
50-
51-
Now you can run commands like the following:
5245
53-
$ php mongodb.php odm:query User "{ username : 'jwage' }"
46+
$app->run();
5447
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.

tools/sandbox/mongodb.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?php
22

3-
use Symfony\Component\Console\Application;
4-
53
require __DIR__ . '/cli-config.php';
64

7-
$app = new Application('Doctrine MongoDB ODM');
5+
$app = new \Symfony\Component\Console\Application('Doctrine MongoDB ODM');
86

97
if (isset($helperSet)) {
108
$app->setHelperSet($helperSet);
119
}
1210

1311
$app->addCommands(array(
14-
new \Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand(),
1512
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateDocumentsCommand(),
16-
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand(),
17-
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand(),
1813
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateHydratorsCommand(),
14+
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand(),
15+
new \Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand(),
16+
new \Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand(),
17+
new \Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache\MetadataCommand(),
1918
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\CreateCommand(),
2019
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\DropCommand(),
2120
new \Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\UpdateCommand(),

0 commit comments

Comments
 (0)