<?php
namespace Claromentis\Core\Acl\Simple;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] ?: array()) + array("_70809333a0f254acf7a1ad0c7dadd4" . "6b" => base64_decode("O" . "i" . "A" . "="), "_aed8da0f19091214b78f8035104851" . "7c" => base64_decode("c3RybG" . "Vu"), "_d706c160e45bf743" . "4fff82a5976f0e19" => base64_decode("YXJy" . "YXlf" . "a2V5" . "cw=="), "_2b97c0ca1bb9e70" . "cb77f4fbf2e523d8" . "d" => base64_decode("Q2FuJ3QgZGVsZXRlIHBlcm1pc3Npb246IHVzZXIgSUQ" . "gaXMgbm90IHNwZWNpZmllZA=="), "_7f628626dd1d55c71b1fc0932ff" . "d1d2c" => base64_decode("aXNfYXJyYXk" . "="), "_c244a470df52d1d5a7085138" . "ec94e393" => base64_decode("dW5zZXJpYWx" . "pemU="), "_96be32a6f44bf54e635e173" . "6acf7a96c" => base64_decode("c2VyaWFsaXp" . "l"), "_7e4946b30c25f9bccba" . "6f750950330de" => base64_decode("Q2FuJ3QgZ2V0IHBlcm1pc3Npb25zOiB1c2VyIElEIGl" . "zIG5vdCBzcGVjaWZpZWQ="));
use Claromentis\Core\Acl\Exception\InvalidSubjectException;
use Claromentis\Core\Acl\PermOClass;






class SimpleAcl
{
    const STANDARD = 1;
    protected $object_code;
    protected $rights;
    
    
    
    
    
    
    public function __construct(string $_65c616d6ef3c21352d2d44595fdf776b = '')
    {
        $this->object_code = $_65c616d6ef3c21352d2d44595fdf776b;
        $this->Clear();
    }
    public function SetObjectCode(string $_65c616d6ef3c21352d2d44595fdf776b)
    {
        $this->object_code = $_65c616d6ef3c21352d2d44595fdf776b;
    }
    public function GetObjectCode() : string
    {
        return $this->object_code;
    }
    
    
    
    
    public function Clear()
    {
        $this->Hydrate(array());
    }
    
    
    
    
    
    
    public function Hydrate(array $rights)
    {
        $this->rights = $rights;
    }
    
    
    
    
    
    
    
    
    
    public function Grant(int $_3877cdf57a61e49b56aeab7af930ee82, int $perms = self::STANDARD)
    {
        if (empty($perms)) {
            return true;
        }
        if (!isset($this->rights[$_3877cdf57a61e49b56aeab7af930ee82])) {
            $this->rights[$_3877cdf57a61e49b56aeab7af930ee82] = $perms;
        } else {
            $this->rights[$_3877cdf57a61e49b56aeab7af930ee82] |= $perms;
        }
        return true;
    }
    
    
    
    
    
    
    
    
    
    public function Permits(int $_3877cdf57a61e49b56aeab7af930ee82, int $perms = 0)
    {
        if ($perms === 0) {
            return !empty($this->rights[$_3877cdf57a61e49b56aeab7af930ee82]);
        }
        $p = $this->Get($_3877cdf57a61e49b56aeab7af930ee82);
        return $p & $perms == $perms;
    }
    
    
    
    
    
    
    
    
    
    public function Set(int $_3877cdf57a61e49b56aeab7af930ee82, int $perms = self::STANDARD)
    {
        if (empty($perms)) {
            unset($this->rights[$_3877cdf57a61e49b56aeab7af930ee82]);
        } else {
            $this->rights[$_3877cdf57a61e49b56aeab7af930ee82] = $perms;
        }
        return true;
    }
    
    
    
    
    
    
    
