Completed
Push — develop ( 2414e2...dd754c )
by Novikov
02:47
created

MongoInitCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Sleepness\UberTranslationBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Initialize environment for storing translations in MongoDB
11
 *
12
 * @author Viktor Novikov <[email protected]>
13
 */
14
class MongoInitCommand extends ContainerAwareCommand
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('uber:translations:mongo:init')
23
            ->setDefinition(array())
24
            ->setDescription('Create mongo database for storing translations')
25
            ->setHelp("
26
The <info>uber:translations:mongo:init</info> command create new database in Mongo for storing translations:
27
28
  <info>./app/console uber:translations:mongo:init</info>
29
30
Command example:
31
32
  <info>./app/console uber:translations:mongo:init</info>
33
34
            ");
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        try {
43
            $mongoClient = new \MongoClient();
44
            $database = new \MongoDB($mongoClient, 'uber_translations');
45
            $database->execute('"foo";'); // perform interaction to persist database
46
47
            $output->writeln("\e[37;42m Database 'uber_translations' successfully created \e[0m");
48
        } catch (\Exception $exception) {
49
            $output->writeln(sprintf("\e[37;43m %s \e[0m", $exception->getMessage()));
50
        }
51
    }
52
}
53