mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-04 22:57:40 +08:00
Adjusted naming
This commit is contained in:
@ -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 #4028: Added ability to `yii\widgets\Menu` to encode each item's label separately (creocoder, umneeq)
|
||||||
- Enh #4072: `\yii\rbac\PhpManager` adjustments (samdark)
|
- Enh #4072: `\yii\rbac\PhpManager` adjustments (samdark)
|
||||||
- Data is now stored in three separate files for items, assignments and rules. File format is simpler.
|
- 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.
|
- `createdAt` and `updatedAt` are now properly filled with corresponding file modification time.
|
||||||
- `save()` and `load()` are now protected instead of public.
|
- `save()` and `load()` are now protected instead of public.
|
||||||
- Added unit test for saving and loading data.
|
- 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
|
||||||
<?php
|
<?php
|
||||||
$oldFile = 'rbac.php';
|
$oldFile = 'rbac.php';
|
||||||
$itemsFile = 'rbac-items.php';
|
$itemsFile = 'items.php';
|
||||||
$assignmentsFile = 'rbac-assignments.php';
|
$assignmentsFile = 'assignments.php';
|
||||||
$rulesFile = 'rbac-rules.php';
|
$rulesFile = 'rules.php';
|
||||||
|
|
||||||
$oldData = include $oldFile;
|
$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
|
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
|
* 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()`.
|
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 loadFromFile()
|
||||||
* @see saveToFile()
|
* @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.
|
* @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.
|
* 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 loadFromFile()
|
||||||
* @see saveToFile()
|
* @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.
|
* @var string the path of the PHP script that contains the authorization rules.
|
||||||
@ -55,7 +55,7 @@ class PhpManager extends BaseManager
|
|||||||
* @see loadFromFile()
|
* @see loadFromFile()
|
||||||
* @see saveToFile()
|
* @see saveToFile()
|
||||||
*/
|
*/
|
||||||
public $rulesFile = '@app/data/rbac-rules.php';
|
public $ruleFile = '@app/rbac/rules.php';
|
||||||
/**
|
/**
|
||||||
* @var Item[]
|
* @var Item[]
|
||||||
*/
|
*/
|
||||||
@ -82,9 +82,9 @@ class PhpManager extends BaseManager
|
|||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
$this->itemsFile = Yii::getAlias($this->itemsFile);
|
$this->itemFile = Yii::getAlias($this->itemFile);
|
||||||
$this->assignmentsFile = Yii::getAlias($this->assignmentsFile);
|
$this->assignmentFile = Yii::getAlias($this->assignmentFile);
|
||||||
$this->rulesFile = Yii::getAlias($this->rulesFile);
|
$this->ruleFile = Yii::getAlias($this->ruleFile);
|
||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,11 +615,11 @@ class PhpManager extends BaseManager
|
|||||||
$this->assignments = [];
|
$this->assignments = [];
|
||||||
$this->items = [];
|
$this->items = [];
|
||||||
|
|
||||||
$items = $this->loadFromFile($this->itemsFile);
|
$items = $this->loadFromFile($this->itemFile);
|
||||||
$itemsMtime = @filemtime($this->itemsFile);
|
$itemsMtime = @filemtime($this->itemFile);
|
||||||
$assignments = $this->loadFromFile($this->assignmentsFile);
|
$assignments = $this->loadFromFile($this->assignmentFile);
|
||||||
$assignmentsMtime = @filemtime($this->assignmentsFile);
|
$assignmentsMtime = @filemtime($this->assignmentFile);
|
||||||
$rules = $this->loadFromFile($this->rulesFile);
|
$rules = $this->loadFromFile($this->ruleFile);
|
||||||
|
|
||||||
foreach ($items as $name => $item) {
|
foreach ($items as $name => $item) {
|
||||||
$class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className();
|
$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;
|
$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) {
|
foreach ($this->rules as $name => $rule) {
|
||||||
$rules[$name] = serialize($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
|
class PhpManagerTest extends ManagerTestCase
|
||||||
{
|
{
|
||||||
protected function getItemsFile()
|
protected function getItemFile()
|
||||||
{
|
{
|
||||||
return Yii::$app->getRuntimePath() . '/rbac-items.php';
|
return Yii::$app->getRuntimePath() . '/rbac-items.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAssignmentsFile()
|
protected function getAssignmentFile()
|
||||||
{
|
{
|
||||||
return Yii::$app->getRuntimePath() . '/rbac-assignments.php';
|
return Yii::$app->getRuntimePath() . '/rbac-assignments.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRulesFile()
|
protected function getRuleFile()
|
||||||
{
|
{
|
||||||
return Yii::$app->getRuntimePath() . '/rbac-rules.php';
|
return Yii::$app->getRuntimePath() . '/rbac-rules.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function removeDataFiles()
|
protected function removeDataFiles()
|
||||||
{
|
{
|
||||||
@unlink($this->getItemsFile());
|
@unlink($this->getItemFile());
|
||||||
@unlink($this->getAssignmentsFile());
|
@unlink($this->getAssignmentFile());
|
||||||
@unlink($this->getRulesFile());
|
@unlink($this->getRuleFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createManager()
|
protected function createManager()
|
||||||
{
|
{
|
||||||
return new ExposedPhpManager([
|
return new ExposedPhpManager([
|
||||||
'itemsFile' => $this->getItemsFile(),
|
'itemFile' => $this->getItemFile(),
|
||||||
'assignmentsFile' => $this->getAssignmentsFile(),
|
'assignmentFile' => $this->getAssignmentFile(),
|
||||||
'rulesFile' => $this->getRulesFile(),
|
'ruleFile' => $this->getRuleFile(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user