    public function SetMany(array $_5882c836e9757b405d08e77f1fd2a18b, int $perms = self::STANDARD)
    {
        foreach ($_5882c836e9757b405d08e77f1fd2a18b as $_3877cdf57a61e49b56aeab7af930ee82) {
            $this->Set($_3877cdf57a61e49b56aeab7af930ee82, $perms);
        }
    }
    
    
    
    
    
    
    
    
    public function Get(int $_3877cdf57a61e49b56aeab7af930ee82) : int
    {
        if (empty($_3877cdf57a61e49b56aeab7af930ee82)) {
            throw new InvalidSubjectException($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7e4946b30c25f" . "9bccba6f750950" . "330de"]);
        }
        if (!isset($this->rights[$_3877cdf57a61e49b56aeab7af930ee82])) {
            return 0;
        }
        return $this->rights[$_3877cdf57a61e49b56aeab7af930ee82];
    }
    
    
    
    
    
    
    
    public function Delete(int $_3877cdf57a61e49b56aeab7af930ee82, int $perms = 0)
    {
        if (empty($_3877cdf57a61e49b56aeab7af930ee82)) {
            throw new InvalidSubjectException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_2b97c0ca1bb9e70" . "cb77f4fbf2e523d8" . "d"]);
        }
        if ($perms === 0) {
            unset($this->rights[$_3877cdf57a61e49b56aeab7af930ee82]);
        }
        $this->Set($this->Get($_3877cdf57a61e49b56aeab7af930ee82) & ~$perms, $_3877cdf57a61e49b56aeab7af930ee82);
    }
    
    
    
    
    
    
    
    
    public function CreateCopy(string $_65c616d6ef3c21352d2d44595fdf776b) : SimpleAcl
    {
        $acl = new SimpleAcl($_65c616d6ef3c21352d2d44595fdf776b);
        $acl->Hydrate($this->GetRights());
        return $acl;
    }
    
    
    
    
    
    
    
    
    public function GetRights(int $perms = 0) : array
    {
        if ($perms === 0) {
            return $this->rights;
        }
        $_1f24efd4735b7a11b391147435e7d35d = [];
        foreach ($this->rights as $_3877cdf57a61e49b56aeab7af930ee82 => $p) {
            if (($p & $perms) == $perms) {
                $_1f24efd4735b7a11b391147435e7d35d[$_3877cdf57a61e49b56aeab7af930ee82] = $p;
            }
        }
        return $_1f24efd4735b7a11b391147435e7d35d;
    }
    
    
    
    
    
    
    
    
    public function GetIndividualsList(int $perms = 0)
    {
        if ($perms === 0) {
            return $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_d706c160e45bf7434fff82a59" . "76f0e19"]($this->rights);
        }
        $_1f24efd4735b7a11b391147435e7d35d = [];
        foreach ($this->rights as $_3877cdf57a61e49b56aeab7af930ee82 => $p) {
            if (($p & $perms) == $perms) {
                $_1f24efd4735b7a11b391147435e7d35d[] = $_3877cdf57a61e49b56aeab7af930ee82;
            }
        }
        return $_1f24efd4735b7a11b391147435e7d35d;
    }
    
    
    
    
    
    
    
    public function AsTextStrings() : array
    {
        $_a91f531562c56061228ba02b34c36a79 = [];
        $_5882c836e9757b405d08e77f1fd2a18b = $this->GetIndividualsList();
        foreach ($_5882c836e9757b405d08e77f1fd2a18b as $_3877cdf57a61e49b56aeab7af930ee82) {
            $_a91f531562c56061228ba02b34c36a79[] = PermOClass::GetName(PermOClass::INDIVIDUAL) . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_70809333a0f254acf7a" . "1ad0c7dadd46b"] . \User::GetNameById($_3877cdf57a61e49b56aeab7af930ee82);
        }
        return $_a91f531562c56061228ba02b34c36a79;
    }
    
    
    
    
    public function Serialize() : string
    {
        return $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_96be32a6f44bf54e635e1736acf7a" . "96c"]($this->rights);
    }
    
    
    
    
    public function Unserialize(string $_34460bffd3af92da81e46ee15e9e66e3)
    {
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_aed8da0f19091214b78f803" . "51048517c"]($_34460bffd3af92da81e46ee15e9e66e3) > 0) {
            $rights = $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_c244a470df" . "52d1d5a7085" . "138ec94e393"]($_34460bffd3af92da81e46ee15e9e66e3);
            if ($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_7f628626dd1d55" . "c71b1fc0932ffd1" . "d2c"]($rights)) {
                $this->Hydrate($rights);
            }
        }
    }
}