@@ -101,6 +101,7 @@ class YesAuthority
101
101
protected $ accessResultContainer = [];
102
102
103
103
protected $ defaultAllowedAccessIds = [];
104
+ protected $ uniqueIdKeyString = null ;
104
105
105
106
/**
106
107
* Constructor
@@ -259,6 +260,7 @@ protected function configure($requestForUserId = null, $options = [])
259
260
$ this ->userPermissions = array_merge ($ this ->userPermissions , $ rawUserPermissions );
260
261
}
261
262
}
263
+
262
264
}
263
265
264
266
if ($ this ->accessScope === 'role ' ) {
@@ -510,10 +512,13 @@ public function check($accessIdKey = null, $requestForUserId = null, array $opti
510
512
$ this ->initialize ();
511
513
return $ accessResultArray ;
512
514
}
515
+
516
+ $ this ->uniqueIdKeyString = $ this ->generateUniqueIdKeyString ($ accessIdKey , $ requestForUserId , $ options );
517
+
513
518
// try to retrive already checked item
514
519
$ existingUniqueIdItem = array_get (
515
520
$ this ->accessResultContainer ,
516
- $ this ->uniqueIdKeyString ( $ accessIdKey , $ requestForUserId , $ options ) ,
521
+ $ this ->uniqueIdKeyString ,
517
522
null
518
523
);
519
524
// if found return that same
@@ -591,9 +596,9 @@ public function check($accessIdKey = null, $requestForUserId = null, array $opti
591
596
592
597
return $ this ->processResult ($ accessIdKey , $ requestForUserId , $ wildCardResult , $ options );
593
598
}
594
-
595
- if (!isset ($ this ->accessStages [$ accessIdKey ])) {
596
- $ this ->accessStages [$ accessIdKey ] = [];
599
+
600
+ if (!isset ($ this ->accessStages [$ this -> uniqueIdKeyString ])) {
601
+ $ this ->accessStages [$ this -> uniqueIdKeyString ] = [];
597
602
}
598
603
599
604
if (array_get ($ this ->permissions , 'rules.base ' )) {
@@ -644,7 +649,7 @@ public function check($accessIdKey = null, $requestForUserId = null, array $opti
644
649
);
645
650
}
646
651
}
647
-
652
+
648
653
if ($ this ->performLevelChecks (4 )) {
649
654
if ($ this ->userPermissions and !empty ($ this ->userPermissions )) {
650
655
// check for permissions using user custom permissions
@@ -750,8 +755,8 @@ public function check($accessIdKey = null, $requestForUserId = null, array $opti
750
755
);
751
756
752
757
if ((is_bool ($ entityConditionIsAccess ) === true )) {
753
- $ this ->accessStages [$ accessIdKey ]['__result ' ] = 'ENTITY_CONDITION ' ;
754
- $ isAccess = $ this ->accessStages [$ accessIdKey ]['ENTITY_CONDITION ' ] = $ entityConditionIsAccess ;
758
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__result ' ] = 'ENTITY_CONDITION ' ;
759
+ $ isAccess = $ this ->accessStages [$ this -> uniqueIdKeyString ]['ENTITY_CONDITION ' ] = $ entityConditionIsAccess ;
755
760
}
756
761
}
757
762
}
@@ -811,18 +816,18 @@ public function check($accessIdKey = null, $requestForUserId = null, array $opti
811
816
// expect boolean
812
817
if (($ isMatchFound === true ) and $ uses and (is_bool ($ isConditionalAccess ) === true )) {
813
818
814
- if (! isset ($ this ->accessStages [$ accessIdKey ]['__conditions ' ])) {
815
- $ this ->accessStages [$ accessIdKey ]['__conditions ' ] = [];
819
+ if (! isset ($ this ->accessStages [$ this -> uniqueIdKeyString ]['__conditions ' ])) {
820
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__conditions ' ] = [];
816
821
}
817
822
818
- $ this ->accessStages [$ accessIdKey ]['__result ' ] = 'CONDITIONS ' ;
819
- $ name = (array_key_exists ($ name , $ this ->accessStages [$ accessIdKey ]['__conditions ' ]))
823
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__result ' ] = 'CONDITIONS ' ;
824
+ $ name = (array_key_exists ($ name , $ this ->accessStages [$ this -> uniqueIdKeyString ]['__conditions ' ]))
820
825
? $ name .'_ ' .$ index : $ name ;
821
826
822
- $ this ->accessStages [$ accessIdKey ]['__conditions ' ]['__result ' ] = $ name ;
823
- $ this ->accessStages [$ accessIdKey ]['__conditions ' ][$ name ] = $ isConditionalAccess ;
827
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__conditions ' ]['__result ' ] = $ name ;
828
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__conditions ' ][$ name ] = $ isConditionalAccess ;
824
829
825
- $ isAccess = $ this ->accessStages [$ accessIdKey ]['CONDITIONS ' ] = $ isConditionalAccess ;
830
+ $ isAccess = $ this ->accessStages [$ this -> uniqueIdKeyString ]['CONDITIONS ' ] = $ isConditionalAccess ;
826
831
}
827
832
828
833
}
@@ -878,7 +883,7 @@ protected function processResult($accessIdKey, $requestForUserId, $accessIdKeyRe
878
883
if (is_string ($ accessIdKey )) {
879
884
880
885
$ this ->accessResultContainer [
881
- $ this ->uniqueIdKeyString ( $ accessIdKey , $ requestForUserId , $ options )
886
+ $ this ->uniqueIdKeyString
882
887
] = [
883
888
'access_id_key ' => $ accessIdKey ,
884
889
'result ' => $ accessIdKeyResult ,
@@ -900,7 +905,7 @@ protected function processResult($accessIdKey, $requestForUserId, $accessIdKeyRe
900
905
*
901
906
* @return mixed
902
907
*---------------------------------------------------------------- */
903
- protected function uniqueIdKeyString ($ accessIdKey , $ requestForUserId , $ options = [])
908
+ protected function generateUniqueIdKeyString ($ accessIdKey , $ requestForUserId , $ options = [])
904
909
{
905
910
return strtolower (str_replace ('. ' , '_ ' , $ accessIdKey )
906
911
. '_ '
@@ -1371,7 +1376,7 @@ protected function performChecks($initialAccess, $accessIdKey, $accessList, $den
1371
1376
}
1372
1377
1373
1378
if (is_array ($ this ->dynamicAccessZones ) and array_key_exists ($ accessIdKey , $ this ->dynamicAccessZones )) {
1374
- $ this ->accessStages [$ accessIdKey ]['__data ' ] = [
1379
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__data ' ] = [
1375
1380
'is_zone ' => true ,
1376
1381
'title ' => array_get ($ this ->dynamicAccessZones [$ accessIdKey ], 'title ' ),
1377
1382
'dependencies ' => array_get ($ this ->dynamicAccessZones [$ accessIdKey ], 'dependencies ' ),
@@ -1382,14 +1387,14 @@ protected function performChecks($initialAccess, $accessIdKey, $accessList, $den
1382
1387
1383
1388
// if it specific item then its important
1384
1389
if ($ specific ) {
1385
- $ this ->accessStages [$ accessIdKey ][$ options ['check_level ' ]] = ($ specific === 'allow ' ) ? true : false ;
1386
- $ this ->accessStages [$ accessIdKey ]['__result ' ] = $ options ['check_level ' ];
1387
- return $ this ->accessStages [$ accessIdKey ][$ options ['check_level ' ]];
1390
+ $ this ->accessStages [$ this -> uniqueIdKeyString ][$ options ['check_level ' ]] = ($ specific === 'allow ' ) ? true : false ;
1391
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__result ' ] = $ options ['check_level ' ];
1392
+ return $ this ->accessStages [$ this -> uniqueIdKeyString ][$ options ['check_level ' ]];
1388
1393
}
1389
1394
1390
1395
if (empty ($ decisionStrength ) === false ) {
1391
- $ this ->accessStages [$ accessIdKey ]['__result ' ] = $ options ['check_level ' ];
1392
- return $ this ->accessStages [$ accessIdKey ][$ options ['check_level ' ]] = $ decisionStrength [max (array_keys ($ decisionStrength ))];
1396
+ $ this ->accessStages [$ this -> uniqueIdKeyString ]['__result ' ] = $ options ['check_level ' ];
1397
+ return $ this ->accessStages [$ this -> uniqueIdKeyString ][$ options ['check_level ' ]] = $ decisionStrength [max (array_keys ($ decisionStrength ))];
1393
1398
}
1394
1399
1395
1400
return $ isAccess ;
@@ -1437,8 +1442,8 @@ protected function collectParentZones($accessZone, $allowDenyList, $intialAccess
1437
1442
*---------------------------------------------------------------- */
1438
1443
protected function detailsFormat ($ isAccess , $ accessIdKey , $ options = []) {
1439
1444
1440
- if (!empty ($ this ->accessStages [$ accessIdKey ])) {
1441
- $ itemData = array_pull ($ this ->accessStages [$ accessIdKey ], '__data ' );
1445
+ if (!empty ($ this ->accessStages [$ this -> uniqueIdKeyString ])) {
1446
+ $ itemData = array_pull ($ this ->accessStages [$ this -> uniqueIdKeyString ], '__data ' );
1442
1447
1443
1448
if (is_array ($ itemData ) and !empty ($ itemData )) {
1444
1449
$ options = array_merge ($ options , $ itemData );
@@ -1463,9 +1468,9 @@ protected function detailsFormat($isAccess, $accessIdKey, $options = []) {
1463
1468
$ conditionsIfAny = [];
1464
1469
$ conditionResult = null ;
1465
1470
1466
- $ resultBy = ifIsset ($ this ->accessStages [$ accessIdKey ], function () use (&$ accessIdKey , &$ conditionsIfAny , &$ conditionResult ) {
1467
- $ conditionsIfAny = array_pull ($ this ->accessStages [$ accessIdKey ], '__conditions ' );
1468
- return array_pull ($ this ->accessStages [$ accessIdKey ], '__result ' );
1471
+ $ resultBy = ifIsset ($ this ->accessStages [$ this -> uniqueIdKeyString ], function () use (&$ accessIdKey , &$ conditionsIfAny , &$ conditionResult ) {
1472
+ $ conditionsIfAny = array_pull ($ this ->accessStages [$ this -> uniqueIdKeyString ], '__conditions ' );
1473
+ return array_pull ($ this ->accessStages [$ this -> uniqueIdKeyString ], '__result ' );
1469
1474
}, null );
1470
1475
1471
1476
if (! empty ($ conditionsIfAny )) {
@@ -1475,7 +1480,7 @@ protected function detailsFormat($isAccess, $accessIdKey, $options = []) {
1475
1480
$ parentLevel = null ;
1476
1481
// find parent level item
1477
1482
if ($ resultBy ) {
1478
- foreach (array_reverse ($ this ->accessStages [$ accessIdKey ]) as $ key => $ value ) {
1483
+ foreach (array_reverse ($ this ->accessStages [$ this -> uniqueIdKeyString ]) as $ key => $ value ) {
1479
1484
$ levelKeyId = $ this ->checkLevels [$ key ];
1480
1485
$ resultKeyId = $ this ->checkLevels [$ resultBy ];
1481
1486
if (($ levelKeyId < $ resultKeyId ) and !$ parentLevel ) {
@@ -1497,7 +1502,7 @@ protected function detailsFormat($isAccess, $accessIdKey, $options = []) {
1497
1502
'upper_level ' => $ parentLevel ,
1498
1503
'condition_result_by ' => $ conditionResult ,
1499
1504
'conditions_checked ' => $ conditionsIfAny ,
1500
- 'levels_checked ' => ifIsset ($ this ->accessStages [$ accessIdKey ], true , []),
1505
+ 'levels_checked ' => ifIsset ($ this ->accessStages [$ this -> uniqueIdKeyString ], true , []),
1501
1506
'access_id_key ' => $ accessIdKey ,
1502
1507
'title ' => ifIsset ($ options ['title ' ], true , null ),
1503
1508
'is_public ' => isset ($ options ['is_public ' ]) ? $ options ['is_public ' ] : false ,
@@ -1551,6 +1556,7 @@ private function initialize() {
1551
1556
$ this ->currentRouteAccessId = null ;
1552
1557
// $this->roleIdentified = null;
1553
1558
// $this->userIdentified = null;
1559
+ $ this ->userPermissions = [];
1554
1560
}
1555
1561
1556
1562
/**
0 commit comments