Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add guard:group:list task
  • Loading branch information
thePanz committed Jan 17, 2018
commit 0f9000f9d8b11044fb003262ad8b0bc1e709ac85
77 changes: 77 additions & 0 deletions lib/task/sfGuardGroupListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Lists sfGuard groups.
*
* @package symfony
* @subpackage task
* @author Fabien Potencier <[email protected]>
* @version SVN: $Id$
*/
class sfGuardGroupListTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
));

$this->addOptions(array(
new sfCommandOption('with-perm', null, sfCommandOption::PARAMETER_NONE, 'Join with Permissions'),
new sfCommandOption('with-users', null, sfCommandOption::PARAMETER_NONE, 'Join with Users'),
));

$this->namespace = 'guard';
$this->name = 'group:list';
$this->briefDescription = 'List groups';

$this->detailedDescription = <<<EOF
The [guard:group:list|INFO] list groups:

[./symfony guard:group:list|INFO]
EOF;
}

/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);

$groupTable = Doctrine_Core::getTable('sfGuardGroup');

$groups = $groupTable->findAll();

$this->logSection('guard', sprintf('Found %d Groups', $groups->count()));

/** @var sfGuardGroup $group */
foreach($groups as $group) {
$this->logSection('guard', sprintf('%d : %s', $group->getPrimaryKey(), $group->getName()));

if ($options['with-perm']) {
/** @var sfGuardPermission $permission */
foreach ($group->getPermissions() as $permission) {
$this->logSection('guard', sprintf(' - Permission: %s', $permission->getName()));
}
}
}
if ($options['with-users']) {
/** @var sfGuardUser $user */
foreach ($group->getUsers() as $user) {
$this->logSection('guard', sprintf(' - User %d: %s', $user->getPrimaryKey(), $user->getName()));
}
}

}
}