Added ACL response class for #157

This commit is contained in:
djmaze 2021-11-01 22:59:04 +01:00
parent ecdf1603b3
commit b1038667ee
3 changed files with 63 additions and 7 deletions

View file

@ -11,6 +11,8 @@
namespace MailSo\Imap\Commands;
use \MailSo\Imap\Responses\ACL as ACLResponse;
/**
* @category MailSo
* @package Imap
@ -48,13 +50,13 @@ trait ACL
&& $sFolderName === $oResponse->ResponseList[2]
)
{
$aResult[$oResponse->ResponseList[3]] = static::aclRightsToArray(\array_slice($oResponse->ResponseList, 4));
$aResult[$oResponse->ResponseList[3]] = static::aclRightsToClass(\array_slice($oResponse->ResponseList, 4));
}
}
return $aResult;
}
public function FolderListRights(string $sFolderName, string $sIdentifier) : ?array
public function FolderListRights(string $sFolderName, string $sIdentifier) : ?ACLResponse
{
// if ($this->IsSupported('ACL')) {
$oResponses = $this->SendRequestGetResponse('LISTRIGHTS', array(
@ -69,13 +71,13 @@ trait ACL
&& $sIdentifier === $oResponse->ResponseList[3]
)
{
return static::aclRightsToArray(\array_slice($oResponse->ResponseList, 4));
return static::aclRightsToClass(\array_slice($oResponse->ResponseList, 4));
}
}
return null;
}
public function FolderMyRights(string $sFolderName) : ?array
public function FolderMyRights(string $sFolderName) : ?ACLResponse
{
// if ($this->IsSupported('ACL')) {
$oResponses = $this->SendRequestGetResponse('MYRIGHTS', array($this->EscapeString($sFolderName)));
@ -86,19 +88,19 @@ trait ACL
&& $sFolderName === $oResponse->ResponseList[2]
)
{
return static::aclRightsToArray(\array_slice($oResponse->ResponseList, 3));
return static::aclRightsToClass(\array_slice($oResponse->ResponseList, 3));
}
}
return null;
}
private static function aclRightsToArray(array $rules) : array
private static function aclRightsToClass(array $rules) : ACLResponse
{
$result = array();
foreach ($rules as $rule) {
$result = \array_merge($result, \str_split($rule));
}
return \array_unique($result);
return new ACLResponse(\array_unique($result));
}
}

View file

@ -19,6 +19,12 @@ namespace MailSo\Imap\Enumerations;
* @package Imap
* @subpackage Enumerations
*/
/**
* PHP 8.1
enum FolderACL: string {
case ADMINISTER = 'a';
}
*/
abstract class FolderACL
{
const

View file

@ -0,0 +1,48 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Imap\Responses;
/**
* @category MailSo
* @package Imap
*/
class ACL implements \JsonSerializable
{
private $rights;
function __construct(array $rights)
{
$this->rights = $rights;
}
/** PHP 8.1
public function hasRight(string|\MailSo\Imap\Enumerations\FolderACL $right)
{
if ($right instanceof \BackedEnum) {
return \in_array($right->value, $this->rights);
}
*/
public function hasRight(string $right)
{
$const = '\\MailSo\\Imap\\Enumerations\\FolderACL::' . \strtoupper($right);
if (\defined($const)) {
$right = \constant($const);
}
return \in_array($right, $this->rights);
}
public function jsonSerialize()
{
return $this->rights;
}
}