Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix overrideMethod
Browse files Browse the repository at this point in the history
Init from array with "read", "write", .. object.
Implements JsonSerializable, php5.4 ONLY.
  • Loading branch information
cdujeu committed Sep 18, 2015
1 parent d28dcfa commit 5ee3a12
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions core/src/core/classes/class.AJXP_PermissionMask.php
Expand Up @@ -22,25 +22,35 @@
defined('AJXP_EXEC') or die('Access not allowed');


class AJXP_PermissionMask
class AJXP_PermissionMask implements JsonSerializable
{
/**
* @var array
*/
private $permissionTree;
private $permissionTree = array();

function __construct($path = null){
/*if(!empty($path)) {
$permission = new AJXP_Permission();
$this->permissionTree = $this->pathToBranch($path, $permission);
/**
* @param array|null $serializedForm
*/
function __construct($serializedForm = null){
if($serializedForm != null){
foreach($serializedForm as $path => $permissionValue){
$path = AJXP_Utils::sanitize(AJXP_Utils::securePath($path), AJXP_SANITIZE_DIRNAME);
if(!is_array($permissionValue) || $permissionValue["children"]) continue;
$perm = new AJXP_Permission();
if($permissionValue["read"]) $perm->setRead();
if($permissionValue["write"]) $perm->setWrite();
if($permissionValue["deny"]) $perm->setDeny();
$this->updateBranch($path, $perm);
}
}
*/
}

/**
* @return array
*/
function getTree(){
if($this->permissionTree == null) return array();
return $this->permissionTree;
}

Expand Down Expand Up @@ -79,8 +89,9 @@ function deleteBranch($path){
*/
function override($mask){
// Return a new mask
$this->permissionTree = $this->mergeTrees($this->permissionTree, $mask->getTree());
return $this;
$newMask = new AJXP_PermissionMask();
$newMask->updateTree($this->mergeTrees($this->permissionTree, $mask->getTree()));
return $newMask;
}

/**
Expand Down Expand Up @@ -189,7 +200,7 @@ private function pathToBranch($path, $permission){
private function flattenTree($tree = null, &$pathes = null, $currentRoot=""){
if($tree == null) $tree = $this->getTree();
if($pathes == null) $pathes = array();

if(!is_array($tree) || $tree == null) $tree = array();
foreach($tree as $pathPart => $value){
if(is_a($value, "AJXP_Permission")){
$pathes[$currentRoot."/".$pathPart] = $value;
Expand Down Expand Up @@ -228,4 +239,16 @@ public function printSpace($number){
echo "--";
}
}

/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
function jsonSerialize()
{
return $this->flattenTree();
}
}

0 comments on commit 5ee3a12

Please sign in to comment.