src/Kunstmaan/AdminBundle/Command/CreateGroupCommand.php
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (null === $this->em) {
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
        }

        $groupName = $input->getArgument('group');
        $roleNames = $input->getOption('role');
        $group = new Group($groupName);

        if (!empty($roleNames)) {
            // Roles were provided, so attach them to the group
            $roleNames = explode(',', strtoupper($roleNames));
            foreach ($roleNames as $roleName) {
                if ('ROLE_' != substr($roleName, 0, 5)) {
                    $roleName = 'ROLE_' . $roleName;
                }
                /* @var Role $role */
                $role = $this->em->getRepository('KunstmaanAdminBundle:Role')->findOneBy(array('role' => $roleName));
                $group->addRole($role);
            }
        }
        $this->em->persist($group);
        $this->em->flush();

        $output->writeln(sprintf('Created group <comment>%s</comment>', $groupName));
    }
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (null === $this->em) {
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
        }

        $groupName = $input->getArgument('group');
        $roleNames = $input->getOption('role');
        $group = new Group($groupName);

        if (!empty($roleNames)) {
            // Roles were provided, so attach them to the group
            $roleNames = explode(',', strtoupper($roleNames));
            foreach ($roleNames as $roleName) {
                if ('ROLE_' != substr($roleName, 0, 5)) {
                    $roleName = 'ROLE_' . $roleName;
                }
                /* @var Role $role */
                $role = $this->em->getRepository('KunstmaanAdminBundle:Role')->findOneBy(array('role' => $roleName));
                $group->addRole($role);
            }
        }
        $this->em->persist($group);
        $this->em->flush();

        $output->writeln(sprintf('Created group <comment>%s</comment>', $groupName));
    }
protected function execute ( InputInterface $ input , OutputInterface $ output ) { if ( null === $ this -> em ) { $ this -> em = $ this -> getContainer ( ) -> get ( 'doctrine.orm.entity_manager' ) ; } $ groupName = $ input -> getArgument ( 'group' ) ; $ roleNames = $ input -> getOption ( 'role' ) ; $ group = new Group ( $ groupName ) ; if ( ! empty ( $ roleNames ) ) { // Roles were provided, so attach them to the group $ roleNames = explode ( ',' , strtoupper ( $ roleNames ) ) ; foreach ( $ roleNames as $ roleName ) { if ( 'ROLE_' != substr ( $ roleName , 0 , 5 ) ) { $ roleName = 'ROLE_' . $ roleName ; } /* @var Role $role */ $ role = $ this -> em -> getRepository ( 'KunstmaanAdminBundle:Role' ) -> findOneBy ( array ( 'role' => $ roleName ) ) ; $ group -> addRole ( $ role ) ; } } $ this -> em -> persist ( $ group ) ; $ this -> em -> flush ( ) ; $ output -> writeln ( sprintf ( 'Created group <comment>%s</comment>' , $ groupName ) ) ; }
Executes the current command

@param InputInterface  $input  The input
@param OutputInterface $output The output

@return int
Executes the current command