SetupAclCommand.php 1.9 KB

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