Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c68e5f1f
Commit
c68e5f1f
authored
Jun 29, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjusted naming
parent
bb01c1cc
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
28 deletions
+28
-28
CHANGELOG.md
framework/CHANGELOG.md
+1
-1
UPGRADE.md
framework/UPGRADE.md
+4
-4
PhpManager.php
framework/rbac/PhpManager.php
+14
-14
PhpManagerTest.php
tests/unit/framework/rbac/PhpManagerTest.php
+9
-9
No files found.
framework/CHANGELOG.md
View file @
c68e5f1f
...
@@ -123,7 +123,7 @@ Yii Framework 2 Change Log
...
@@ -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
`item
sFile`
,
`assignmentsFile`
and
`rules
File`
.
-
Removed
`authFile`
. Added
`item
File`
,
`assignmentFile`
and
`rule
File`
.
-
`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.
...
...
framework/UPGRADE.md
View file @
c68e5f1f
...
@@ -79,9 +79,9 @@ new ones save the following code as `convert.php` that should be placed in the s
...
@@ -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
=
'r
bac-r
ules.php'
;
$rulesFile
=
'rules.php'
;
$oldData
=
include
$oldFile
;
$oldData
=
include
$oldFile
;
...
@@ -119,7 +119,7 @@ echo "Done!\n";
...
@@ -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
`item
sFile`
,
`assignmentsFile`
and
`rules
File`
.
configure
`item
File`
,
`assignmentFile`
and
`rule
File`
.
*
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()`
.
...
...
framework/rbac/PhpManager.php
View file @
c68e5f1f
...
@@ -38,7 +38,7 @@ class PhpManager extends BaseManager
...
@@ -38,7 +38,7 @@ class PhpManager extends BaseManager
* @see loadFromFile()
* @see loadFromFile()
* @see saveToFile()
* @see saveToFile()
*/
*/
public
$item
sFile
=
'@app/data/rbac-
items.php'
;
public
$item
File
=
'@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
...
@@ -46,7 +46,7 @@ class PhpManager extends BaseManager
* @see loadFromFile()
* @see loadFromFile()
* @see saveToFile()
* @see saveToFile()
*/
*/
public
$assignment
sFile
=
'@app/data/rbac-
assignments.php'
;
public
$assignment
File
=
'@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
...
@@ -55,7 +55,7 @@ class PhpManager extends BaseManager
* @see loadFromFile()
* @see loadFromFile()
* @see saveToFile()
* @see saveToFile()
*/
*/
public
$rule
sFile
=
'@app/data/rbac-
rules.php'
;
public
$rule
File
=
'@app/rbac/
rules.php'
;
/**
/**
* @var Item[]
* @var Item[]
*/
*/
...
@@ -82,9 +82,9 @@ class PhpManager extends BaseManager
...
@@ -82,9 +82,9 @@ class PhpManager extends BaseManager
public
function
init
()
public
function
init
()
{
{
parent
::
init
();
parent
::
init
();
$this
->
item
sFile
=
Yii
::
getAlias
(
$this
->
items
File
);
$this
->
item
File
=
Yii
::
getAlias
(
$this
->
item
File
);
$this
->
assignment
sFile
=
Yii
::
getAlias
(
$this
->
assignments
File
);
$this
->
assignment
File
=
Yii
::
getAlias
(
$this
->
assignment
File
);
$this
->
rule
sFile
=
Yii
::
getAlias
(
$this
->
rules
File
);
$this
->
rule
File
=
Yii
::
getAlias
(
$this
->
rule
File
);
$this
->
load
();
$this
->
load
();
}
}
...
@@ -615,11 +615,11 @@ class PhpManager extends BaseManager
...
@@ -615,11 +615,11 @@ class PhpManager extends BaseManager
$this
->
assignments
=
[];
$this
->
assignments
=
[];
$this
->
items
=
[];
$this
->
items
=
[];
$items
=
$this
->
loadFromFile
(
$this
->
item
s
File
);
$items
=
$this
->
loadFromFile
(
$this
->
itemFile
);
$itemsMtime
=
@
filemtime
(
$this
->
item
s
File
);
$itemsMtime
=
@
filemtime
(
$this
->
itemFile
);
$assignments
=
$this
->
loadFromFile
(
$this
->
assignment
s
File
);
$assignments
=
$this
->
loadFromFile
(
$this
->
assignmentFile
);
$assignmentsMtime
=
@
filemtime
(
$this
->
assignment
s
File
);
$assignmentsMtime
=
@
filemtime
(
$this
->
assignmentFile
);
$rules
=
$this
->
loadFromFile
(
$this
->
rule
s
File
);
$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
...
@@ -718,7 +718,7 @@ class PhpManager extends BaseManager
}
}
}
}
}
}
$this
->
saveToFile
(
$items
,
$this
->
item
s
File
);
$this
->
saveToFile
(
$items
,
$this
->
itemFile
);
}
}
/**
/**
...
@@ -733,7 +733,7 @@ class PhpManager extends BaseManager
...
@@ -733,7 +733,7 @@ class PhpManager extends BaseManager
$assignmentData
[
$userId
]
=
$assignment
->
roleName
;
$assignmentData
[
$userId
]
=
$assignment
->
roleName
;
}
}
}
}
$this
->
saveToFile
(
$assignmentData
,
$this
->
assignment
s
File
);
$this
->
saveToFile
(
$assignmentData
,
$this
->
assignmentFile
);
}
}
/**
/**
...
@@ -745,6 +745,6 @@ class PhpManager extends BaseManager
...
@@ -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
->
rule
s
File
);
$this
->
saveToFile
(
$rules
,
$this
->
ruleFile
);
}
}
}
}
tests/unit/framework/rbac/PhpManagerTest.php
View file @
c68e5f1f
...
@@ -10,34 +10,34 @@ use Yii;
...
@@ -10,34 +10,34 @@ use Yii;
*/
*/
class
PhpManagerTest
extends
ManagerTestCase
class
PhpManagerTest
extends
ManagerTestCase
{
{
protected
function
getItem
s
File
()
protected
function
getItemFile
()
{
{
return
Yii
::
$app
->
getRuntimePath
()
.
'/rbac-items.php'
;
return
Yii
::
$app
->
getRuntimePath
()
.
'/rbac-items.php'
;
}
}
protected
function
getAssignment
s
File
()
protected
function
getAssignmentFile
()
{
{
return
Yii
::
$app
->
getRuntimePath
()
.
'/rbac-assignments.php'
;
return
Yii
::
$app
->
getRuntimePath
()
.
'/rbac-assignments.php'
;
}
}
protected
function
getRule
s
File
()
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
->
getItem
s
File
());
@
unlink
(
$this
->
getItemFile
());
@
unlink
(
$this
->
getAssignment
s
File
());
@
unlink
(
$this
->
getAssignmentFile
());
@
unlink
(
$this
->
getRule
s
File
());
@
unlink
(
$this
->
getRuleFile
());
}
}
protected
function
createManager
()
protected
function
createManager
()
{
{
return
new
ExposedPhpManager
([
return
new
ExposedPhpManager
([
'item
sFile'
=>
$this
->
getItems
File
(),
'item
File'
=>
$this
->
getItem
File
(),
'assignment
sFile'
=>
$this
->
getAssignments
File
(),
'assignment
File'
=>
$this
->
getAssignment
File
(),
'rule
sFile'
=>
$this
->
getRules
File
(),
'rule
File'
=>
$this
->
getRule
File
(),
]);
]);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment