Commit c68e5f1f by Alexander Makarov

Adjusted naming

parent bb01c1cc
......@@ -123,7 +123,7 @@ Yii Framework 2 Change Log
- Enh #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
- Enh #4072: `\yii\rbac\PhpManager` adjustments (samdark)
- Data is now stored in three separate files for items, assignments and rules. File format is simpler.
- Removed `authFile`. Added `itemsFile`, `assignmentsFile` and `rulesFile`.
- Removed `authFile`. Added `itemFile`, `assignmentFile` and `ruleFile`.
- `createdAt` and `updatedAt` are now properly filled with corresponding file modification time.
- `save()` and `load()` are now protected instead of public.
- Added unit test for saving and loading data.
......
......@@ -79,9 +79,9 @@ new ones save the following code as `convert.php` that should be placed in the s
```php
<?php
$oldFile = 'rbac.php';
$itemsFile = 'rbac-items.php';
$assignmentsFile = 'rbac-assignments.php';
$rulesFile = 'rbac-rules.php';
$itemsFile = 'items.php';
$assignmentsFile = 'assignments.php';
$rulesFile = 'rules.php';
$oldData = include $oldFile;
......@@ -119,7 +119,7 @@ echo "Done!\n";
```
Run it once, delete `rbac.php`. If you've configured `authFile` property, remove the line from config and instead
configure `itemsFile`, `assignmentsFile` and `rulesFile`.
configure `itemFile`, `assignmentFile` and `ruleFile`.
* Static helper `yii\helpers\Security` has been converted into an application component. You should change all usage of
its methods to a new syntax, for example: instead of `yii\helpers\Security::hashData()` use `Yii::$app->getSecurity()->hashData()`.
......
......@@ -38,7 +38,7 @@ class PhpManager extends BaseManager
* @see loadFromFile()
* @see saveToFile()
*/
public $itemsFile = '@app/data/rbac-items.php';
public $itemFile = '@app/rbac/items.php';
/**
* @var string the path of the PHP script that contains the authorization assignments.
* This can be either a file path or a path alias to the file.
......@@ -46,7 +46,7 @@ class PhpManager extends BaseManager
* @see loadFromFile()
* @see saveToFile()
*/
public $assignmentsFile = '@app/data/rbac-assignments.php';
public $assignmentFile = '@app/rbac/assignments.php';
/**
* @var string the path of the PHP script that contains the authorization rules.
......@@ -55,7 +55,7 @@ class PhpManager extends BaseManager
* @see loadFromFile()
* @see saveToFile()
*/
public $rulesFile = '@app/data/rbac-rules.php';
public $ruleFile = '@app/rbac/rules.php';
/**
* @var Item[]
*/
......@@ -82,9 +82,9 @@ class PhpManager extends BaseManager
public function init()
{
parent::init();
$this->itemsFile = Yii::getAlias($this->itemsFile);
$this->assignmentsFile = Yii::getAlias($this->assignmentsFile);
$this->rulesFile = Yii::getAlias($this->rulesFile);
$this->itemFile = Yii::getAlias($this->itemFile);
$this->assignmentFile = Yii::getAlias($this->assignmentFile);
$this->ruleFile = Yii::getAlias($this->ruleFile);
$this->load();
}
......@@ -615,11 +615,11 @@ class PhpManager extends BaseManager
$this->assignments = [];
$this->items = [];
$items = $this->loadFromFile($this->itemsFile);
$itemsMtime = @filemtime($this->itemsFile);
$assignments = $this->loadFromFile($this->assignmentsFile);
$assignmentsMtime = @filemtime($this->assignmentsFile);
$rules = $this->loadFromFile($this->rulesFile);
$items = $this->loadFromFile($this->itemFile);
$itemsMtime = @filemtime($this->itemFile);
$assignments = $this->loadFromFile($this->assignmentFile);
$assignmentsMtime = @filemtime($this->assignmentFile);
$rules = $this->loadFromFile($this->ruleFile);
foreach ($items as $name => $item) {
$class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
......@@ -718,7 +718,7 @@ class PhpManager extends BaseManager
}
}
}
$this->saveToFile($items, $this->itemsFile);
$this->saveToFile($items, $this->itemFile);
}
/**
......@@ -733,7 +733,7 @@ class PhpManager extends BaseManager
$assignmentData[$userId] = $assignment->roleName;
}
}
$this->saveToFile($assignmentData, $this->assignmentsFile);
$this->saveToFile($assignmentData, $this->assignmentFile);
}
/**
......@@ -745,6 +745,6 @@ class PhpManager extends BaseManager
foreach ($this->rules as $name => $rule) {
$rules[$name] = serialize($rule);
}
$this->saveToFile($rules, $this->rulesFile);
$this->saveToFile($rules, $this->ruleFile);
}
}
......@@ -10,34 +10,34 @@ use Yii;
*/
class PhpManagerTest extends ManagerTestCase
{
protected function getItemsFile()
protected function getItemFile()
{
return Yii::$app->getRuntimePath() . '/rbac-items.php';
}
protected function getAssignmentsFile()
protected function getAssignmentFile()
{
return Yii::$app->getRuntimePath() . '/rbac-assignments.php';
}
protected function getRulesFile()
protected function getRuleFile()
{
return Yii::$app->getRuntimePath() . '/rbac-rules.php';
}
protected function removeDataFiles()
{
@unlink($this->getItemsFile());
@unlink($this->getAssignmentsFile());
@unlink($this->getRulesFile());
@unlink($this->getItemFile());
@unlink($this->getAssignmentFile());
@unlink($this->getRuleFile());
}
protected function createManager()
{
return new ExposedPhpManager([
'itemsFile' => $this->getItemsFile(),
'assignmentsFile' => $this->getAssignmentsFile(),
'rulesFile' => $this->getRulesFile(),
'itemFile' => $this->getItemFile(),
'assignmentFile' => $this->getAssignmentFile(),
'ruleFile' => $this->getRuleFile(),
]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment