SetupAclCommand.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  17. */
  18. class SetupAclCommand extends ContainerAwareCommand
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function configure()
  24. {
  25. $this->setName('sonata:admin:setup-acl');
  26. $this->setDescription('Install ACL for Admin Classes');
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function execute(InputInterface $input, OutputInterface $output)
  32. {
  33. $output->writeln('Starting ACL AdminBundle configuration');
  34. foreach ($this->getContainer()->get('sonata.admin.pool')->getAdminServiceIds() as $id) {
  35. try {
  36. $admin = $this->getContainer()->get($id);
  37. } catch (\Exception $e) {
  38. $output->writeln('<error>Warning : The admin class cannot be initiated from the command line</error>');
  39. $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
  40. continue;
  41. }
  42. $manipulator = $this->getContainer()->get('sonata.admin.manipulator.acl.admin');
  43. if (!$manipulator instanceof AdminAclManipulatorInterface) {
  44. $output->writeln(sprintf(
  45. 'The interface "AdminAclManipulatorInterface" is not implemented for %s: <info>ignoring</info>',
  46. get_class($manipulator)
  47. ));
  48. continue;
  49. }
  50. $manipulator->configureAcls($output, $admin);
  51. }
  52. }
  53. }