Skip to content

Commit

Permalink
Actualize
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Apr 29, 2023
1 parent 432476c commit 29cc6cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 67 deletions.
20 changes: 20 additions & 0 deletions src/Command/RbacDbInit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Rbac\Db\Command;

/**
* Command for creating RBAC related database tables using Yii Database.
*/
final class RbacDbInit extends \Yiisoft\Rbac\Command\RbacDbInit
{
protected static $defaultName = 'rbac/db/init';

protected function configure(): void
{
parent::configure();

$this->setHelp('This command creates schemas for RBAC using Yii Database');

Check warning on line 18 in src/Command/RbacDbInit.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ protected function configure() : void { parent::configure(); - $this->setHelp('This command creates schemas for RBAC using Yii Database'); + } }
}
}
70 changes: 4 additions & 66 deletions src/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,11 @@
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Sqlite\Column;
use Yiisoft\Rbac\SchemaManagerInterface;
use Yiisoft\Rbac\SchemaManagerTrait;

final class SchemaManager implements SchemaManagerInterface
{
/**
* @var string A name of the table for storing RBAC items (roles and permissions).
* @psalm-var non-empty-string
*/
private string $itemsTable;
/**
* @var string A name of the table for storing RBAC assignments.
* @psalm-var non-empty-string
*/
private string $assignmentsTable;
/**
* @var string A name of the table for storing relations between RBAC items.
* @psalm-var non-empty-string
*/
private string $itemsChildrenTable;
use SchemaManagerTrait;

/**
* @param string $itemsTable A name of the table for storing RBAC items (roles and permissions).
Expand All @@ -43,23 +30,7 @@ public function __construct(
private ConnectionInterface $database,
string|null $itemsChildrenTable = null,
) {
if ($itemsTable === '') {
throw new InvalidArgumentException('Items table name can\'t be empty.');
}

$this->itemsTable = $itemsTable;

if ($assignmentsTable === '') {
throw new InvalidArgumentException('Assignments table name can\'t be empty.');
}

$this->assignmentsTable = $assignmentsTable;

if ($itemsChildrenTable === '') {
throw new InvalidArgumentException('Items children table name can\'t be empty.');
}

$this->itemsChildrenTable = $itemsChildrenTable ?? $this->itemsTable . '_child';
$this->initTables($itemsTable, $assignmentsTable, $itemsChildrenTable);
}

/**
Expand Down Expand Up @@ -137,7 +108,7 @@ public function createAssignmentsTable(): void
->execute();
}

public function tableExists(string $tableName): bool
public function hasTable(string $tableName): bool
{
return $this->database->getSchema()->getTableSchema($tableName) !== null;
}
Expand All @@ -146,37 +117,4 @@ public function dropTable(string $tableName): void
{
$this->database->createCommand()->dropTable($tableName)->execute();
}

public function createAll(bool $force = true): void
{
if ($force === true) {
$this->dropAll();
}

$this->createItemsTable();
$this->createItemsChildrenTable();
$this->createAssignmentsTable();
}

public function dropAll(): void
{
$this->dropTable($this->itemsChildrenTable);
$this->dropTable($this->assignmentsTable);
$this->dropTable($this->itemsTable);
}

public function getItemsTable(): string
{
return $this->itemsTable;
}

public function getAssignmentsTable(): string
{
return $this->assignmentsTable;
}

public function getItemsChildrenTable(): string
{
return $this->itemsChildrenTable;
}
}
2 changes: 1 addition & 1 deletion tests/Base/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Rbac\Command\RbacDbInit;
use Yiisoft\Rbac\Db\Command\RbacDbInit;
use Yiisoft\Rbac\Db\SchemaManager;

abstract class TestCase extends \PHPUnit\Framework\TestCase
Expand Down

0 comments on commit 29cc6cf

Please sign in to comment.