SetupAclCommand.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Command;
  11. use Sonata\AdminBundle\Util\AdminAclManipulatorInterface;
  12. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. /**
  16. * Class SetupAclCommand.
  17. *
  18. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  19. */
  20. class SetupAclCommand extends ContainerAwareCommand
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function configure()
  26. {
  27. $this->setName('sonata:admin:setup-acl');
  28. $this->setDescription('Install ACL for Admin Classes');
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function execute(InputInterface $input, OutputInterface $output)
  34. {
  35. $output->writeln('Starting ACL AdminBundle configuration');
  36. foreach ($this->getContainer()->get('sonata.admin.pool')->getAdminServiceIds() as $id) {
  37. try {
  38. $admin = $this->getContainer()->get($id);
  39. } catch (\Exception $e) {
  40. $output->writeln('<error>Warning : The admin class cannot be initiated from the command line</error>');
  41. $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
  42. continue;
  43. }
  44. $manipulator = $this->getContainer()->get('sonata.admin.manipulator.acl.admin');
  45. if (!$manipulator instanceof AdminAclManipulatorInterface) {
  46. $output->writeln(sprintf('The interface "AdminAclManipulatorInterface" is not implemented for %s: <info>ignoring</info>', get_class($manipulator)));
  47. continue;
  48. }
  49. $manipulator->configureAcls($output, $admin);
  50. }
  51. }
  52. }