SetupAclCommand.php 2.0 KB

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