Ejemplo n.º 1
0
 /**
  * This method is executed after initialize(). It usually contains the logic
  * to execute to complete this command task.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $maxResults = $input->getOption('max-results');
     // Use ->findBy() instead of ->findAll() to allow result sorting and limiting
     $users = $this->em->getRepository('AppBundle:User')->findBy(array(), array('id' => 'DESC'), $maxResults);
     // Doctrine query returns an array of objects and we need an array of plain arrays
     $usersAsPlainArrays = array_map(function ($user) {
         return array($user->getId(), $user->getUsername(), $user->getEmail(), implode(', ', $user->getRoles()));
     }, $users);
     // In your console commands you should always use the regular output type,
     // which outputs contents directly in the console window. However, this
     // particular command uses the BufferedOutput type instead.
     // The reason is that the table displaying the list of users can be sent
     // via email if the '--send-to' option is provided. Instead of complicating
     // things, the BufferedOutput allows to get the command output and store
     // it in a variable before displaying it.
     $bufferedOutput = new BufferedOutput();
     $table = new Table($bufferedOutput);
     $table->setHeaders(array('ID', 'Username', 'Email', 'Roles'))->setRows($usersAsPlainArrays);
     $table->render();
     // instead of displaying the table of users, store it in a variable
     $tableContents = $bufferedOutput->fetch();
     if (null !== ($email = $input->getOption('send-to'))) {
         $this->sendReport($tableContents, $email);
     }
     $output->writeln($tableContents);
 }
 private function initialize()
 {
     if (!isset($this->manager)) {
         throw new Exception('No ObjectManager set');
     }
     $currencies = $this->manager->getRepository($this->currencyClass)->findAll();
     foreach ($currencies as $currency) {
         $this[$currency->getCode()] = $currency;
     }
 }
Ejemplo n.º 3
0
 /**
  * Load objects
  *
  * @throws RuntimeException
  * @throws Exception\InvalidRepositoryResultException
  * @return void
  */
 protected function loadObjects()
 {
     if (!empty($this->objects)) {
         return;
     }
     $findMethod = (array) $this->getFindMethod();
     if (!$findMethod) {
         $findMethodName = 'fetchAll';
         $objects = $this->tableCible->fetchAll();
     } else {
         if (!isset($findMethod['name'])) {
             throw new RuntimeException('No method name was set');
         }
         $findMethodName = $findMethod['name'];
         $findMethodParams = isset($findMethod['params']) ? array_change_key_case($findMethod['params']) : array();
         $repository = $this->serviceManager->getRepository($this->targetClass);
         if (!method_exists($repository, $findMethodName)) {
             throw new RuntimeException(sprintf('Method "%s" could not be found in repository "%s"', $findMethodName, get_class($repository)));
         }
         $r = new ReflectionMethod($repository, $findMethodName);
         $args = array();
         foreach ($r->getParameters() as $param) {
             if (array_key_exists(strtolower($param->getName()), $findMethodParams)) {
                 $args[] = $findMethodParams[strtolower($param->getName())];
             } elseif ($param->isDefaultValueAvailable()) {
                 $args[] = $param->getDefaultValue();
             } elseif (!$param->isOptional()) {
                 throw new RuntimeException(sprintf('Required parameter "%s" with no default value for method "%s" in repository "%s"' . ' was not provided', $param->getName(), $findMethodName, get_class($repository)));
             }
         }
         $objects = $r->invokeArgs($repository, $args);
     }
     GuardUtils::guardForArrayOrTraversable($objects, sprintf('%s::%s() return value', $this->targetClass, $findMethodName), 'DoctrineModule\\Form\\Element\\Exception\\InvalidRepositoryResultException');
     $this->objects = $objects;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getRepository($className)
 {
     return $this->wrapped->getRepository($className);
 }
Ejemplo n.º 5
0
 public function getInputFilterSpecification()
 {
     return array('controlId' => array('required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'DoctrineModule\\Validator\\NoObjectExists', 'options' => array('object_repository' => $this->objectManager->getRepository('GDI\\Entity\\TProduct'), 'fields' => 'controlId')))), 'eArtworkSpDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'rArtworkSpDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'eGslickDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'rGslickDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'eDemoDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'rDemoDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'eMovieDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'rMovieDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'eArtworkTrDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'rArtworkTrDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'eWebsiteDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'rWebsiteDate' => array('required' => false, 'validators' => array(array('name' => 'Date'))), 'isReturnDemo' => array('required' => false, 'validators' => array()), 'gameImagePass' => array('required' => false, 'type' => 'Zend\\InputFilter\\FileInput', 'filters' => array(array('name' => "Zend\\Filter\\File\\RenameUpload", 'options' => array('target' => "./data/uploads/", 'randomize' => true, 'use_upload_name' => true, 'use_upload_extension' => true)), array('name' => 'filelowercase')), 'validators' => array(array('name' => 'File\\IsImage'))), 'isDeleted' => array('required' => false, 'validators' => array()), 'createUserId' => array('required' => false, 'validators' => array()), 'updateUserId' => array('required' => false, 'validators' => array()), 'createTime' => array('required' => false, 'validators' => array()));
     // filter and validation here
 }