Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed command and cs

  • Loading branch information...
commit 655b4600cafbb43e4cdea18cb46b4026bb8565b4 1 parent 24e62c9
Bilal Amarni bamarni authored
40 Doctrine/ODM/MongoDB/Symfony/TailableCursorBundle/Command/TailableCursorCommand.php
... ... @@ -1,19 +1,14 @@
1 1 <?php
2 2
3   -namespace Doctrine\ODM\MongoDB\Symfony\TailableCursorBundle\Command;
  3 +namespace Doctrine\Bundle\MongoDBTailableCursorBundle\Command;
4 4
5   -use Symfony\Bundle\FrameworkBundle\Command\Command;
  5 +use Doctrine\Bundle\MongoDBTailableCursorBundle\ProcessorInterface;
  6 +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6 7 use Symfony\Component\Console\Input\InputArgument;
7 8 use Symfony\Component\Console\Input\InputInterface;
8   -use Symfony\Component\Console\Input\InputOption;
9 9 use Symfony\Component\Console\Output\OutputInterface;
10   -use Symfony\Component\HttpFoundation\Request;
11   -use Doctrine\ODM\MongoDB\Symfony\TailableCursorBundle\ProcessorInterface;
12   -use ReflectionClass;
13   -use Exception;
14   -use InvalidArgumentException;
15 10
16   -class TailableCursorCommand extends Command
  11 +class TailableCursorCommand extends ContainerAwareCommand
17 12 {
18 13 protected function configure()
19 14 {
@@ -28,17 +23,17 @@ protected function configure()
28 23
29 24 protected function execute(InputInterface $input, OutputInterface $output)
30 25 {
31   - $dm = $this->container->get('doctrine.odm.mongodb.document_manager');
  26 + $dm = $this->getContainer()->get('doctrine.odm.mongodb.document_manager');
32 27 $repository = $dm->getRepository($input->getArgument('document'));
33   - $repositoryReflection = new ReflectionClass(get_class($repository));
  28 + $repositoryReflection = new \ReflectionClass(get_class($repository));
34 29 $documentReflection = $repository->getDocumentManager()->getMetadataFactory()->getMetadataFor($input->getArgument('document'))->getReflectionClass();
35   - $processor = $this->container->get($input->getArgument('processor'));
  30 + $processor = $this->getContainer()->get($input->getArgument('processor'));
36 31
37   - if ( ! $processor instanceof ProcessorInterface) {
38   - throw new InvalidArgumentException('A tailable cursor processor must implement the ProcessorInterface.');
  32 + if (!$processor instanceof ProcessorInterface) {
  33 + throw new \InvalidArgumentException('A tailable cursor processor must implement the ProcessorInterface.');
39 34 }
40 35
41   - $processorReflection = new ReflectionClass(get_class($processor));
  36 + $processorReflection = new \ReflectionClass(get_class($processor));
42 37 $method = $input->getArgument('finder');
43 38
44 39 $output->writeln(sprintf('Getting cursor for <info>%s</info> from <info>%s#%s</info>', $input->getArgument('document'), $repositoryReflection->getShortName(), $method));
@@ -46,12 +41,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
46 41
47 42 $cursor = $repository->$method();
48 43
49   - if (!count($cursor)) {
50   - $output->writeln('<comment>Nothing found, waiting to try again</comment>');
51   - }
52   -
53 44 while (true) {
54   - if ( ! $cursor->hasNext()) {
  45 + while (!$cursor->hasNext()) {
  46 + $output->writeln('<comment>Nothing found, waiting to try again</comment>');
55 47 // read all results so far, wait for more
56 48 sleep(10);
57 49 }
@@ -66,14 +58,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
66 58 $output->writeln(null);
67 59
68 60 try {
69   - $processor->process($output, $document);
70   - } catch (Exception $e) {
  61 + $processor->process($document);
  62 + } catch (\Exception $e) {
71 63 $output->writeln(sprintf('Error occurred while processing document: <error>%s</error>', $e->getMessage()));
72 64 continue;
73 65 }
74 66
75   - $dm->flush(array('safe' => true));
  67 + $dm->flush();
76 68 $dm->clear();
77 69 }
78 70 }
79   -}
  71 +}

0 comments on commit 655b460

Please sign in to comment.
Something went wrong with that request. Please try again.