GenerateGroupsCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
	namespace Vivait\AuthBundle\Command;
4
5
	use Vivait\AuthBundle\Entity\Group;
6
	use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
	use Symfony\Component\Console\Input\InputInterface;
8
	use Symfony\Component\Console\Output\OutputInterface;
9
10
	class GenerateGroupsCommand extends ContainerAwareCommand {
11
12
		protected function configure() {
13
			$this
14
				->setName('auth:role:generate')
15
				->setDescription('Creates the standard set of roles into the database');
16
		}
17
18
19
		protected function execute(InputInterface $input, OutputInterface $output) {
20
			$em = $this->getContainer()->get('doctrine')->getManager();
21
			$array = array(
22
				array('ROLE_USER','User'),
23
				array('ROLE_ADMIN','Administrator'),
24
				array('ROLE_SUPER_ADMIN','Super Administrator'),
25
			);
26
27
			foreach($array as $row) {
28
				$obj = new Group();
29
				$obj->setRole($row[0]);
30
				$obj->setName($row[1]);
31
				$em->persist($obj);
32
				$output->writeln(sprintf('%s (%s), ', $obj->getRole(), $obj->getName()));
33
			}
34
			$em->flush();
35
36
			$output->writeln(sprintf('Created %s built-in groups/roles, ', count($array)));
37
		}
38
	}