SetupAclCommand.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Sonata 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 Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. use Symfony\Component\Console\Output\Output;
  15. use Sonata\AdminBundle\Util\AdminAclManipulatorInterface;
  16. class SetupAclCommand extends ContainerAwareCommand
  17. {
  18. /**
  19. * {@inheritDoc}
  20. */
  21. public function configure()
  22. {
  23. $this->setName('sonata:admin:setup-acl');
  24. $this->setDescription('Install ACL for Admin Classes');
  25. }
  26. /**
  27. * {@inheritDoc}
  28. */
  29. public function execute(InputInterface $input, OutputInterface $output)
  30. {
  31. $output->writeln('Starting ACL AdminBundle configuration');
  32. foreach ($this->getContainer()->get('sonata.admin.pool')->getAdminServiceIds() as $id) {
  33. try {
  34. $admin = $this->getContainer()->get($id);
  35. } catch (\Exception $e) {
  36. $output->writeln('<error>Warning : The admin class cannot be initiated from the command line</error>');
  37. $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
  38. continue;
  39. }
  40. $manipulator = $this->getContainer()->get('sonata.admin.manipulator.acl.admin');
  41. if (!$manipulator instanceof AdminAclManipulatorInterface) {
  42. $output->writeln(sprintf('The interface "AdminAclManipulatorInterface" is not implemented for %s: <info>ignoring</info>', get_class($manipulator)));
  43. continue;
  44. }
  45. $manipulator->configureAcls($output, $admin);
  46. }
  47. }
  48. }