|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the symfony package. |
| 5 | + * (c) Fabien Potencier <[email protected]> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * Associates a sfGuard group with a permission. |
| 13 | + * |
| 14 | + * @package symfony |
| 15 | + * @subpackage task |
| 16 | + * @author Emanuele Panzeri <[email protected]> |
| 17 | + */ |
| 18 | +class sfGuardGroupPermissionListTask extends sfBaseTask |
| 19 | +{ |
| 20 | + protected function configure() |
| 21 | + { |
| 22 | + $this->addArguments(array( |
| 23 | + new sfCommandArgument('group', sfCommandArgument::REQUIRED, 'The group name'), |
| 24 | + )); |
| 25 | + |
| 26 | + $this->addOptions(array( |
| 27 | + new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), |
| 28 | + new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), |
| 29 | + )); |
| 30 | + |
| 31 | + $this->namespace = 'guard'; |
| 32 | + $this->name = 'group:permission-list'; |
| 33 | + $this->briefDescription = 'List the group permissions'; |
| 34 | + } |
| 35 | + |
| 36 | + protected function execute($arguments = array(), $options = array()) |
| 37 | + { |
| 38 | + $databaseManager = new sfDatabaseManager($this->configuration); |
| 39 | + |
| 40 | + /** @var sfGuardGroup $group */ |
| 41 | + $group = Doctrine_Core::getTable('sfGuardGroup')->findOneByName($arguments['group']); |
| 42 | + if (!$group) { |
| 43 | + $this->logSection('guard', sprintf('Group "%s" not found!', $arguments['group']), null, 'ERROR'); |
| 44 | + return -1; |
| 45 | + } |
| 46 | + |
| 47 | + $this->logSection('guard', sprintf('Listing permissions for Group "%s"', $group->getName())); |
| 48 | + |
| 49 | + /** @var sfGuardPermission $permission */ |
| 50 | + foreach ($group->getPermissions() as $permission) { |
| 51 | + $this->logSection('guard', sprintf(' - %s', $permission->getName())); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments