Closed mcd-php closed 9 years ago
Here's fix, too lazy to fork and PR. Is where any way to send fixes by patches ?
diff --git a/rbac/PhpManager.php b/rbac/PhpManager.php
index 151a634..9490ce2 100644
--- a/rbac/PhpManager.php
+++ b/rbac/PhpManager.php
@@ -713,7 +713,7 @@ class PhpManager extends BaseManager
*/
protected function saveToFile($data, $file)
{
- file_put_contents($file, "<?php\nreturn " . VarDumper::export($data) . ";\n", LOCK_EX);
+ file_put_contents(Yii::getAlias($file), "<?php\nreturn " . VarDumper::export($data) . ";\n", LOCK_EX);
}
/**
Such problem could not appear: all file names are passed through Yii::getAlias()
at init()
method:
https://github.com/yiisoft/yii2/blob/master/framework/rbac/PhpManager.php#L88
Oops, I see it's my fault, forgot to call parent::init();
.
But anyway it's more intuitive to expand upon use - what if user change them after creation ?
No: this is not acceptable, because these names are also used while loading data: https://github.com/yiisoft/yii2/blob/master/framework/rbac/PhpManager.php#L630
How does this Yii::getAlias($file)
help guys? I have Yii 2 version 2.0.13.1 and this issue persists still.
The actual reason is hidden behind it. As is written in documentation of getAlias method - "Note, this method does not check if the returned path exists or not." . Thank you. I am unable without fix (or creating folder rbac manually), to use file-based rbac authentication.
Although I worked it around by creating rbac directory myself in Rbac command
mkdir(Yii::getAlias("@app/rbac"));
but I don't know if it's the best practice.
file_put_contents(@common/rbac/data/items.php): failed to open stream: No such file or directory
Not so critical, will use
__DIR__
, but anyway violation of given example.